qtype 0.0.12__py3-none-any.whl → 0.1.7__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/application/commons/tools.py +1 -1
- qtype/application/converters/tools_from_api.py +476 -11
- qtype/application/converters/tools_from_module.py +38 -14
- qtype/application/converters/types.py +15 -30
- qtype/application/documentation.py +1 -1
- qtype/application/facade.py +102 -85
- qtype/base/types.py +227 -7
- qtype/cli.py +5 -1
- qtype/commands/convert.py +52 -6
- qtype/commands/generate.py +44 -4
- qtype/commands/run.py +78 -36
- qtype/commands/serve.py +74 -44
- qtype/commands/validate.py +37 -14
- qtype/commands/visualize.py +46 -25
- qtype/dsl/__init__.py +6 -5
- qtype/dsl/custom_types.py +1 -1
- qtype/dsl/domain_types.py +86 -5
- qtype/dsl/linker.py +384 -0
- qtype/dsl/loader.py +315 -0
- qtype/dsl/model.py +753 -264
- qtype/dsl/parser.py +200 -0
- qtype/dsl/types.py +50 -0
- qtype/interpreter/api.py +63 -136
- qtype/interpreter/auth/aws.py +19 -9
- qtype/interpreter/auth/generic.py +93 -16
- qtype/interpreter/base/base_step_executor.py +436 -0
- qtype/interpreter/base/batch_step_executor.py +171 -0
- qtype/interpreter/base/exceptions.py +50 -0
- qtype/interpreter/base/executor_context.py +91 -0
- qtype/interpreter/base/factory.py +84 -0
- qtype/interpreter/base/progress_tracker.py +110 -0
- qtype/interpreter/base/secrets.py +339 -0
- qtype/interpreter/base/step_cache.py +74 -0
- qtype/interpreter/base/stream_emitter.py +469 -0
- qtype/interpreter/conversions.py +495 -24
- qtype/interpreter/converters.py +79 -0
- qtype/interpreter/endpoints.py +355 -0
- qtype/interpreter/executors/agent_executor.py +242 -0
- qtype/interpreter/executors/aggregate_executor.py +93 -0
- qtype/interpreter/executors/bedrock_reranker_executor.py +195 -0
- qtype/interpreter/executors/decoder_executor.py +163 -0
- qtype/interpreter/executors/doc_to_text_executor.py +112 -0
- qtype/interpreter/executors/document_embedder_executor.py +123 -0
- qtype/interpreter/executors/document_search_executor.py +113 -0
- qtype/interpreter/executors/document_source_executor.py +118 -0
- qtype/interpreter/executors/document_splitter_executor.py +105 -0
- qtype/interpreter/executors/echo_executor.py +63 -0
- qtype/interpreter/executors/field_extractor_executor.py +165 -0
- qtype/interpreter/executors/file_source_executor.py +101 -0
- qtype/interpreter/executors/file_writer_executor.py +110 -0
- qtype/interpreter/executors/index_upsert_executor.py +232 -0
- qtype/interpreter/executors/invoke_embedding_executor.py +104 -0
- qtype/interpreter/executors/invoke_flow_executor.py +51 -0
- qtype/interpreter/executors/invoke_tool_executor.py +358 -0
- qtype/interpreter/executors/llm_inference_executor.py +272 -0
- qtype/interpreter/executors/prompt_template_executor.py +78 -0
- qtype/interpreter/executors/sql_source_executor.py +106 -0
- qtype/interpreter/executors/vector_search_executor.py +91 -0
- qtype/interpreter/flow.py +172 -22
- qtype/interpreter/logging_progress.py +61 -0
- qtype/interpreter/metadata_api.py +115 -0
- qtype/interpreter/resource_cache.py +5 -4
- qtype/interpreter/rich_progress.py +225 -0
- qtype/interpreter/stream/chat/__init__.py +15 -0
- qtype/interpreter/stream/chat/converter.py +391 -0
- qtype/interpreter/{chat → stream/chat}/file_conversions.py +2 -2
- qtype/interpreter/stream/chat/ui_request_to_domain_type.py +140 -0
- qtype/interpreter/stream/chat/vercel.py +609 -0
- qtype/interpreter/stream/utils/__init__.py +15 -0
- qtype/interpreter/stream/utils/build_vercel_ai_formatter.py +74 -0
- qtype/interpreter/stream/utils/callback_to_stream.py +66 -0
- qtype/interpreter/stream/utils/create_streaming_response.py +18 -0
- qtype/interpreter/stream/utils/default_chat_extract_text.py +20 -0
- qtype/interpreter/stream/utils/error_streaming_response.py +20 -0
- qtype/interpreter/telemetry.py +135 -8
- qtype/interpreter/tools/__init__.py +5 -0
- qtype/interpreter/tools/function_tool_helper.py +265 -0
- qtype/interpreter/types.py +330 -0
- qtype/interpreter/typing.py +83 -89
- qtype/interpreter/ui/404/index.html +1 -1
- qtype/interpreter/ui/404.html +1 -1
- qtype/interpreter/ui/_next/static/{OT8QJQW3J70VbDWWfrEMT → 20HoJN6otZ_LyHLHpCPE6}/_buildManifest.js +1 -1
- qtype/interpreter/ui/_next/static/chunks/434-b2112d19f25c44ff.js +36 -0
- qtype/interpreter/ui/_next/static/chunks/{964-ed4ab073db645007.js → 964-2b041321a01cbf56.js} +1 -1
- qtype/interpreter/ui/_next/static/chunks/app/{layout-5ccbc44fd528d089.js → layout-a05273ead5de2c41.js} +1 -1
- qtype/interpreter/ui/_next/static/chunks/app/page-8c67d16ac90d23cb.js +1 -0
- qtype/interpreter/ui/_next/static/chunks/ba12c10f-546f2714ff8abc66.js +1 -0
- qtype/interpreter/ui/_next/static/chunks/{main-6d261b6c5d6fb6c2.js → main-e26b9cb206da2cac.js} +1 -1
- qtype/interpreter/ui/_next/static/chunks/webpack-08642e441b39b6c2.js +1 -0
- qtype/interpreter/ui/_next/static/css/8a8d1269e362fef7.css +3 -0
- qtype/interpreter/ui/_next/static/media/4cf2300e9c8272f7-s.p.woff2 +0 -0
- qtype/interpreter/ui/icon.png +0 -0
- qtype/interpreter/ui/index.html +1 -1
- qtype/interpreter/ui/index.txt +5 -5
- qtype/semantic/checker.py +643 -0
- qtype/semantic/generate.py +268 -85
- qtype/semantic/loader.py +95 -0
- qtype/semantic/model.py +535 -163
- qtype/semantic/resolver.py +63 -19
- qtype/semantic/visualize.py +50 -35
- {qtype-0.0.12.dist-info → qtype-0.1.7.dist-info}/METADATA +22 -5
- qtype-0.1.7.dist-info/RECORD +137 -0
- qtype/dsl/base_types.py +0 -38
- qtype/dsl/validator.py +0 -464
- qtype/interpreter/batch/__init__.py +0 -0
- qtype/interpreter/batch/flow.py +0 -95
- qtype/interpreter/batch/sql_source.py +0 -95
- qtype/interpreter/batch/step.py +0 -63
- qtype/interpreter/batch/types.py +0 -41
- qtype/interpreter/batch/utils.py +0 -179
- qtype/interpreter/chat/chat_api.py +0 -237
- qtype/interpreter/chat/vercel.py +0 -314
- qtype/interpreter/exceptions.py +0 -10
- qtype/interpreter/step.py +0 -67
- qtype/interpreter/steps/__init__.py +0 -0
- qtype/interpreter/steps/agent.py +0 -114
- qtype/interpreter/steps/condition.py +0 -36
- qtype/interpreter/steps/decoder.py +0 -88
- qtype/interpreter/steps/llm_inference.py +0 -150
- qtype/interpreter/steps/prompt_template.py +0 -54
- qtype/interpreter/steps/search.py +0 -24
- qtype/interpreter/steps/tool.py +0 -53
- qtype/interpreter/streaming_helpers.py +0 -123
- qtype/interpreter/ui/_next/static/chunks/736-7fc606e244fedcb1.js +0 -36
- qtype/interpreter/ui/_next/static/chunks/app/page-c72e847e888e549d.js +0 -1
- qtype/interpreter/ui/_next/static/chunks/ba12c10f-22556063851a6df2.js +0 -1
- qtype/interpreter/ui/_next/static/chunks/webpack-8289c17c67827f22.js +0 -1
- qtype/interpreter/ui/_next/static/css/a262c53826df929b.css +0 -3
- qtype/interpreter/ui/_next/static/media/569ce4b8f30dc480-s.p.woff2 +0 -0
- qtype/interpreter/ui/favicon.ico +0 -0
- qtype/loader.py +0 -389
- qtype-0.0.12.dist-info/RECORD +0 -105
- /qtype/interpreter/ui/_next/static/{OT8QJQW3J70VbDWWfrEMT → 20HoJN6otZ_LyHLHpCPE6}/_ssgManifest.js +0 -0
- {qtype-0.0.12.dist-info → qtype-0.1.7.dist-info}/WHEEL +0 -0
- {qtype-0.0.12.dist-info → qtype-0.1.7.dist-info}/entry_points.txt +0 -0
- {qtype-0.0.12.dist-info → qtype-0.1.7.dist-info}/licenses/LICENSE +0 -0
- {qtype-0.0.12.dist-info → qtype-0.1.7.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
from qtype.base.types import PrimitiveTypeEnum
|
|
6
|
+
from qtype.dsl.domain_types import ChatContent, ChatMessage, MessageRole
|
|
7
|
+
from qtype.interpreter.stream.chat.file_conversions import file_to_content
|
|
8
|
+
from qtype.interpreter.stream.chat.vercel import (
|
|
9
|
+
ChatRequest,
|
|
10
|
+
CompletionRequest,
|
|
11
|
+
UIMessage,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def ui_request_to_domain_type(request: ChatRequest) -> list[ChatMessage]:
|
|
16
|
+
"""
|
|
17
|
+
Convert a ChatRequest to domain-specific ChatMessages.
|
|
18
|
+
|
|
19
|
+
Processes all UI messages from the AI SDK UI/React request format.
|
|
20
|
+
Returns the full conversation history for context.
|
|
21
|
+
"""
|
|
22
|
+
if not request.messages:
|
|
23
|
+
raise ValueError("No messages provided in request.")
|
|
24
|
+
|
|
25
|
+
# Convert each UIMessage to a domain-specific ChatMessage
|
|
26
|
+
return [
|
|
27
|
+
_ui_message_to_domain_type(message) for message in request.messages
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _ui_message_to_domain_type(message: UIMessage) -> ChatMessage:
|
|
32
|
+
"""
|
|
33
|
+
Convert a UIMessage to a domain-specific ChatMessage.
|
|
34
|
+
|
|
35
|
+
Creates one block for each part in the message content.
|
|
36
|
+
"""
|
|
37
|
+
blocks = []
|
|
38
|
+
|
|
39
|
+
for part in message.parts:
|
|
40
|
+
if part.type == "text":
|
|
41
|
+
blocks.append(
|
|
42
|
+
ChatContent(type=PrimitiveTypeEnum.text, content=part.text)
|
|
43
|
+
)
|
|
44
|
+
elif part.type == "reasoning":
|
|
45
|
+
blocks.append(
|
|
46
|
+
ChatContent(type=PrimitiveTypeEnum.text, content=part.text)
|
|
47
|
+
)
|
|
48
|
+
elif part.type == "file":
|
|
49
|
+
blocks.append(
|
|
50
|
+
file_to_content(part.url) # type: ignore
|
|
51
|
+
)
|
|
52
|
+
elif part.type == "source-url":
|
|
53
|
+
# Source URLs are references that might be displayed as citations
|
|
54
|
+
# Store as structured citation data
|
|
55
|
+
citation_data = {
|
|
56
|
+
"source_id": part.source_id, # type: ignore
|
|
57
|
+
"url": part.url, # type: ignore
|
|
58
|
+
"title": part.title, # type: ignore
|
|
59
|
+
}
|
|
60
|
+
blocks.append(
|
|
61
|
+
ChatContent(
|
|
62
|
+
type=PrimitiveTypeEnum.citation_url,
|
|
63
|
+
content=citation_data,
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
elif part.type == "source-document":
|
|
67
|
+
# Source documents are references to documents
|
|
68
|
+
# Store as structured citation data
|
|
69
|
+
citation_data = {
|
|
70
|
+
"source_id": part.source_id, # type: ignore
|
|
71
|
+
"title": part.title, # type: ignore
|
|
72
|
+
"filename": part.filename, # type: ignore
|
|
73
|
+
"media_type": part.media_type, # type: ignore
|
|
74
|
+
}
|
|
75
|
+
blocks.append(
|
|
76
|
+
ChatContent(
|
|
77
|
+
type=PrimitiveTypeEnum.citation_document,
|
|
78
|
+
content=citation_data,
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
elif part.type == "step-start":
|
|
82
|
+
# Step boundaries might not need content blocks
|
|
83
|
+
continue
|
|
84
|
+
else:
|
|
85
|
+
# Log unknown part types for debugging
|
|
86
|
+
raise ValueError(f"Unknown part type: {part.type}")
|
|
87
|
+
|
|
88
|
+
# If no blocks were created, raise an error
|
|
89
|
+
if not blocks:
|
|
90
|
+
raise ValueError(
|
|
91
|
+
"No valid content blocks created from UIMessage parts."
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
return ChatMessage(
|
|
95
|
+
role=MessageRole(message.role),
|
|
96
|
+
blocks=blocks,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def completion_request_to_input_model(
|
|
101
|
+
request: CompletionRequest, input_model: type[BaseModel]
|
|
102
|
+
) -> BaseModel:
|
|
103
|
+
"""
|
|
104
|
+
Convert a CompletionRequest to a flow's input model.
|
|
105
|
+
|
|
106
|
+
The CompletionRequest has a required 'prompt' field.
|
|
107
|
+
This function maps the request data to the flow's input shape.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
request: The Vercel CompletionRequest with prompt and additional fields
|
|
111
|
+
input_model: The Pydantic model class created by create_input_shape()
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
An instance of input_model with data from the request
|
|
115
|
+
|
|
116
|
+
Raises:
|
|
117
|
+
ValueError: If required fields are missing or data doesn't match schema
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
prompt_str = request.prompt
|
|
121
|
+
|
|
122
|
+
# Get the field name from the input model
|
|
123
|
+
# The semantic checker ensures there's exactly one field for Complete flows
|
|
124
|
+
field_names = list(input_model.model_fields.keys())
|
|
125
|
+
if len(field_names) != 1:
|
|
126
|
+
raise ValueError(
|
|
127
|
+
(
|
|
128
|
+
f"Expected exactly one input field for Complete flow, "
|
|
129
|
+
f"found {len(field_names)}: {field_names}"
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
field_name = field_names[0]
|
|
133
|
+
|
|
134
|
+
# Create instance of the input model with the prompt mapped to the field
|
|
135
|
+
try:
|
|
136
|
+
return input_model(**{field_name: prompt_str})
|
|
137
|
+
except Exception as e:
|
|
138
|
+
raise ValueError(
|
|
139
|
+
f"Failed to map CompletionRequest to input model: {e}"
|
|
140
|
+
) from e
|