qtype 0.0.1__py3-none-any.whl → 0.0.3__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.
- qtype/interpreter/conversions.py +7 -2
- qtype/semantic/base_types.py +47 -0
- qtype/semantic/generate.py +2 -8
- qtype/semantic/model.py +2 -12
- {qtype-0.0.1.dist-info → qtype-0.0.3.dist-info}/METADATA +13 -1
- {qtype-0.0.1.dist-info → qtype-0.0.3.dist-info}/RECORD +10 -9
- {qtype-0.0.1.dist-info → qtype-0.0.3.dist-info}/WHEEL +0 -0
- {qtype-0.0.1.dist-info → qtype-0.0.3.dist-info}/entry_points.txt +0 -0
- {qtype-0.0.1.dist-info → qtype-0.0.3.dist-info}/licenses/LICENSE +0 -0
- {qtype-0.0.1.dist-info → qtype-0.0.3.dist-info}/top_level.txt +0 -0
qtype/interpreter/conversions.py
CHANGED
|
@@ -39,6 +39,7 @@ def to_llm(model: Model, system_prompt: str | None) -> BaseLLM:
|
|
|
39
39
|
# BedrockConverse requires a model_id and system_prompt
|
|
40
40
|
# Inference params can be passed as additional kwargs
|
|
41
41
|
from llama_index.llms.bedrock_converse import BedrockConverse
|
|
42
|
+
|
|
42
43
|
brv: BaseLLM = BedrockConverse(
|
|
43
44
|
model=model.model_id if model.model_id else model.id,
|
|
44
45
|
system_prompt=system_prompt,
|
|
@@ -47,14 +48,18 @@ def to_llm(model: Model, system_prompt: str | None) -> BaseLLM:
|
|
|
47
48
|
return brv
|
|
48
49
|
elif model.provider == "openai":
|
|
49
50
|
from llama_index.llms.openai import OpenAI
|
|
51
|
+
|
|
50
52
|
return OpenAI(
|
|
51
53
|
model=model.model_id if model.model_id else model.id,
|
|
52
54
|
system_prompt=system_prompt,
|
|
53
55
|
**(model.inference_params if model.inference_params else {}),
|
|
54
|
-
api_key=model.auth.api_key
|
|
56
|
+
api_key=model.auth.api_key
|
|
57
|
+
if model.auth and model.auth.api_key
|
|
58
|
+
else None,
|
|
55
59
|
)
|
|
56
60
|
elif model.provider == "anthropic":
|
|
57
61
|
from llama_index.llms.anthropic import Anthropic
|
|
62
|
+
|
|
58
63
|
arv: BaseLLM = Anthropic(
|
|
59
64
|
model=model.model_id if model.model_id else model.id,
|
|
60
65
|
system_prompt=system_prompt,
|
|
@@ -71,7 +76,7 @@ def to_llm(model: Model, system_prompt: str | None) -> BaseLLM:
|
|
|
71
76
|
def to_embedding_model(model: Model) -> BaseEmbedding:
|
|
72
77
|
"""Convert a qtype Model to a LlamaIndex embedding model."""
|
|
73
78
|
|
|
74
|
-
if model.provider in {"bedrock","aws", "aws-bedrock"}:
|
|
79
|
+
if model.provider in {"bedrock", "aws", "aws-bedrock"}:
|
|
75
80
|
from llama_index.embeddings.bedrock import BedrockEmbedding
|
|
76
81
|
|
|
77
82
|
embedding: BaseEmbedding = BedrockEmbedding(
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _make_hashable(value: Any) -> Any:
|
|
9
|
+
"""Convert a value to a hashable equivalent."""
|
|
10
|
+
if isinstance(value, BaseModel):
|
|
11
|
+
# Handle Pydantic models by iterating over their fields
|
|
12
|
+
hashable_values = []
|
|
13
|
+
for field_name, field_value in value.model_dump().items():
|
|
14
|
+
hashable_values.append((field_name, _make_hashable(field_value)))
|
|
15
|
+
return tuple(sorted(hashable_values))
|
|
16
|
+
elif isinstance(value, dict):
|
|
17
|
+
return frozenset(
|
|
18
|
+
(k, _make_hashable(v)) for k, v in sorted(value.items())
|
|
19
|
+
)
|
|
20
|
+
elif isinstance(value, list):
|
|
21
|
+
return tuple(_make_hashable(item) for item in value)
|
|
22
|
+
elif isinstance(value, set):
|
|
23
|
+
return frozenset(_make_hashable(item) for item in value)
|
|
24
|
+
elif hasattr(value, "__dict__"):
|
|
25
|
+
# Handle nested objects
|
|
26
|
+
return tuple(
|
|
27
|
+
sorted(
|
|
28
|
+
(k, _make_hashable(v))
|
|
29
|
+
for k, v in value.__dict__.items()
|
|
30
|
+
if not k.startswith("_")
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
else:
|
|
34
|
+
# Value is already hashable (int, str, tuple, etc.)
|
|
35
|
+
return value
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ImmutableModel(BaseModel):
|
|
39
|
+
"""Base model that can't be mutated but can be cached."""
|
|
40
|
+
|
|
41
|
+
id: str = Field(..., description="Unique ID of this model.")
|
|
42
|
+
|
|
43
|
+
model_config = ConfigDict(frozen=True)
|
|
44
|
+
|
|
45
|
+
def __hash__(self) -> int:
|
|
46
|
+
"""Hash based on all model fields."""
|
|
47
|
+
return hash(_make_hashable(self))
|
qtype/semantic/generate.py
CHANGED
|
@@ -108,7 +108,7 @@ def generate_semantic_model(args: argparse.Namespace) -> None:
|
|
|
108
108
|
# Write imports
|
|
109
109
|
f.write("from __future__ import annotations\n\n")
|
|
110
110
|
f.write("from typing import Any, Type\n\n")
|
|
111
|
-
f.write("from pydantic import BaseModel,
|
|
111
|
+
f.write("from pydantic import BaseModel, Field\n\n")
|
|
112
112
|
f.write("# Import enums and type aliases from DSL\n")
|
|
113
113
|
f.write("from qtype.dsl.model import VariableType # noqa: F401\n")
|
|
114
114
|
f.write(
|
|
@@ -117,6 +117,7 @@ def generate_semantic_model(args: argparse.Namespace) -> None:
|
|
|
117
117
|
f.write(
|
|
118
118
|
"from qtype.dsl.model import Variable as DSLVariable # noqa: F401\n"
|
|
119
119
|
)
|
|
120
|
+
f.write("from qtype.semantic.base_types import ImmutableModel\n")
|
|
120
121
|
|
|
121
122
|
# Write the new variable class
|
|
122
123
|
f.write("class Variable(DSLVariable, BaseModel):\n")
|
|
@@ -129,13 +130,6 @@ def generate_semantic_model(args: argparse.Namespace) -> None:
|
|
|
129
130
|
f.write(" def is_set(self) -> bool:\n")
|
|
130
131
|
f.write(" return self.value is not None\n")
|
|
131
132
|
|
|
132
|
-
# Write the new ImmutableModel class
|
|
133
|
-
f.write("\n\nclass ImmutableModel(BaseModel):\n")
|
|
134
|
-
f.write(
|
|
135
|
-
' """Base model that can\'t be mutated but can be cached."""\n'
|
|
136
|
-
)
|
|
137
|
-
f.write(" model_config = ConfigDict(frozen=True)\n\n")
|
|
138
|
-
|
|
139
133
|
# Write classes
|
|
140
134
|
f.write("\n\n".join(generated))
|
|
141
135
|
f.write("\n\n")
|
qtype/semantic/model.py
CHANGED
|
@@ -13,7 +13,7 @@ from __future__ import annotations
|
|
|
13
13
|
|
|
14
14
|
from typing import Any
|
|
15
15
|
|
|
16
|
-
from pydantic import BaseModel,
|
|
16
|
+
from pydantic import BaseModel, Field
|
|
17
17
|
|
|
18
18
|
# Import enums and type aliases from DSL
|
|
19
19
|
from qtype.dsl.model import VariableType # noqa: F401
|
|
@@ -24,6 +24,7 @@ from qtype.dsl.model import (
|
|
|
24
24
|
StructuralTypeEnum,
|
|
25
25
|
)
|
|
26
26
|
from qtype.dsl.model import Variable as DSLVariable # noqa: F401
|
|
27
|
+
from qtype.semantic.base_types import ImmutableModel
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
class Variable(DSLVariable, BaseModel):
|
|
@@ -35,17 +36,6 @@ class Variable(DSLVariable, BaseModel):
|
|
|
35
36
|
return self.value is not None
|
|
36
37
|
|
|
37
38
|
|
|
38
|
-
class ImmutableModel(BaseModel):
|
|
39
|
-
"""Base model that can't be mutated but can be cached."""
|
|
40
|
-
|
|
41
|
-
id: str = Field(..., description="Unique ID of this model.")
|
|
42
|
-
|
|
43
|
-
model_config = ConfigDict(frozen=True)
|
|
44
|
-
|
|
45
|
-
def __hash__(self) -> int:
|
|
46
|
-
return hash(self.id) # Hash based on a hashable field
|
|
47
|
-
|
|
48
|
-
|
|
49
39
|
class Application(BaseModel):
|
|
50
40
|
"""Defines a QType application that can include models, variables, and other components."""
|
|
51
41
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: qtype
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Summary: DSL for Generative AI Prototyping
|
|
5
5
|
Author-email: Lou Kratz <lou.kratz+qtype@bazaarvoice.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -15,6 +15,18 @@ Requires-Dist: python-dotenv>=1.0.0
|
|
|
15
15
|
Requires-Dist: openai>=1.93.0
|
|
16
16
|
Requires-Dist: fsspec>=2025.5.1
|
|
17
17
|
Requires-Dist: pydantic-yaml>=1.5.1
|
|
18
|
+
Provides-Extra: interpreter
|
|
19
|
+
Requires-Dist: arize-phoenix-otel>=0.12.1; extra == "interpreter"
|
|
20
|
+
Requires-Dist: boto3>=1.34.0; extra == "interpreter"
|
|
21
|
+
Requires-Dist: fastapi>=0.116.1; extra == "interpreter"
|
|
22
|
+
Requires-Dist: llama-index-embeddings-bedrock>=0.5.2; extra == "interpreter"
|
|
23
|
+
Requires-Dist: llama-index-embeddings-openai>=0.3.1; extra == "interpreter"
|
|
24
|
+
Requires-Dist: llama-index-llms-bedrock-converse>=0.7.4; extra == "interpreter"
|
|
25
|
+
Requires-Dist: llama-index-llms-bedrock>=0.3.8; extra == "interpreter"
|
|
26
|
+
Requires-Dist: llama-index>=0.12.45; extra == "interpreter"
|
|
27
|
+
Requires-Dist: openinference-instrumentation-llama-index>=4.3.1; extra == "interpreter"
|
|
28
|
+
Requires-Dist: psycopg2-binary>=2.9.10; extra == "interpreter"
|
|
29
|
+
Requires-Dist: uvicorn[standard]>=0.35.0; extra == "interpreter"
|
|
18
30
|
Dynamic: license-file
|
|
19
31
|
|
|
20
32
|
# QType
|
|
@@ -21,7 +21,7 @@ qtype/dsl/model.py,sha256=mAgqfG1us1mT53nYd0gAIwOSgudLSDlwQjUlG5MDfRg,21169
|
|
|
21
21
|
qtype/dsl/validator.py,sha256=yuDFPHfErPTIpZXCIyBrwpZJAitMEW0jNL8867KixUA,17130
|
|
22
22
|
qtype/interpreter/__init__.py,sha256=IaRF90JLFbsTLKz9LTOMI_Pz4xwVaEyXPNaXV7sLou8,43
|
|
23
23
|
qtype/interpreter/api.py,sha256=DrBV0fF6f4HiGSgXzHE07FwOr5Qe7uBQ2yQ6UjDOUTU,3872
|
|
24
|
-
qtype/interpreter/conversions.py,sha256=
|
|
24
|
+
qtype/interpreter/conversions.py,sha256=d_hyWWR0PlhvRf2EiNt1sEzhFH8gIl3vMrVnSOFUZGk,5612
|
|
25
25
|
qtype/interpreter/exceptions.py,sha256=Il8IF0UAtYWQXwvOVQCY-csfRzC1iOejHM1G-nF5EfY,288
|
|
26
26
|
qtype/interpreter/flow.py,sha256=2u1wRahNFQaRRklnU4uW7_UKSD73-uZe_WiYlKitXQg,1233
|
|
27
27
|
qtype/interpreter/resource_cache.py,sha256=XylIIh7RFHs4JdOZWx24a3P-sH0qjgqU9_vri9ztAXU,1014
|
|
@@ -37,13 +37,14 @@ qtype/interpreter/steps/prompt_template.py,sha256=Hs4ZANMqDViZVEPhD2v6JcUJ0DdMka
|
|
|
37
37
|
qtype/interpreter/steps/search.py,sha256=wyVFwg5wVXytsm2JyNPwkuBAWpxEunP-dAiqhDZyii4,660
|
|
38
38
|
qtype/interpreter/steps/tool.py,sha256=zAL9us_KRrcaw_sktD1z2pm0Z2W9ruMd3rrjqk7TI_k,1996
|
|
39
39
|
qtype/semantic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
40
|
+
qtype/semantic/base_types.py,sha256=wfUlT0gV3_Mk1xLLI64SSXCB9GFmn29yz5adTaHrsOI,1540
|
|
40
41
|
qtype/semantic/errors.py,sha256=dmdxGkVHrTwfiEHj5RFu2q11dAtefsivpLdJd6QynK0,119
|
|
41
|
-
qtype/semantic/generate.py,sha256=
|
|
42
|
-
qtype/semantic/model.py,sha256=
|
|
42
|
+
qtype/semantic/generate.py,sha256=U4r5Yo1b0wTBgw3dLnqjYD6wD6lc0TqdwUjhIV_yQRI,13085
|
|
43
|
+
qtype/semantic/model.py,sha256=Hd3rsTdvkHtAeIrPqpJf0yjHa697TnrUbm3pbrIgSK0,11047
|
|
43
44
|
qtype/semantic/resolver.py,sha256=D3CmRmr_ACL54ZCbc9HxXCuCZ37bNtSzlPLMpOeeOcw,3439
|
|
44
|
-
qtype-0.0.
|
|
45
|
-
qtype-0.0.
|
|
46
|
-
qtype-0.0.
|
|
47
|
-
qtype-0.0.
|
|
48
|
-
qtype-0.0.
|
|
49
|
-
qtype-0.0.
|
|
45
|
+
qtype-0.0.3.dist-info/licenses/LICENSE,sha256=1KA5EgYBSR0O6nCH2HEvk6Di53YKJ9r_VCR7G8G8qAY,11341
|
|
46
|
+
qtype-0.0.3.dist-info/METADATA,sha256=F4WqzZVkHDvHI8gl7bzB7P0bGbQcYGuUoB-Wb4SOkLE,4809
|
|
47
|
+
qtype-0.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
48
|
+
qtype-0.0.3.dist-info/entry_points.txt,sha256=5y4vj8RLvgl2tXSj-Hm7v5-Tn3kP4-UonjNoN-mfaQE,41
|
|
49
|
+
qtype-0.0.3.dist-info/top_level.txt,sha256=ONroH5B0mZ51jr7NSWCK0weFwwCO7wBLmyVS1YqNU14,6
|
|
50
|
+
qtype-0.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|