qtype 0.0.1__tar.gz
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.
- qtype-0.0.1/LICENSE +202 -0
- qtype-0.0.1/PKG-INFO +120 -0
- qtype-0.0.1/README.md +101 -0
- qtype-0.0.1/pyproject.toml +163 -0
- qtype-0.0.1/qtype/__init__.py +0 -0
- qtype-0.0.1/qtype/cli.py +73 -0
- qtype-0.0.1/qtype/commands/__init__.py +5 -0
- qtype-0.0.1/qtype/commands/convert.py +76 -0
- qtype-0.0.1/qtype/commands/generate.py +107 -0
- qtype-0.0.1/qtype/commands/run.py +200 -0
- qtype-0.0.1/qtype/commands/validate.py +83 -0
- qtype-0.0.1/qtype/commons/__init__.py +0 -0
- qtype-0.0.1/qtype/commons/generate.py +88 -0
- qtype-0.0.1/qtype/commons/tools.py +192 -0
- qtype-0.0.1/qtype/converters/__init__.py +0 -0
- qtype-0.0.1/qtype/converters/tools_from_api.py +24 -0
- qtype-0.0.1/qtype/converters/tools_from_module.py +326 -0
- qtype-0.0.1/qtype/converters/types.py +20 -0
- qtype-0.0.1/qtype/dsl/__init__.py +1 -0
- qtype-0.0.1/qtype/dsl/base_types.py +31 -0
- qtype-0.0.1/qtype/dsl/document.py +108 -0
- qtype-0.0.1/qtype/dsl/domain_types.py +56 -0
- qtype-0.0.1/qtype/dsl/model.py +685 -0
- qtype-0.0.1/qtype/dsl/validator.py +439 -0
- qtype-0.0.1/qtype/interpreter/__init__.py +1 -0
- qtype-0.0.1/qtype/interpreter/api.py +104 -0
- qtype-0.0.1/qtype/interpreter/conversions.py +148 -0
- qtype-0.0.1/qtype/interpreter/exceptions.py +10 -0
- qtype-0.0.1/qtype/interpreter/flow.py +37 -0
- qtype-0.0.1/qtype/interpreter/resource_cache.py +37 -0
- qtype-0.0.1/qtype/interpreter/step.py +67 -0
- qtype-0.0.1/qtype/interpreter/steps/__init__.py +0 -0
- qtype-0.0.1/qtype/interpreter/steps/agent.py +114 -0
- qtype-0.0.1/qtype/interpreter/steps/condition.py +36 -0
- qtype-0.0.1/qtype/interpreter/steps/decoder.py +84 -0
- qtype-0.0.1/qtype/interpreter/steps/llm_inference.py +127 -0
- qtype-0.0.1/qtype/interpreter/steps/prompt_template.py +54 -0
- qtype-0.0.1/qtype/interpreter/steps/search.py +24 -0
- qtype-0.0.1/qtype/interpreter/steps/tool.py +53 -0
- qtype-0.0.1/qtype/interpreter/telemetry.py +16 -0
- qtype-0.0.1/qtype/interpreter/typing.py +78 -0
- qtype-0.0.1/qtype/loader.py +341 -0
- qtype-0.0.1/qtype/semantic/__init__.py +0 -0
- qtype-0.0.1/qtype/semantic/errors.py +4 -0
- qtype-0.0.1/qtype/semantic/generate.py +383 -0
- qtype-0.0.1/qtype/semantic/model.py +354 -0
- qtype-0.0.1/qtype/semantic/resolver.py +97 -0
- qtype-0.0.1/qtype.egg-info/PKG-INFO +120 -0
- qtype-0.0.1/qtype.egg-info/SOURCES.txt +56 -0
- qtype-0.0.1/qtype.egg-info/dependency_links.txt +1 -0
- qtype-0.0.1/qtype.egg-info/entry_points.txt +2 -0
- qtype-0.0.1/qtype.egg-info/requires.txt +7 -0
- qtype-0.0.1/qtype.egg-info/top_level.txt +1 -0
- qtype-0.0.1/setup.cfg +4 -0
- qtype-0.0.1/tests/test_dsl_loader.py +706 -0
- qtype-0.0.1/tests/test_dsl_validation.py +153 -0
- qtype-0.0.1/tests/test_semantic_resolver.py +84 -0
- qtype-0.0.1/tests/test_tool_provider_python_module.py +769 -0
qtype-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025 Bazaarvoice
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
qtype-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qtype
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: DSL for Generative AI Prototyping
|
|
5
|
+
Author-email: Lou Kratz <lou.kratz+qtype@bazaarvoice.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/bazaarvoice/qtype
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: jsonschema>=4.24.0
|
|
12
|
+
Requires-Dist: pydantic>=2.11.5
|
|
13
|
+
Requires-Dist: pyyaml>=6.0.2
|
|
14
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
15
|
+
Requires-Dist: openai>=1.93.0
|
|
16
|
+
Requires-Dist: fsspec>=2025.5.1
|
|
17
|
+
Requires-Dist: pydantic-yaml>=1.5.1
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# QType
|
|
21
|
+
|
|
22
|
+
**QType is a domain-specific language (DSL) for rapid prototyping of AI applications.**
|
|
23
|
+
It is designed to help developers define modular, composable AI systems using a structured YAML-based specification. QType supports models, prompts, tools, retrievers, and flow orchestration, and is extensible for code generation or live interpretation.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 🚀 Quick Start
|
|
28
|
+
|
|
29
|
+
Install QType:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install qtype[interpreter]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Create a file `hello_world.qtype.yaml` that executes a single chat question:
|
|
36
|
+
```yaml
|
|
37
|
+
id: hello_world
|
|
38
|
+
flows:
|
|
39
|
+
- id: simple_qa_flow
|
|
40
|
+
steps:
|
|
41
|
+
- id: llm_inference_step
|
|
42
|
+
model:
|
|
43
|
+
id: gpt-4o
|
|
44
|
+
provider: openai
|
|
45
|
+
auth:
|
|
46
|
+
id: openai_auth
|
|
47
|
+
type: api_key
|
|
48
|
+
api_key: ${OPENAI_KEY}
|
|
49
|
+
system_message: |
|
|
50
|
+
You are a helpful assistant.
|
|
51
|
+
inputs:
|
|
52
|
+
- id: prompt
|
|
53
|
+
type: text
|
|
54
|
+
outputs:
|
|
55
|
+
- id: response_message
|
|
56
|
+
type: text
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Put your openai api key into your `.env` file:
|
|
60
|
+
```
|
|
61
|
+
echo "OPENAI_KEY=sk...." >> .env
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Validate that the file matches the spec:
|
|
65
|
+
```
|
|
66
|
+
qtype validate hello_world.qtype.yaml
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
You should see:
|
|
70
|
+
```
|
|
71
|
+
INFO: ✅ Schema validation successful.
|
|
72
|
+
INFO: ✅ Model validation successful.
|
|
73
|
+
INFO: ✅ Language validation successful
|
|
74
|
+
INFO: ✅ Semantic validation successful
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Finally,execute the flow.
|
|
78
|
+
```
|
|
79
|
+
qtype run flow '{"prompt":"What is the airspeed of a laden swallow?"}' hello_world.qtype.yaml
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
You should see (something similar to):
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
INFO: Executing flow: simple_qa_flow
|
|
86
|
+
|
|
87
|
+
The airspeed of a laden swallow is a humorous reference from the movie "Monty Python and the Holy Grail." In the film, the question is posed as "What is the airspeed velocity of an unladen swallow?" The joke revolves around the absurdity and specificity of the question, and it doesn't have a straightforward answer. However, if you're curious about the real-life airspeed of a swallow, the European Swallow (Hirundo rustica) typically flies at around 11 meters per second, or 24 miles per hour, when unladen. The concept of a "laden" swallow is part of the humor, as it would depend on what the swallow is carrying and is not a standard measurement.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
See the [full docs](https://bazaarvoice.github.io/qtype/) for more examples and guides.
|
|
93
|
+
|
|
94
|
+
## 🤝 Contributing
|
|
95
|
+
|
|
96
|
+
Contributions welcome! Please follow the instructions in the [contribution guide](https://bazaarvoice.github.io/qtype/contributing/).
|
|
97
|
+
|
|
98
|
+
## 📄 License
|
|
99
|
+
|
|
100
|
+
This project is licensed under the **MIT License**.
|
|
101
|
+
See the [LICENSE](./LICENSE) file for details.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 🧠 Philosophy
|
|
106
|
+
|
|
107
|
+
QType is built around modularity, traceability, and rapid iteration. It aims to empower developers to quickly scaffold ideas into usable AI applications without sacrificing maintainability or control.
|
|
108
|
+
|
|
109
|
+
Stay tuned for upcoming features like:
|
|
110
|
+
- Integrated OpenTelemetry tracing
|
|
111
|
+
- Validation via LLM-as-a-judge
|
|
112
|
+
- UI hinting via input display types
|
|
113
|
+
- Flow state switching and conditional routing
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
Happy hacking with QType! 🛠️
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
[](https://github.com/bazaarvoice/qtype/actions/workflows/github_workflows_generate-schema.yml) [](https://github.com/bazaarvoice/qtype/actions/workflows/publish-pypi.yml)
|
qtype-0.0.1/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# QType
|
|
2
|
+
|
|
3
|
+
**QType is a domain-specific language (DSL) for rapid prototyping of AI applications.**
|
|
4
|
+
It is designed to help developers define modular, composable AI systems using a structured YAML-based specification. QType supports models, prompts, tools, retrievers, and flow orchestration, and is extensible for code generation or live interpretation.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 🚀 Quick Start
|
|
9
|
+
|
|
10
|
+
Install QType:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install qtype[interpreter]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Create a file `hello_world.qtype.yaml` that executes a single chat question:
|
|
17
|
+
```yaml
|
|
18
|
+
id: hello_world
|
|
19
|
+
flows:
|
|
20
|
+
- id: simple_qa_flow
|
|
21
|
+
steps:
|
|
22
|
+
- id: llm_inference_step
|
|
23
|
+
model:
|
|
24
|
+
id: gpt-4o
|
|
25
|
+
provider: openai
|
|
26
|
+
auth:
|
|
27
|
+
id: openai_auth
|
|
28
|
+
type: api_key
|
|
29
|
+
api_key: ${OPENAI_KEY}
|
|
30
|
+
system_message: |
|
|
31
|
+
You are a helpful assistant.
|
|
32
|
+
inputs:
|
|
33
|
+
- id: prompt
|
|
34
|
+
type: text
|
|
35
|
+
outputs:
|
|
36
|
+
- id: response_message
|
|
37
|
+
type: text
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Put your openai api key into your `.env` file:
|
|
41
|
+
```
|
|
42
|
+
echo "OPENAI_KEY=sk...." >> .env
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Validate that the file matches the spec:
|
|
46
|
+
```
|
|
47
|
+
qtype validate hello_world.qtype.yaml
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
You should see:
|
|
51
|
+
```
|
|
52
|
+
INFO: ✅ Schema validation successful.
|
|
53
|
+
INFO: ✅ Model validation successful.
|
|
54
|
+
INFO: ✅ Language validation successful
|
|
55
|
+
INFO: ✅ Semantic validation successful
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Finally,execute the flow.
|
|
59
|
+
```
|
|
60
|
+
qtype run flow '{"prompt":"What is the airspeed of a laden swallow?"}' hello_world.qtype.yaml
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
You should see (something similar to):
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
INFO: Executing flow: simple_qa_flow
|
|
67
|
+
|
|
68
|
+
The airspeed of a laden swallow is a humorous reference from the movie "Monty Python and the Holy Grail." In the film, the question is posed as "What is the airspeed velocity of an unladen swallow?" The joke revolves around the absurdity and specificity of the question, and it doesn't have a straightforward answer. However, if you're curious about the real-life airspeed of a swallow, the European Swallow (Hirundo rustica) typically flies at around 11 meters per second, or 24 miles per hour, when unladen. The concept of a "laden" swallow is part of the humor, as it would depend on what the swallow is carrying and is not a standard measurement.
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
See the [full docs](https://bazaarvoice.github.io/qtype/) for more examples and guides.
|
|
74
|
+
|
|
75
|
+
## 🤝 Contributing
|
|
76
|
+
|
|
77
|
+
Contributions welcome! Please follow the instructions in the [contribution guide](https://bazaarvoice.github.io/qtype/contributing/).
|
|
78
|
+
|
|
79
|
+
## 📄 License
|
|
80
|
+
|
|
81
|
+
This project is licensed under the **MIT License**.
|
|
82
|
+
See the [LICENSE](./LICENSE) file for details.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 🧠 Philosophy
|
|
87
|
+
|
|
88
|
+
QType is built around modularity, traceability, and rapid iteration. It aims to empower developers to quickly scaffold ideas into usable AI applications without sacrificing maintainability or control.
|
|
89
|
+
|
|
90
|
+
Stay tuned for upcoming features like:
|
|
91
|
+
- Integrated OpenTelemetry tracing
|
|
92
|
+
- Validation via LLM-as-a-judge
|
|
93
|
+
- UI hinting via input display types
|
|
94
|
+
- Flow state switching and conditional routing
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
Happy hacking with QType! 🛠️
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
[](https://github.com/bazaarvoice/qtype/actions/workflows/github_workflows_generate-schema.yml) [](https://github.com/bazaarvoice/qtype/actions/workflows/publish-pypi.yml)
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "qtype"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "DSL for Generative AI Prototyping"
|
|
5
|
+
authors = [{ name="Lou Kratz", email="lou.kratz+qtype@bazaarvoice.com" }]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
requires-python = ">=3.10"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"jsonschema>=4.24.0",
|
|
10
|
+
"pydantic>=2.11.5",
|
|
11
|
+
"pyyaml>=6.0.2",
|
|
12
|
+
"python-dotenv>=1.0.0",
|
|
13
|
+
"openai>=1.93.0",
|
|
14
|
+
"fsspec>=2025.5.1",
|
|
15
|
+
"pydantic-yaml>=1.5.1"
|
|
16
|
+
]
|
|
17
|
+
license = "APACHE-2.0"
|
|
18
|
+
license-files = ["LICEN[CS]E*"]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/bazaarvoice/qtype"
|
|
22
|
+
|
|
23
|
+
[dependency-groups]
|
|
24
|
+
dev = [
|
|
25
|
+
"arize-phoenix>=11.2.2",
|
|
26
|
+
"boto3>=1.34.0",
|
|
27
|
+
"coverage>=7.0.0",
|
|
28
|
+
"ipython>=8.37.0",
|
|
29
|
+
"isort>=5.13.0",
|
|
30
|
+
"mkdocs-exclude>=1.0.2",
|
|
31
|
+
"mkdocs-material>=9.6.15",
|
|
32
|
+
"mkdocs>=1.6.1",
|
|
33
|
+
"mkdocstrings-python>=1.16.12",
|
|
34
|
+
"mkdocstrings>=0.30.0",
|
|
35
|
+
"mypy>=1.8.0",
|
|
36
|
+
"networkx>=3.4.2",
|
|
37
|
+
"pre-commit>=3.6.0",
|
|
38
|
+
"pymdown-extensions>=10.16",
|
|
39
|
+
"pytest-cov>=6.0.0",
|
|
40
|
+
"pytest>=8.4.1",
|
|
41
|
+
"ruff>=0.1.0",
|
|
42
|
+
"types-PyYAML>=6.0.2",
|
|
43
|
+
]
|
|
44
|
+
docs = [
|
|
45
|
+
"mkdocs>=1.5.0",
|
|
46
|
+
"mkdocs-material>=9.0.0",
|
|
47
|
+
]
|
|
48
|
+
interpreter = [
|
|
49
|
+
"arize-phoenix-otel>=0.12.1",
|
|
50
|
+
"boto3>=1.34.0",
|
|
51
|
+
"fastapi>=0.116.1",
|
|
52
|
+
"llama-index-embeddings-bedrock>=0.5.2",
|
|
53
|
+
"llama-index-embeddings-openai>=0.3.1",
|
|
54
|
+
"llama-index-llms-bedrock-converse>=0.7.4",
|
|
55
|
+
"llama-index-llms-bedrock>=0.3.8",
|
|
56
|
+
"llama-index>=0.12.45",
|
|
57
|
+
"openinference-instrumentation-llama-index>=4.3.1",
|
|
58
|
+
"psycopg2-binary>=2.9.10",
|
|
59
|
+
"uvicorn[standard]>=0.35.0",
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
[tool.uv]
|
|
63
|
+
# Install dev dependencies by default when running uv sync
|
|
64
|
+
default-groups = ["dev"]
|
|
65
|
+
# Use highest resolution strategy for dependencies
|
|
66
|
+
resolution = "highest"
|
|
67
|
+
# Compile bytecode for faster subsequent runs
|
|
68
|
+
compile-bytecode = true
|
|
69
|
+
|
|
70
|
+
[project.scripts]
|
|
71
|
+
qtype = "qtype.cli:main"
|
|
72
|
+
|
|
73
|
+
[tool.setuptools.packages.find]
|
|
74
|
+
include = ["qtype*"]
|
|
75
|
+
exclude = ["tests*"]
|
|
76
|
+
|
|
77
|
+
# Tool configurations
|
|
78
|
+
[tool.ruff]
|
|
79
|
+
line-length = 79
|
|
80
|
+
target-version = "py310"
|
|
81
|
+
|
|
82
|
+
[tool.ruff.format]
|
|
83
|
+
quote-style = "double"
|
|
84
|
+
indent-style = "space"
|
|
85
|
+
line-ending = "auto"
|
|
86
|
+
|
|
87
|
+
[tool.ruff.lint]
|
|
88
|
+
select = ["E", "F", "W"]
|
|
89
|
+
ignore = ["E501"] # Let ruff handle line length
|
|
90
|
+
|
|
91
|
+
[tool.isort]
|
|
92
|
+
line_length = 79
|
|
93
|
+
multi_line_output = 3
|
|
94
|
+
include_trailing_comma = true
|
|
95
|
+
force_grid_wrap = 0
|
|
96
|
+
use_parentheses = true
|
|
97
|
+
ensure_newline_before_comments = true
|
|
98
|
+
|
|
99
|
+
[tool.mypy]
|
|
100
|
+
python_version = "3.10"
|
|
101
|
+
warn_return_any = true
|
|
102
|
+
warn_unused_configs = true
|
|
103
|
+
disallow_untyped_defs = true
|
|
104
|
+
plugins = ["pydantic.mypy"]
|
|
105
|
+
|
|
106
|
+
[[tool.mypy.overrides]]
|
|
107
|
+
module = "tests.*"
|
|
108
|
+
disallow_untyped_defs = false
|
|
109
|
+
|
|
110
|
+
[tool.pydantic-mypy]
|
|
111
|
+
init_forbid_extra = true
|
|
112
|
+
init_typed = true
|
|
113
|
+
warn_required_dynamic_aliases = true
|
|
114
|
+
|
|
115
|
+
[tool.coverage.run]
|
|
116
|
+
source = ["qtype"]
|
|
117
|
+
omit = [
|
|
118
|
+
"*/tests/*",
|
|
119
|
+
"*/test_*",
|
|
120
|
+
"*/__pycache__/*",
|
|
121
|
+
"*/venv/*",
|
|
122
|
+
"*/.venv/*",
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
[tool.coverage.report]
|
|
126
|
+
exclude_lines = [
|
|
127
|
+
"pragma: no cover",
|
|
128
|
+
"def __repr__",
|
|
129
|
+
"if self.debug:",
|
|
130
|
+
"if settings.DEBUG",
|
|
131
|
+
"raise AssertionError",
|
|
132
|
+
"raise NotImplementedError",
|
|
133
|
+
"if 0:",
|
|
134
|
+
"if __name__ == .__main__.:",
|
|
135
|
+
"class .*\\bProtocol\\):",
|
|
136
|
+
"@(abc\\.)?abstractmethod",
|
|
137
|
+
]
|
|
138
|
+
show_missing = true
|
|
139
|
+
precision = 2
|
|
140
|
+
|
|
141
|
+
[tool.coverage.html]
|
|
142
|
+
directory = "htmlcov"
|
|
143
|
+
|
|
144
|
+
[tool.pytest.ini_options]
|
|
145
|
+
testpaths = ["tests"]
|
|
146
|
+
python_files = ["test_*.py", "*_test.py"]
|
|
147
|
+
python_classes = ["Test*"]
|
|
148
|
+
python_functions = ["test_*"]
|
|
149
|
+
addopts = [
|
|
150
|
+
"--strict-markers",
|
|
151
|
+
"--strict-config",
|
|
152
|
+
"--verbose",
|
|
153
|
+
"--tb=short",
|
|
154
|
+
"-ra",
|
|
155
|
+
]
|
|
156
|
+
filterwarnings = [
|
|
157
|
+
"ignore::DeprecationWarning",
|
|
158
|
+
"ignore::PendingDeprecationWarning",
|
|
159
|
+
]
|
|
160
|
+
markers = [
|
|
161
|
+
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
|
|
162
|
+
"network: marks tests as requiring network access",
|
|
163
|
+
]
|
|
File without changes
|
qtype-0.0.1/qtype/cli.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QType CLI entry point for generating schemas and validating QType specs.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import importlib
|
|
7
|
+
import logging
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _discover_commands(subparsers: argparse._SubParsersAction) -> None:
|
|
12
|
+
"""Automatically discover and register command modules.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
subparsers: The subparsers object to add commands to.
|
|
16
|
+
"""
|
|
17
|
+
commands_dir = Path(__file__).parent / "commands"
|
|
18
|
+
|
|
19
|
+
for py_file in commands_dir.glob("*.py"):
|
|
20
|
+
# Skip __init__.py and other private files
|
|
21
|
+
if py_file.name.startswith("_"):
|
|
22
|
+
continue
|
|
23
|
+
|
|
24
|
+
module_name = f"qtype.commands.{py_file.stem}"
|
|
25
|
+
try:
|
|
26
|
+
module = importlib.import_module(module_name)
|
|
27
|
+
# Call the parser function to set up the subparser
|
|
28
|
+
if hasattr(module, "parser"):
|
|
29
|
+
module.parser(subparsers)
|
|
30
|
+
else:
|
|
31
|
+
logging.warning(
|
|
32
|
+
f"Command module {module_name} does not have a 'parser' function"
|
|
33
|
+
)
|
|
34
|
+
except Exception as e:
|
|
35
|
+
logging.error(
|
|
36
|
+
f"Failed to load command module {module_name}: {e}",
|
|
37
|
+
exc_info=True,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def main() -> None:
|
|
42
|
+
"""
|
|
43
|
+
Main entry point for the QType CLI.
|
|
44
|
+
Sets up argument parsing and dispatches to the appropriate subcommand.
|
|
45
|
+
"""
|
|
46
|
+
parser = argparse.ArgumentParser(
|
|
47
|
+
description="QType CLI: Generate schema, validate, or run QType specs."
|
|
48
|
+
)
|
|
49
|
+
parser.add_argument(
|
|
50
|
+
"--log-level",
|
|
51
|
+
default="INFO",
|
|
52
|
+
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
|
53
|
+
help="Set the logging level (default: INFO)",
|
|
54
|
+
)
|
|
55
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
56
|
+
|
|
57
|
+
# Auto-discover and register commands
|
|
58
|
+
_discover_commands(subparsers)
|
|
59
|
+
|
|
60
|
+
args = parser.parse_args()
|
|
61
|
+
|
|
62
|
+
# Set logging level based on user input
|
|
63
|
+
logging.basicConfig(
|
|
64
|
+
level=getattr(logging, args.log_level),
|
|
65
|
+
format="%(levelname)s: %(message)s",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# Dispatch to the selected subcommand
|
|
69
|
+
args.func(args)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if __name__ == "__main__":
|
|
73
|
+
main()
|