aiqtoolkit 1.2.0a20250609__py3-none-any.whl → 1.2.0a20250610__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.
Potentially problematic release.
This version of aiqtoolkit might be problematic. Click here for more details.
- aiq/data_models/intermediate_step.py +23 -0
- aiq/observability/async_otel_listener.py +30 -0
- aiq/profiler/callbacks/langchain_callback_handler.py +22 -10
- {aiqtoolkit-1.2.0a20250609.dist-info → aiqtoolkit-1.2.0a20250610.dist-info}/METADATA +1 -1
- {aiqtoolkit-1.2.0a20250609.dist-info → aiqtoolkit-1.2.0a20250610.dist-info}/RECORD +10 -10
- {aiqtoolkit-1.2.0a20250609.dist-info → aiqtoolkit-1.2.0a20250610.dist-info}/WHEEL +0 -0
- {aiqtoolkit-1.2.0a20250609.dist-info → aiqtoolkit-1.2.0a20250610.dist-info}/entry_points.txt +0 -0
- {aiqtoolkit-1.2.0a20250609.dist-info → aiqtoolkit-1.2.0a20250610.dist-info}/licenses/LICENSE-3rd-party.txt +0 -0
- {aiqtoolkit-1.2.0a20250609.dist-info → aiqtoolkit-1.2.0a20250610.dist-info}/licenses/LICENSE.md +0 -0
- {aiqtoolkit-1.2.0a20250609.dist-info → aiqtoolkit-1.2.0a20250610.dist-info}/top_level.txt +0 -0
|
@@ -17,6 +17,7 @@ import time
|
|
|
17
17
|
import typing
|
|
18
18
|
import uuid
|
|
19
19
|
from enum import Enum
|
|
20
|
+
from typing import Literal
|
|
20
21
|
|
|
21
22
|
from pydantic import BaseModel
|
|
22
23
|
from pydantic import ConfigDict
|
|
@@ -82,6 +83,26 @@ class UsageInfo(BaseModel):
|
|
|
82
83
|
seconds_between_calls: int = 0
|
|
83
84
|
|
|
84
85
|
|
|
86
|
+
class ToolParameters(BaseModel):
|
|
87
|
+
properties: dict[str, typing.Any] = Field(..., description="The properties of the function parameters.")
|
|
88
|
+
required: list[str] = Field(default_factory=list, description="The required properties of the function parameters.")
|
|
89
|
+
type_: Literal["object"] = Field(default="object", description="The type of the function parameters.", alias="type")
|
|
90
|
+
additionalProperties: bool = Field(default=False,
|
|
91
|
+
description="Enable function parameters allow additional properties.")
|
|
92
|
+
strict: bool = Field(default=True, description="Ensure function calls reliably adhere to the function schema.")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class ToolDetails(BaseModel):
|
|
96
|
+
name: str = Field(..., description="The name of the function.")
|
|
97
|
+
description: str = Field(..., description="The description of the function.")
|
|
98
|
+
parameters: ToolParameters = Field(..., description="The parameters of the function.")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class ToolSchema(BaseModel):
|
|
102
|
+
type: Literal["function"] = Field(..., description="The type of the tool.")
|
|
103
|
+
function: ToolDetails = Field(..., description="The function details.")
|
|
104
|
+
|
|
105
|
+
|
|
85
106
|
class TraceMetadata(BaseModel):
|
|
86
107
|
chat_responses: typing.Any | None = None
|
|
87
108
|
chat_inputs: typing.Any | None = None
|
|
@@ -91,6 +112,8 @@ class TraceMetadata(BaseModel):
|
|
|
91
112
|
span_inputs: typing.Any | None = None
|
|
92
113
|
span_outputs: typing.Any | None = None
|
|
93
114
|
provided_metadata: typing.Any | None = None
|
|
115
|
+
tools_schema: list[ToolSchema] = Field(default_factory=list,
|
|
116
|
+
description="The schema of tools used in a tool calling request.")
|
|
94
117
|
|
|
95
118
|
# Allow extra fields in the model_config to support derived models
|
|
96
119
|
model_config = ConfigDict(extra="allow")
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
# See the License for the specific language governing permissions and
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
|
|
16
|
+
import json
|
|
16
17
|
import logging
|
|
17
18
|
import re
|
|
18
19
|
import warnings
|
|
@@ -75,6 +76,24 @@ except TelemetryOptionalImportError:
|
|
|
75
76
|
set_span_in_context = dummy_set_span_in_context
|
|
76
77
|
|
|
77
78
|
|
|
79
|
+
def merge_dicts(dict1: dict, dict2: dict) -> dict:
|
|
80
|
+
"""
|
|
81
|
+
Merge two dictionaries, prioritizing non-null values from the first dictionary.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
dict1 (dict): First dictionary (higher priority)
|
|
85
|
+
dict2 (dict): Second dictionary (lower priority)
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
dict: Merged dictionary with non-null values from dict1 taking precedence
|
|
89
|
+
"""
|
|
90
|
+
result = dict2.copy() # Start with a copy of the second dictionary
|
|
91
|
+
for key, value in dict1.items():
|
|
92
|
+
if value is not None: # Only update if value is not None
|
|
93
|
+
result[key] = value
|
|
94
|
+
return result
|
|
95
|
+
|
|
96
|
+
|
|
78
97
|
def _ns_timestamp(seconds_float: float) -> int:
|
|
79
98
|
"""
|
|
80
99
|
Convert AIQ Toolkit's float `event_timestamp` (in seconds) into an integer number
|
|
@@ -285,6 +304,10 @@ class AsyncOtelSpanListener:
|
|
|
285
304
|
sub_span.set_attribute(SpanAttributes.INPUT_VALUE, serialized_input)
|
|
286
305
|
sub_span.set_attribute(SpanAttributes.INPUT_MIME_TYPE, "application/json" if is_json else "text/plain")
|
|
287
306
|
|
|
307
|
+
# Optional: add metadata to the span from TraceMetadata
|
|
308
|
+
if step.payload.metadata:
|
|
309
|
+
sub_span.set_attribute("aiq.metadata", step.payload.metadata.model_dump_json())
|
|
310
|
+
|
|
288
311
|
self._span_stack[step.UUID] = sub_span
|
|
289
312
|
|
|
290
313
|
self._outstanding_spans[step.UUID] = sub_span
|
|
@@ -323,6 +346,13 @@ class AsyncOtelSpanListener:
|
|
|
323
346
|
sub_span.set_attribute(SpanAttributes.OUTPUT_VALUE, serialized_output)
|
|
324
347
|
sub_span.set_attribute(SpanAttributes.OUTPUT_MIME_TYPE, "application/json" if is_json else "text/plain")
|
|
325
348
|
|
|
349
|
+
# # Optional: add metadata to the span from TraceMetadata
|
|
350
|
+
if step.payload.metadata:
|
|
351
|
+
start_event_metadata = json.loads(sub_span.attributes.get("aiq.metadata", {}))
|
|
352
|
+
end_event_metadata = json.loads(step.payload.metadata.model_dump_json())
|
|
353
|
+
merged_event_metadata = merge_dicts(start_event_metadata, end_event_metadata)
|
|
354
|
+
sub_span.set_attribute("aiq.metadata", json.dumps(merged_event_metadata))
|
|
355
|
+
|
|
326
356
|
end_ns = _ns_timestamp(step.payload.event_timestamp)
|
|
327
357
|
|
|
328
358
|
# End the subspan
|
|
@@ -34,6 +34,7 @@ from aiq.builder.framework_enum import LLMFrameworkEnum
|
|
|
34
34
|
from aiq.data_models.intermediate_step import IntermediateStepPayload
|
|
35
35
|
from aiq.data_models.intermediate_step import IntermediateStepType
|
|
36
36
|
from aiq.data_models.intermediate_step import StreamEventData
|
|
37
|
+
from aiq.data_models.intermediate_step import ToolSchema
|
|
37
38
|
from aiq.data_models.intermediate_step import TraceMetadata
|
|
38
39
|
from aiq.data_models.intermediate_step import UsageInfo
|
|
39
40
|
from aiq.profiler.callbacks.base_callback_class import BaseProfilerCallback
|
|
@@ -42,6 +43,16 @@ from aiq.profiler.callbacks.token_usage_base_model import TokenUsageBaseModel
|
|
|
42
43
|
logger = logging.getLogger(__name__)
|
|
43
44
|
|
|
44
45
|
|
|
46
|
+
def _extract_tools_schema(invocation_params: dict) -> list:
|
|
47
|
+
|
|
48
|
+
tools_schema = []
|
|
49
|
+
if invocation_params is not None:
|
|
50
|
+
for tool in invocation_params.get("tools", []):
|
|
51
|
+
tools_schema.append(ToolSchema(**tool))
|
|
52
|
+
|
|
53
|
+
return tools_schema
|
|
54
|
+
|
|
55
|
+
|
|
45
56
|
class LangchainProfilerHandler(AsyncCallbackHandler, BaseProfilerCallback): # pylint: disable=R0901
|
|
46
57
|
"""Callback Handler that tracks NIM info."""
|
|
47
58
|
|
|
@@ -138,16 +149,17 @@ class LangchainProfilerHandler(AsyncCallbackHandler, BaseProfilerCallback): # p
|
|
|
138
149
|
run_id = str(run_id)
|
|
139
150
|
self._run_id_to_model_name[run_id] = model_name
|
|
140
151
|
|
|
141
|
-
stats = IntermediateStepPayload(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
stats = IntermediateStepPayload(
|
|
153
|
+
event_type=IntermediateStepType.LLM_START,
|
|
154
|
+
framework=LLMFrameworkEnum.LANGCHAIN,
|
|
155
|
+
name=model_name,
|
|
156
|
+
UUID=run_id,
|
|
157
|
+
data=StreamEventData(input=copy.deepcopy(messages[0])),
|
|
158
|
+
metadata=TraceMetadata(chat_inputs=copy.deepcopy(messages[0]),
|
|
159
|
+
tools_schema=_extract_tools_schema(kwargs.get("invocation_params", {}))),
|
|
160
|
+
usage_info=UsageInfo(token_usage=TokenUsageBaseModel(),
|
|
161
|
+
num_llm_calls=1,
|
|
162
|
+
seconds_between_calls=int(time.time() - self.last_call_ts)))
|
|
151
163
|
|
|
152
164
|
self.step_manager.push_intermediate_step(stats)
|
|
153
165
|
self._run_id_to_llm_input[run_id] = messages[0][-1].content
|
|
@@ -88,7 +88,7 @@ aiq/data_models/front_end.py,sha256=z8k6lSWjt1vMOYFbjWQxodpwAqPeuGS0hRBjsriDW2s,
|
|
|
88
88
|
aiq/data_models/function.py,sha256=M_duXVXL5MvYe0WVLvqEgEzXs0UAYNSMfy9ZTpxuKPA,1013
|
|
89
89
|
aiq/data_models/function_dependencies.py,sha256=bIdfrwDT_rR5eEER2WhYtl43QaOAnTL1p8IkyGJtB_Y,2403
|
|
90
90
|
aiq/data_models/interactive.py,sha256=cYBIp3N3AaP0pxMRJFMwVoMrAWpWVT2turidhr__36A,8418
|
|
91
|
-
aiq/data_models/intermediate_step.py,sha256=
|
|
91
|
+
aiq/data_models/intermediate_step.py,sha256=XVn8MdAJAk5Yy3JfWfgUQHKqjsr5E-XrC_sluFAU8OA,11385
|
|
92
92
|
aiq/data_models/invocation_node.py,sha256=nDRylgzBfJduGA-lme9xN4P6BdOYj0L6ytLHnTuetMI,1618
|
|
93
93
|
aiq/data_models/llm.py,sha256=McbDdUUtWfp9WCdMMJA2xh7mvlmyNdGDCH8P_7l2iKU,920
|
|
94
94
|
aiq/data_models/logging.py,sha256=1QtVjIQ99PgMYUuzw4h1FAoPRteZY7uf3oFTqV3ONgA,940
|
|
@@ -174,7 +174,7 @@ aiq/memory/models.py,sha256=c5dA7nKHQ4AS1_ptQZcfC_oXO495-ehocnf_qXTE6c8,4319
|
|
|
174
174
|
aiq/meta/module_to_distro.json,sha256=1XV7edobFrdDKvsSoynfodXg_hczUWpDrQzGkW9qqEs,28
|
|
175
175
|
aiq/meta/pypi.md,sha256=Ukj1J--Q6GF7Zh1tKonygttN3aiq_Lf2-445nz0sE-o,4362
|
|
176
176
|
aiq/observability/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
177
|
-
aiq/observability/async_otel_listener.py,sha256=
|
|
177
|
+
aiq/observability/async_otel_listener.py,sha256=2Ye9bkHfAssuxFS_ECyRyl-bTa73yYvsPyO4BaK5Beg,19662
|
|
178
178
|
aiq/observability/register.py,sha256=WLPGY1b_RmVv48od-hIytvJrCqNoJupriHCzyxvTbUw,6723
|
|
179
179
|
aiq/plugins/.namespace,sha256=Gace0pOC3ETEJf-TBVuNw0TQV6J_KtOPpEiSzMH-odo,215
|
|
180
180
|
aiq/profiler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -186,7 +186,7 @@ aiq/profiler/utils.py,sha256=hNh_JfxXDrACIp4usXtlriTfVuYUkk3Pv-x74K34MQg,8180
|
|
|
186
186
|
aiq/profiler/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
187
187
|
aiq/profiler/callbacks/agno_callback_handler.py,sha256=aDAUY6GDIUtly6KowXXKUqLc7NbE6khg1aXT1AritaA,14930
|
|
188
188
|
aiq/profiler/callbacks/base_callback_class.py,sha256=BFZMkb-dPoHAnM_4jVXX08hD8Vi2n8thyftVlUxfE24,745
|
|
189
|
-
aiq/profiler/callbacks/langchain_callback_handler.py,sha256=
|
|
189
|
+
aiq/profiler/callbacks/langchain_callback_handler.py,sha256=tG9OX2C3Rsqpew2Jaj2LLkZkwEztbeQ-oLVIBUDPL48,12511
|
|
190
190
|
aiq/profiler/callbacks/llama_index_callback_handler.py,sha256=AXUtfsUwif-rUFoVaRnMeSe29TcpT9Z8nxWcJWD2PiQ,9334
|
|
191
191
|
aiq/profiler/callbacks/semantic_kernel_callback_handler.py,sha256=uYlq0Lku6U1AMg5GoPpJoZm6lvgIjLQN5_uIbswL4bA,11157
|
|
192
192
|
aiq/profiler/callbacks/token_usage_base_model.py,sha256=X0b_AbBgVQAAbgbDMim-3S3XdQ7PaPs9qMUACvMAe5o,1104
|
|
@@ -308,10 +308,10 @@ aiq/utils/reactive/base/observer_base.py,sha256=UAlyAY_ky4q2t0P81RVFo2Bs_R7z5Nde
|
|
|
308
308
|
aiq/utils/reactive/base/subject_base.py,sha256=Ed-AC6P7cT3qkW1EXjzbd5M9WpVoeN_9KCe3OM3FLU4,2521
|
|
309
309
|
aiq/utils/settings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
310
310
|
aiq/utils/settings/global_settings.py,sha256=U9TCLdoZsKq5qOVGjREipGVv9e-FlStzqy5zv82_VYk,7454
|
|
311
|
-
aiqtoolkit-1.2.
|
|
312
|
-
aiqtoolkit-1.2.
|
|
313
|
-
aiqtoolkit-1.2.
|
|
314
|
-
aiqtoolkit-1.2.
|
|
315
|
-
aiqtoolkit-1.2.
|
|
316
|
-
aiqtoolkit-1.2.
|
|
317
|
-
aiqtoolkit-1.2.
|
|
311
|
+
aiqtoolkit-1.2.0a20250610.dist-info/licenses/LICENSE-3rd-party.txt,sha256=8o7aySJa9CBvFshPcsRdJbczzdNyDGJ8b0J67WRUQ2k,183936
|
|
312
|
+
aiqtoolkit-1.2.0a20250610.dist-info/licenses/LICENSE.md,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
|
313
|
+
aiqtoolkit-1.2.0a20250610.dist-info/METADATA,sha256=IU2IX0jWhO68QeQ8nZMzpCNnlGHCShFaijLFkWxKajo,20250
|
|
314
|
+
aiqtoolkit-1.2.0a20250610.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
315
|
+
aiqtoolkit-1.2.0a20250610.dist-info/entry_points.txt,sha256=gRlPfR5g21t328WNEQ4CcEz80S1sJNS8A7rMDYnzl4A,452
|
|
316
|
+
aiqtoolkit-1.2.0a20250610.dist-info/top_level.txt,sha256=fo7AzYcNhZ_tRWrhGumtxwnxMew4xrT1iwouDy_f0Kc,4
|
|
317
|
+
aiqtoolkit-1.2.0a20250610.dist-info/RECORD,,
|
|
File without changes
|
{aiqtoolkit-1.2.0a20250609.dist-info → aiqtoolkit-1.2.0a20250610.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{aiqtoolkit-1.2.0a20250609.dist-info → aiqtoolkit-1.2.0a20250610.dist-info}/licenses/LICENSE.md
RENAMED
|
File without changes
|
|
File without changes
|