qtype 0.1.11__py3-none-any.whl → 0.1.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. docs/Concepts/mental-model-and-philosophy.md +363 -0
  2. docs/Contributing/index.md +276 -0
  3. docs/Contributing/roadmap.md +81 -0
  4. docs/Decisions/ADR-001-Chat-vs-Completion-Endpoint-Features.md +56 -0
  5. docs/Gallery/dataflow_pipelines.md +80 -0
  6. docs/Gallery/dataflow_pipelines.mermaid +45 -0
  7. docs/Gallery/research_assistant.md +98 -0
  8. docs/Gallery/research_assistant.mermaid +42 -0
  9. docs/Gallery/simple_chatbot.md +36 -0
  10. docs/Gallery/simple_chatbot.mermaid +35 -0
  11. docs/How To/Authentication/configure_aws_authentication.md +60 -0
  12. docs/How To/Authentication/use_api_key_authentication.md +40 -0
  13. docs/How To/Command Line Usage/load_multiple_inputs_from_files.md +62 -0
  14. docs/How To/Command Line Usage/pass_inputs_on_the_cli.md +52 -0
  15. docs/How To/Command Line Usage/serve_with_auto_reload.md +26 -0
  16. docs/How To/Data Processing/adjust_concurrency.md +41 -0
  17. docs/How To/Data Processing/cache_step_results.md +71 -0
  18. docs/How To/Data Processing/decode_json_xml.md +24 -0
  19. docs/How To/Data Processing/explode_collections.md +40 -0
  20. docs/How To/Data Processing/gather_results.md +68 -0
  21. docs/How To/Data Processing/read_data_from_files.md +35 -0
  22. docs/How To/Data Processing/read_sql_databases.md +47 -0
  23. docs/How To/Data Processing/write_data_to_file.md +40 -0
  24. docs/How To/Invoke Models/call_large_language_models.md +51 -0
  25. docs/How To/Invoke Models/create_embeddings.md +49 -0
  26. docs/How To/Invoke Models/reuse_prompts_with_templates.md +39 -0
  27. docs/How To/Language Features/include_qtype_yaml.md +45 -0
  28. docs/How To/Language Features/include_raw_text_from_other_files.md +47 -0
  29. docs/How To/Language Features/reference_entities_by_id.md +51 -0
  30. docs/How To/Language Features/use_environment_variables.md +47 -0
  31. docs/How To/Language Features/use_qtype_mcp.md +59 -0
  32. docs/How To/Observability & Debugging/trace_calls_with_open_telemetry.md +49 -0
  33. docs/How To/Observability & Debugging/validate_qtype_yaml.md +35 -0
  34. docs/How To/Observability & Debugging/visualize_application_architecture.md +61 -0
  35. docs/How To/Observability & Debugging/visualize_example.mermaid +35 -0
  36. docs/How To/Qtype Server/flow_as_ui.png +0 -0
  37. docs/How To/Qtype Server/serve_flows_as_apis.md +40 -0
  38. docs/How To/Qtype Server/serve_flows_as_ui.md +42 -0
  39. docs/How To/Qtype Server/use_conversational_interfaces.md +59 -0
  40. docs/How To/Qtype Server/use_variables_with_ui_hints.md +47 -0
  41. docs/How To/Tools & Integration/bind_tool_inputs_and_outputs.md +48 -0
  42. docs/How To/Tools & Integration/create_tools_from_openapi_specifications.md +89 -0
  43. docs/How To/Tools & Integration/create_tools_from_python_modules.md +90 -0
  44. docs/Reference/cli.md +338 -0
  45. docs/Reference/plugins.md +95 -0
  46. docs/Reference/semantic-validation-rules.md +179 -0
  47. docs/Tutorials/01-first-qtype-application.md +248 -0
  48. docs/Tutorials/02-conversational-chatbot.md +327 -0
  49. docs/Tutorials/03-structured-data.md +481 -0
  50. docs/Tutorials/04-tools-and-function-calling.md +483 -0
  51. docs/Tutorials/example_chat.png +0 -0
  52. docs/Tutorials/index.md +92 -0
  53. docs/components/APIKeyAuthProvider.md +7 -0
  54. docs/components/APITool.md +10 -0
  55. docs/components/AWSAuthProvider.md +13 -0
  56. docs/components/AWSSecretManager.md +5 -0
  57. docs/components/Agent.md +6 -0
  58. docs/components/Aggregate.md +8 -0
  59. docs/components/AggregateStats.md +7 -0
  60. docs/components/Application.md +22 -0
  61. docs/components/AuthorizationProvider.md +6 -0
  62. docs/components/AuthorizationProviderList.md +5 -0
  63. docs/components/BearerTokenAuthProvider.md +6 -0
  64. docs/components/BedrockReranker.md +8 -0
  65. docs/components/ChatContent.md +7 -0
  66. docs/components/ChatMessage.md +6 -0
  67. docs/components/ConstantPath.md +5 -0
  68. docs/components/CustomType.md +7 -0
  69. docs/components/Decoder.md +8 -0
  70. docs/components/DecoderFormat.md +8 -0
  71. docs/components/DocToTextConverter.md +7 -0
  72. docs/components/Document.md +7 -0
  73. docs/components/DocumentEmbedder.md +7 -0
  74. docs/components/DocumentIndex.md +7 -0
  75. docs/components/DocumentSearch.md +7 -0
  76. docs/components/DocumentSource.md +12 -0
  77. docs/components/DocumentSplitter.md +10 -0
  78. docs/components/Echo.md +8 -0
  79. docs/components/Embedding.md +7 -0
  80. docs/components/EmbeddingModel.md +6 -0
  81. docs/components/FieldExtractor.md +20 -0
  82. docs/components/FileSource.md +6 -0
  83. docs/components/FileWriter.md +7 -0
  84. docs/components/Flow.md +14 -0
  85. docs/components/FlowInterface.md +7 -0
  86. docs/components/Index.md +8 -0
  87. docs/components/IndexUpsert.md +6 -0
  88. docs/components/InvokeEmbedding.md +7 -0
  89. docs/components/InvokeFlow.md +8 -0
  90. docs/components/InvokeTool.md +8 -0
  91. docs/components/LLMInference.md +9 -0
  92. docs/components/ListType.md +5 -0
  93. docs/components/Memory.md +8 -0
  94. docs/components/MessageRole.md +14 -0
  95. docs/components/Model.md +10 -0
  96. docs/components/ModelList.md +5 -0
  97. docs/components/OAuth2AuthProvider.md +9 -0
  98. docs/components/PrimitiveTypeEnum.md +21 -0
  99. docs/components/PromptTemplate.md +7 -0
  100. docs/components/PythonFunctionTool.md +7 -0
  101. docs/components/RAGChunk.md +7 -0
  102. docs/components/RAGDocument.md +10 -0
  103. docs/components/RAGSearchResult.md +8 -0
  104. docs/components/Reranker.md +5 -0
  105. docs/components/SQLSource.md +8 -0
  106. docs/components/Search.md +7 -0
  107. docs/components/SearchResult.md +7 -0
  108. docs/components/SecretManager.md +7 -0
  109. docs/components/SecretReference.md +7 -0
  110. docs/components/Source.md +6 -0
  111. docs/components/Step.md +9 -0
  112. docs/components/TelemetrySink.md +9 -0
  113. docs/components/Tool.md +9 -0
  114. docs/components/ToolList.md +5 -0
  115. docs/components/ToolParameter.md +6 -0
  116. docs/components/TypeList.md +5 -0
  117. docs/components/Variable.md +6 -0
  118. docs/components/VariableList.md +5 -0
  119. docs/components/VectorIndex.md +7 -0
  120. docs/components/VectorSearch.md +6 -0
  121. docs/components/VertexAuthProvider.md +9 -0
  122. docs/components/Writer.md +5 -0
  123. docs/example_ui.png +0 -0
  124. docs/index.md +81 -0
  125. docs/legacy_how_tos/Configuration/modular-yaml.md +366 -0
  126. docs/legacy_how_tos/Configuration/phoenix_projects.png +0 -0
  127. docs/legacy_how_tos/Configuration/phoenix_traces.png +0 -0
  128. docs/legacy_how_tos/Configuration/reference-by-id.md +251 -0
  129. docs/legacy_how_tos/Configuration/telemetry-setup.md +259 -0
  130. docs/legacy_how_tos/Data Types/custom-types.md +52 -0
  131. docs/legacy_how_tos/Data Types/domain-types.md +113 -0
  132. docs/legacy_how_tos/Debugging/visualize-apps.md +147 -0
  133. docs/legacy_how_tos/Tools/api-tools.md +29 -0
  134. docs/legacy_how_tos/Tools/python-tools.md +299 -0
  135. examples/authentication/aws_authentication.qtype.yaml +63 -0
  136. examples/conversational_ai/hello_world_chat.qtype.yaml +43 -0
  137. examples/conversational_ai/simple_chatbot.qtype.yaml +40 -0
  138. examples/data_processing/batch_processing.qtype.yaml +54 -0
  139. examples/data_processing/cache_step_results.qtype.yaml +78 -0
  140. examples/data_processing/collect_results.qtype.yaml +55 -0
  141. examples/data_processing/dataflow_pipelines.qtype.yaml +108 -0
  142. examples/data_processing/decode_json.qtype.yaml +23 -0
  143. examples/data_processing/explode_items.qtype.yaml +25 -0
  144. examples/data_processing/read_file.qtype.yaml +60 -0
  145. examples/invoke_models/create_embeddings.qtype.yaml +28 -0
  146. examples/invoke_models/simple_llm_call.qtype.yaml +32 -0
  147. examples/language_features/include_raw.qtype.yaml +27 -0
  148. examples/language_features/ui_hints.qtype.yaml +52 -0
  149. examples/legacy/bedrock/data_analysis_with_telemetry.qtype.yaml +169 -0
  150. examples/legacy/bedrock/hello_world.qtype.yaml +39 -0
  151. examples/legacy/bedrock/hello_world_chat.qtype.yaml +37 -0
  152. examples/legacy/bedrock/hello_world_chat_with_telemetry.qtype.yaml +40 -0
  153. examples/legacy/bedrock/hello_world_chat_with_thinking.qtype.yaml +40 -0
  154. examples/legacy/bedrock/hello_world_completion.qtype.yaml +41 -0
  155. examples/legacy/bedrock/hello_world_completion_with_auth.qtype.yaml +44 -0
  156. examples/legacy/bedrock/simple_agent_chat.qtype.yaml +46 -0
  157. examples/legacy/chat_with_langfuse.qtype.yaml +50 -0
  158. examples/legacy/data_processor.qtype.yaml +48 -0
  159. examples/legacy/echo/debug_example.qtype.yaml +59 -0
  160. examples/legacy/echo/prompt.qtype.yaml +22 -0
  161. examples/legacy/echo/test.qtype.yaml +26 -0
  162. examples/legacy/echo/video.qtype.yaml +20 -0
  163. examples/legacy/field_extractor_example.qtype.yaml +137 -0
  164. examples/legacy/multi_flow_example.qtype.yaml +125 -0
  165. examples/legacy/openai/hello_world_chat.qtype.yaml +43 -0
  166. examples/legacy/openai/hello_world_chat_with_telemetry.qtype.yaml +46 -0
  167. examples/legacy/rag.qtype.yaml +207 -0
  168. examples/legacy/time_utilities.qtype.yaml +64 -0
  169. examples/legacy/vertex/hello_world_chat.qtype.yaml +36 -0
  170. examples/legacy/vertex/hello_world_completion.qtype.yaml +40 -0
  171. examples/legacy/vertex/hello_world_completion_with_auth.qtype.yaml +45 -0
  172. examples/observability_debugging/trace_with_opentelemetry.qtype.yaml +40 -0
  173. examples/research_assistant/research_assistant.qtype.yaml +94 -0
  174. examples/research_assistant/tavily.oas.yaml +722 -0
  175. examples/research_assistant/tavily.qtype.yaml +289 -0
  176. examples/tutorials/01_hello_world.qtype.yaml +48 -0
  177. examples/tutorials/02_conversational_chat.qtype.yaml +37 -0
  178. examples/tutorials/03_structured_data.qtype.yaml +130 -0
  179. examples/tutorials/04_tools_and_function_calling.qtype.yaml +89 -0
  180. qtype/application/converters/tools_from_api.py +39 -35
  181. qtype/base/types.py +6 -1
  182. qtype/commands/convert.py +3 -6
  183. qtype/commands/generate.py +7 -3
  184. qtype/commands/mcp.py +68 -0
  185. qtype/commands/validate.py +4 -4
  186. qtype/dsl/custom_types.py +2 -1
  187. qtype/dsl/linker.py +15 -7
  188. qtype/dsl/loader.py +3 -3
  189. qtype/dsl/model.py +24 -3
  190. qtype/interpreter/api.py +4 -1
  191. qtype/interpreter/base/base_step_executor.py +3 -1
  192. qtype/interpreter/conversions.py +7 -3
  193. qtype/interpreter/executors/construct_executor.py +1 -1
  194. qtype/interpreter/executors/file_source_executor.py +3 -3
  195. qtype/interpreter/executors/file_writer_executor.py +4 -4
  196. qtype/interpreter/executors/index_upsert_executor.py +1 -1
  197. qtype/interpreter/executors/sql_source_executor.py +1 -1
  198. qtype/interpreter/resource_cache.py +3 -1
  199. qtype/interpreter/rich_progress.py +6 -3
  200. qtype/interpreter/stream/chat/converter.py +25 -17
  201. qtype/interpreter/stream/chat/ui_request_to_domain_type.py +2 -2
  202. qtype/interpreter/typing.py +5 -7
  203. qtype/mcp/__init__.py +0 -0
  204. qtype/mcp/server.py +467 -0
  205. qtype/semantic/checker.py +1 -1
  206. qtype/semantic/generate.py +3 -3
  207. qtype/semantic/visualize.py +38 -51
  208. {qtype-0.1.11.dist-info → qtype-0.1.12.dist-info}/METADATA +21 -1
  209. qtype-0.1.12.dist-info/RECORD +325 -0
  210. {qtype-0.1.11.dist-info → qtype-0.1.12.dist-info}/WHEEL +1 -1
  211. schema/qtype.schema.json +4018 -0
  212. qtype-0.1.11.dist-info/RECORD +0 -142
  213. {qtype-0.1.11.dist-info → qtype-0.1.12.dist-info}/entry_points.txt +0 -0
  214. {qtype-0.1.11.dist-info → qtype-0.1.12.dist-info}/licenses/LICENSE +0 -0
  215. {qtype-0.1.11.dist-info → qtype-0.1.12.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,299 @@
1
+ # Create Tools from Python Modules
2
+
3
+ QType allows you to automatically convert Python functions into QType tools. This tutorial will walk you through creating a Python module with functions and converting them into a QType specification that can be used in your applications.
4
+
5
+ ## Prerequisites
6
+
7
+ Before following this tutorial, make sure you understand:
8
+
9
+ - [Variables and types](../../Concepts/Core/variable.md) in QType
10
+ - [Primitive types](../../components/PrimitiveTypeEnum.md)
11
+ - [Domain types](../Data%20Types/domain-types.md)
12
+ - [Custom types](../Data%20Types/custom-types.md)
13
+
14
+ ## Overview
15
+
16
+ The `qtype convert module` command analyzes Python functions in a module and automatically generates QType tool definitions. This saves you from manually writing tool specifications and ensures consistency between your Python code and QType definitions.
17
+
18
+ ## Supported Types
19
+
20
+ For functions to be converted successfully, all arguments and return types must use supported type annotations:
21
+
22
+ ### Primitive Types
23
+ - `str` → `text`
24
+ - `int` → `int`
25
+ - `float` → `float`
26
+ - `bool` → `boolean`
27
+ - `bytes` → `file`
28
+ - `datetime.datetime` → `datetime`
29
+ - `datetime.date` → `date`
30
+ - `datetime.time` → `time`
31
+
32
+ ### Domain Types
33
+ - `ChatMessage` from `qtype.dsl.domain_types`
34
+ - `ChatContent` from `qtype.dsl.domain_types`
35
+ - `Embedding` from `qtype.dsl.domain_types`
36
+
37
+ ### Custom Types
38
+ You can use your own classes **only if** they inherit from `pydantic.BaseModel`. These will be automatically converted to QType custom types.
39
+
40
+ ## Creating a Sample Module
41
+
42
+ Let's create a sample Python module with utility functions. Create a new file called `my_utilities.py`:
43
+
44
+ ```python
45
+ from datetime import datetime, timedelta
46
+ from pydantic import BaseModel
47
+
48
+
49
+ class ProcessingResult(BaseModel):
50
+ """Result of a text processing operation."""
51
+ processed_text: str
52
+ word_count: int
53
+ processing_time: float
54
+
55
+
56
+ def count_words(text: str) -> int:
57
+ """
58
+ Count the number of words in a text string.
59
+
60
+ Args:
61
+ text: The input text to count words in.
62
+
63
+ Returns:
64
+ Number of words in the text.
65
+ """
66
+ return len(text.split())
67
+
68
+
69
+ def format_timestamp(timestamp: datetime, format_str: str = "%Y-%m-%d %H:%M:%S") -> str:
70
+ """
71
+ Format a datetime object as a string.
72
+
73
+ Args:
74
+ timestamp: The datetime to format.
75
+ format_str: The format string to use.
76
+
77
+ Returns:
78
+ Formatted datetime string.
79
+ """
80
+ return timestamp.strftime(format_str)
81
+
82
+
83
+ def calculate_future_date(start_date: datetime, days_ahead: int) -> datetime:
84
+ """
85
+ Calculate a future date by adding days to a start date.
86
+
87
+ Args:
88
+ start_date: The starting date.
89
+ days_ahead: Number of days to add.
90
+
91
+ Returns:
92
+ The calculated future date.
93
+ """
94
+ return start_date + timedelta(days=days_ahead)
95
+
96
+
97
+ def process_text_advanced(text: str, uppercase: bool = False) -> ProcessingResult:
98
+ """
99
+ Process text and return detailed results.
100
+
101
+ Args:
102
+ text: The text to process.
103
+ uppercase: Whether to convert to uppercase.
104
+
105
+ Returns:
106
+ Processing results including word count and timing.
107
+ """
108
+ import time
109
+ start_time = time.time()
110
+
111
+ processed = text.upper() if uppercase else text.lower()
112
+ word_count = len(text.split())
113
+ processing_time = time.time() - start_time
114
+
115
+ return ProcessingResult(
116
+ processed_text=processed,
117
+ word_count=word_count,
118
+ processing_time=processing_time
119
+ )
120
+ ```
121
+
122
+ ## Converting the Module to QType Tools
123
+
124
+ Now convert your Python module to QType tools using the CLI:
125
+
126
+ ```bash
127
+ qtype convert module my_utilities -o my_utilities.qtype.yml
128
+ ```
129
+
130
+ This will generate a QType specification file with all your functions converted to tools.
131
+
132
+ ## Understanding the Generated Output
133
+
134
+ The generated `my_utilities.qtype.yml` file will contain:
135
+
136
+ ```yaml
137
+ description: Tools created from Python module my_utilities
138
+ id: my_utilities
139
+ tools:
140
+ - description: Count the number of words in a text string.
141
+ function_name: count_words
142
+ id: my_utilities.count_words
143
+ inputs:
144
+ - id: count_words.text
145
+ type: text
146
+ module_path: my_utilities
147
+ name: count_words
148
+ outputs:
149
+ - id: my_utilities.count_words.result
150
+ type: int
151
+
152
+ - description: Format a datetime object as a string.
153
+ function_name: format_timestamp
154
+ id: my_utilities.format_timestamp
155
+ inputs:
156
+ - id: format_timestamp.timestamp
157
+ type: datetime
158
+ - id: format_timestamp.format_str
159
+ type: text
160
+ module_path: my_utilities
161
+ name: format_timestamp
162
+ outputs:
163
+ - id: my_utilities.format_timestamp.result
164
+ type: text
165
+
166
+ - description: Calculate a future date by adding days to a start date.
167
+ function_name: calculate_future_date
168
+ id: my_utilities.calculate_future_date
169
+ inputs:
170
+ - id: calculate_future_date.start_date
171
+ type: datetime
172
+ - id: calculate_future_date.days_ahead
173
+ type: int
174
+ module_path: my_utilities
175
+ name: calculate_future_date
176
+ outputs:
177
+ - id: my_utilities.calculate_future_date.result
178
+ type: datetime
179
+
180
+ - description: Process text and return detailed results.
181
+ function_name: process_text_advanced
182
+ id: my_utilities.process_text_advanced
183
+ inputs:
184
+ - id: process_text_advanced.text
185
+ type: text
186
+ - id: process_text_advanced.uppercase
187
+ type: boolean
188
+ module_path: my_utilities
189
+ name: process_text_advanced
190
+ outputs:
191
+ - id: my_utilities.process_text_advanced.result
192
+ type: ProcessingResult
193
+
194
+ types:
195
+ - description: Result of a text processing operation.
196
+ id: ProcessingResult
197
+ properties:
198
+ processed_text: str
199
+ word_count: int
200
+ processing_time: float
201
+ ```
202
+
203
+ ## Key Features of the Conversion
204
+
205
+ ### Automatic Type Mapping
206
+ - Python types are automatically mapped to QType types
207
+ - Type hints are required for all function parameters and return values
208
+ - Docstrings are extracted and used as tool descriptions
209
+
210
+ ### Custom Type Generation
211
+ - Pydantic models are automatically converted to QType custom types
212
+ - The `ProcessingResult` class becomes a custom type definition
213
+ - All fields in the Pydantic model are preserved with their types
214
+
215
+ ### Tool Naming
216
+ - Tool IDs follow the pattern: `{module_path}.{function_name}`
217
+ - Input variable IDs follow: `{function_name}.{parameter_name}`
218
+ - Output variable IDs follow: `{module_path}.{function_name}.result`
219
+
220
+ ## Requirements and Limitations
221
+
222
+ ### Function Requirements
223
+ 1. **Type Annotations**: All functions must have complete type annotations for parameters and return values
224
+ 2. **Public Functions**: Only public functions (not starting with `_`) are converted
225
+ 3. **Module Definition**: Functions must be defined in the target module (not imported from elsewhere)
226
+ 4. **Supported Types**: All types must be mappable to QType types
227
+
228
+ ### Unsupported Features
229
+ - Functions with `*args` or `**kwargs` parameters
230
+ - Functions without return type annotations
231
+ - Complex generic types (e.g., `Dict[str, List[int]]`)
232
+ - Circular type references
233
+
234
+ ## Using Generated Tools
235
+
236
+ Once you have your `.qtype.yml` file, you can use these tools in QType applications:
237
+
238
+ ```yaml
239
+ id: text_processing_app
240
+ name: Text Processing Application
241
+
242
+ tools:
243
+ - import: my_utilities.qtype.yml
244
+
245
+ flows:
246
+ - id: word_counter_flow
247
+ name: Count Words Flow
248
+ inputs:
249
+ - id: input_text
250
+ type: text
251
+ steps:
252
+ - id: count
253
+ type: tool
254
+ tool: my_utilities.count_words
255
+ inputs:
256
+ text: $input_text
257
+ outputs:
258
+ - id: word_count
259
+ source: count.result
260
+ ```
261
+
262
+ ## Best Practices
263
+
264
+ ### Function Design
265
+ 1. **Clear Docstrings**: Write descriptive docstrings as they become tool descriptions
266
+ 2. **Single Responsibility**: Keep functions focused on one task
267
+ 3. **Type Safety**: Use precise type hints rather than `Any`
268
+ 4. **Error Handling**: Include proper error handling in your functions
269
+
270
+ ### Module Organization
271
+ 1. **Logical Grouping**: Group related functions in the same module
272
+ 2. **Dependencies**: Keep external dependencies minimal
273
+ 3. **Testing**: Write tests for your functions before converting
274
+
275
+ ### Custom Types
276
+ 1. **Pydantic Models**: Use Pydantic BaseModel for complex return types
277
+ 2. **Field Documentation**: Add docstrings to model fields
278
+ 3. **Type Validation**: Leverage Pydantic's validation features
279
+
280
+ ## Troubleshooting
281
+
282
+ ### Common Issues
283
+
284
+ **"Function must have a return type annotation"**
285
+ - Ensure all functions have explicit return type annotations
286
+
287
+ **"Unsupported Python type"**
288
+ - Check that all parameter and return types are supported
289
+ - Consider using custom Pydantic models for complex types
290
+
291
+ **"No public functions found"**
292
+ - Verify functions don't start with underscore
293
+ - Check functions are defined in the target module
294
+
295
+ ### Debugging Tips
296
+ 1. Start with simple functions and gradually add complexity
297
+ 2. Test your Python functions independently before conversion
298
+ 3. Use `mypy` to validate type annotations before conversion
299
+
@@ -0,0 +1,63 @@
1
+ id: aws_auth_demo
2
+ description: |
3
+ Demonstrates different methods of AWS authentication for Bedrock models.
4
+ Choose the method that best fits your deployment environment.
5
+
6
+ # Method 1: AWS Profile (recommended for local development)
7
+ # Uses credentials from ~/.aws/credentials
8
+ auths:
9
+ - type: aws
10
+ id: aws_profile
11
+ profile_name: default
12
+ region: us-east-1
13
+
14
+ # Method 2: Environment variables (recommended for production)
15
+ # Set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION in environment
16
+ # Uncomment to use:
17
+ # - type: aws
18
+ # id: aws_env
19
+ # access_key_id: ${AWS_ACCESS_KEY_ID}
20
+ # secret_access_key: ${AWS_SECRET_ACCESS_KEY}
21
+ # region: us-east-1
22
+
23
+ # Method 3: Role assumption (for cross-account access)
24
+ # Uncomment and configure to use:
25
+ # - type: aws
26
+ # id: aws_role
27
+ # profile_name: base_profile
28
+ # role_arn: arn:aws:iam::123456789012:role/BedrockAccessRole
29
+ # role_session_name: qtype-app-session
30
+ # region: us-east-1
31
+
32
+ models:
33
+ - type: Model
34
+ id: nova_micro
35
+ provider: aws-bedrock
36
+ model_id: us.amazon.nova-micro-v1:0
37
+ auth: aws_profile # Change to aws_env, aws_keys, or aws_role as needed
38
+
39
+ flows:
40
+ - id: simple_completion
41
+ variables:
42
+ - id: user_prompt
43
+ type: text
44
+ - id: formatted
45
+ type: text
46
+ - id: response
47
+ type: text
48
+ inputs:
49
+ - user_prompt
50
+ outputs:
51
+ - response
52
+ steps:
53
+ - type: PromptTemplate
54
+ id: format_prompt
55
+ template: "{user_prompt}"
56
+ inputs: [user_prompt]
57
+ outputs: [formatted]
58
+
59
+ - type: LLMInference
60
+ id: generate
61
+ model: nova_micro
62
+ inputs: [formatted]
63
+ outputs: [response]
@@ -0,0 +1,43 @@
1
+ id: hello_world
2
+ description: A simple chat flow with OpenAI
3
+ models:
4
+ - type: Model
5
+ id: gpt4
6
+ provider: openai
7
+ model_id: gpt-4
8
+ inference_params:
9
+ temperature: 0.7
10
+ max_tokens: 512
11
+ auth: openai_auth
12
+ auths:
13
+ - type: api_key
14
+ id: openai_auth
15
+ api_key: ${OPENAI_KEY}
16
+ host: https://api.openai.com
17
+ memories:
18
+ - id: chat_memory
19
+ token_limit: 10000
20
+ flows:
21
+ - type: Flow
22
+ id: chat_example
23
+ interface:
24
+ type: Conversational
25
+ variables:
26
+ - id: user_message
27
+ type: ChatMessage
28
+ - id: response
29
+ type: ChatMessage
30
+ inputs:
31
+ - user_message
32
+ outputs:
33
+ - response
34
+ steps:
35
+ - id: llm_inference_step
36
+ type: LLMInference
37
+ model: gpt4
38
+ system_message: "You are a helpful assistant."
39
+ memory: chat_memory
40
+ inputs:
41
+ - user_message
42
+ outputs:
43
+ - response
@@ -0,0 +1,40 @@
1
+ id: simple_chatbot
2
+ description: A friendly chatbot with conversation memory using AWS Bedrock
3
+ models:
4
+ - type: Model
5
+ id: nova_lite
6
+ provider: aws-bedrock
7
+ model_id: amazon.nova-lite-v1:0
8
+ inference_params:
9
+ temperature: 0.7
10
+ max_tokens: 512
11
+ memories:
12
+ - id: conversation_memory
13
+ token_limit: 10000
14
+ flows:
15
+ - type: Flow
16
+ id: chat_flow
17
+ interface:
18
+ type: Conversational
19
+ variables:
20
+ - id: user_message
21
+ type: ChatMessage
22
+ - id: assistant_response
23
+ type: ChatMessage
24
+ inputs:
25
+ - user_message
26
+ outputs:
27
+ - assistant_response
28
+ steps:
29
+ - id: generate_response
30
+ type: LLMInference
31
+ model: nova_lite
32
+ system_message: |
33
+ You are a friendly and helpful chatbot. You have a warm, conversational
34
+ tone and enjoy helping users with their questions. You remember context
35
+ from previous messages in the conversation.
36
+ memory: conversation_memory
37
+ inputs:
38
+ - user_message
39
+ outputs:
40
+ - assistant_response
@@ -0,0 +1,54 @@
1
+ id: batch_processing_example
2
+ description: Process multiple inputs loaded from a file
3
+
4
+ models:
5
+ - type: Model
6
+ id: nova_lite
7
+ provider: aws-bedrock
8
+ model_id: amazon.nova-lite-v1:0
9
+
10
+ flows:
11
+ - type: Flow
12
+ id: process_queries
13
+ description: Process multiple queries in batch
14
+
15
+ variables:
16
+ - id: query
17
+ type: text
18
+ - id: topic
19
+ type: text
20
+ - id: prompt
21
+ type: text
22
+ - id: response
23
+ type: text
24
+
25
+ inputs:
26
+ - query
27
+ - topic
28
+
29
+ outputs:
30
+ - query
31
+ - topic
32
+ - response
33
+
34
+ steps:
35
+ - id: create_prompt
36
+ type: PromptTemplate
37
+ template: |
38
+ Category: {topic}
39
+ Question: {query}
40
+
41
+ Provide a brief, helpful answer:
42
+ inputs:
43
+ - query
44
+ - topic
45
+ outputs:
46
+ - prompt
47
+
48
+ - id: answer_query
49
+ type: LLMInference
50
+ model: nova_lite
51
+ inputs:
52
+ - prompt
53
+ outputs:
54
+ - response
@@ -0,0 +1,78 @@
1
+ id: cache_step_demo
2
+ description: |
3
+ Demonstrates step caching to avoid redundant computation.
4
+ On first run, classifications are cached. On subsequent runs with same inputs,
5
+ results are retrieved from cache.
6
+
7
+ auths:
8
+ - type: aws
9
+ id: aws_auth
10
+ region: us-east-1
11
+
12
+ models:
13
+ - type: Model
14
+ id: nova
15
+ provider: aws-bedrock
16
+ model_id: us.amazon.nova-micro-v1:0
17
+ auth: aws_auth
18
+
19
+ flows:
20
+ - id: classify_documents
21
+ variables:
22
+ - id: file_path
23
+ type: text
24
+ - id: document
25
+ type: text
26
+ - id: prompt
27
+ type: text
28
+ - id: category
29
+ type: text
30
+ - id: output_file
31
+ type: text
32
+
33
+ inputs:
34
+ - file_path
35
+
36
+ outputs:
37
+ - output_file
38
+
39
+ steps:
40
+ - type: FileSource
41
+ id: load_docs
42
+ path: file_path
43
+ outputs: [document]
44
+
45
+ - type: PromptTemplate
46
+ id: create_classification_prompt
47
+ template: |
48
+ Classify this document into one of these categories:
49
+ - Technology
50
+ - Finance
51
+ - Healthcare
52
+ - Education
53
+
54
+ Document: {document}
55
+
56
+ Reply with only the category name.
57
+ inputs: [document]
58
+ outputs: [prompt]
59
+
60
+ - type: LLMInference
61
+ id: classify
62
+ model: nova
63
+ inputs: [prompt]
64
+ outputs: [category]
65
+ # Enable caching with configuration
66
+ cache_config:
67
+ namespace: document_classification # Logical separation for cache
68
+ version: "1.0" # Bump this to invalidate cache
69
+ on_error: Drop # Don't cache errors (default)
70
+ ttl: 3600 # Cache for 1 hour (seconds)
71
+ compress: false # Optionally compress cached data
72
+
73
+ - type: FileWriter
74
+ id: write_results
75
+ path:
76
+ uri: classification_results.parquet
77
+ inputs: [document, category]
78
+ outputs: [output_file]
@@ -0,0 +1,55 @@
1
+ id: collect_example
2
+ description: Aggregate fan-out results preserving only common ancestor variables
3
+
4
+ flows:
5
+ - type: Flow
6
+ id: main
7
+ description: Process products by category, then collect results
8
+
9
+ variables:
10
+ - id: category
11
+ type: text
12
+ - id: region
13
+ type: text
14
+ - id: products
15
+ type: list[text]
16
+ - id: product
17
+ type: text
18
+ - id: processed_product
19
+ type: text
20
+ - id: all_processed
21
+ type: list[text]
22
+
23
+ inputs:
24
+ - category
25
+ - region
26
+ - products
27
+
28
+ outputs:
29
+ - all_processed
30
+
31
+ steps:
32
+ # Explode creates multiple messages, each with:
33
+ # - category (same for all)
34
+ # - region (same for all)
35
+ # - product (different for each)
36
+ - type: Explode
37
+ id: fan_out
38
+ inputs: [products]
39
+ outputs: [product]
40
+
41
+ # Each message still has category, region, and its unique product
42
+ - type: PromptTemplate
43
+ id: process
44
+ inputs: [product]
45
+ outputs: [processed_product]
46
+ template: "Processed: {product}"
47
+
48
+ # Collect aggregates all processed_product values into a list
49
+ # Only category and region are preserved as "common ancestors"
50
+ # (same value across all messages)
51
+ # The unique product variable is NOT preserved (different in each)
52
+ - type: Collect
53
+ id: aggregate
54
+ inputs: [processed_product]
55
+ outputs: [all_processed]