Skip to content

Commit 9ff9056

Browse files
author
Andrei Bratu
committed
import
1 parent 6b7edb3 commit 9ff9056

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

src/humanloop/decorators/tool.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212

1313
from humanloop.eval_utils import File
1414
from humanloop.otel import TRACE_FLOW_CONTEXT, FlowContext
15-
from humanloop.otel.constants import HUMANLOOP_FILE_KEY, HUMANLOOP_FILE_TYPE_KEY, HUMANLOOP_LOG_KEY, HUMANLOOP_PATH_KEY
15+
from humanloop.otel.constants import (
16+
HUMANLOOP_FILE_KEY,
17+
HUMANLOOP_FILE_TYPE_KEY,
18+
HUMANLOOP_LOG_KEY,
19+
HUMANLOOP_PATH_KEY,
20+
)
1621
from humanloop.otel.helpers import generate_span_id, write_to_opentelemetry_span
1722
from humanloop.requests.tool_function import ToolFunctionParams
1823
from humanloop.requests.tool_kernel_request import ToolKernelRequestParams
1924

20-
from humanloop.otel.helpers import args_to_inputs
25+
from humanloop.decorators.helpers import args_to_inputs
2126

2227
logger = logging.getLogger("humanloop.sdk")
2328

@@ -163,7 +168,9 @@ def _build_function_parameters_property(func) -> _JSONSchemaFunctionParameters:
163168
inspect.Parameter.VAR_POSITIONAL,
164169
inspect.Parameter.VAR_KEYWORD,
165170
):
166-
raise ValueError(f"{func.__name__}: *args and **kwargs are not supported by the @tool decorator")
171+
raise ValueError(
172+
f"{func.__name__}: *args and **kwargs are not supported by the @tool decorator"
173+
)
167174

168175
for parameter in signature.parameters.values():
169176
try:
@@ -267,7 +274,16 @@ def _parse_annotation(annotation: typing.Type) -> _ParsedAnnotation:
267274
if origin is None:
268275
# Either not a nested type or no type hint
269276
# Parameter.empty is used for parameters without type hints
270-
if annotation not in (str, int, float, bool, Parameter.empty, dict, list, tuple):
277+
if annotation not in (
278+
str,
279+
int,
280+
float,
281+
bool,
282+
Parameter.empty,
283+
dict,
284+
list,
285+
tuple,
286+
):
271287
raise ValueError(f"Unsupported type hint: {annotation}")
272288

273289
# Check if it's a complex type with no inner type
@@ -321,7 +337,9 @@ def _parse_annotation(annotation: typing.Type) -> _ParsedAnnotation:
321337
# Union has sub_types and is Optional
322338
return _ParsedOptionalAnnotation(
323339
annotation=_ParsedUnionAnnotation(
324-
annotation=[_parse_annotation(sub_type) for sub_type in sub_types[:-1]],
340+
annotation=[
341+
_parse_annotation(sub_type) for sub_type in sub_types[:-1]
342+
],
325343
)
326344
)
327345
# Union type that is not Optional
@@ -355,7 +373,10 @@ def _annotation_parse_to_json_schema(
355373

356374
if isinstance(arg, _ParsedUnionAnnotation):
357375
arg_type = {
358-
"anyOf": [_annotation_parse_to_json_schema(sub_type) for sub_type in arg.annotation],
376+
"anyOf": [
377+
_annotation_parse_to_json_schema(sub_type)
378+
for sub_type in arg.annotation
379+
],
359380
}
360381

361382
elif isinstance(arg, _ParsedTupleAnnotation):
@@ -370,7 +391,10 @@ def _annotation_parse_to_json_schema(
370391
else:
371392
arg_type = {
372393
"type": "array",
373-
"items": [_annotation_parse_to_json_schema(sub_type) for sub_type in arg.annotation],
394+
"items": [
395+
_annotation_parse_to_json_schema(sub_type)
396+
for sub_type in arg.annotation
397+
],
374398
}
375399

376400
elif isinstance(arg, _ParsedListAnnotation):
@@ -439,7 +463,10 @@ def _annotation_parse_to_json_schema(
439463
if is_optional:
440464
if isinstance(arg, _ParsedUnionAnnotation):
441465
for type_option in arg_type["anyOf"]:
442-
if isinstance(type_option["type"], list) and "null" not in type_option["type"]: # type: ignore
466+
if (
467+
isinstance(type_option["type"], list)
468+
and "null" not in type_option["type"]
469+
): # type: ignore
443470
type_option["type"] = [*type_option["type"], "null"] # type: ignore
444471
elif not isinstance(type_option["type"], list): # type: ignore
445472
type_option["type"] = [type_option["type"], "null"] # type: ignore

0 commit comments

Comments
 (0)