Skip to content

Commit

Permalink
fix tool bug
Browse files Browse the repository at this point in the history
  • Loading branch information
axiomofjoy committed Jan 19, 2025
1 parent a4f5881 commit 143c56b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1050,9 +1050,7 @@ async def async_wrapper(
if asyncio.iscoroutinefunction(wrapped_function):
return async_wrapper(wrapped_function) # type: ignore[no-any-return]
return sync_wrapper(wrapped_function) # type: ignore[no-any-return]
if asyncio.iscoroutinefunction(wrapped_function):
return lambda x: async_wrapper(x)
return lambda x: sync_wrapper(x)
return lambda f: async_wrapper(f) if asyncio.iscoroutinefunction(f) else sync_wrapper(f)


class TracerProvider(OTelTracerProvider):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,35 @@ async def decorated_async_tool(input: str) -> None:
assert json.loads(tool_parameters) == {}
assert not attributes

async def test_async_tool_with_overridden_name(
self,
in_memory_span_exporter: InMemorySpanExporter,
tracer: OITracer,
) -> None:
@tracer.tool(name="overridden-name")
async def decorated_async_tool(input: str) -> None:
pass

await decorated_async_tool("input")

spans = in_memory_span_exporter.get_finished_spans()
assert len(spans) == 1
span = spans[0]
assert span.name == "overridden-name"
assert span.status.is_ok
assert not span.events
attributes = dict(span.attributes or {})
assert attributes.pop(OPENINFERENCE_SPAN_KIND) == TOOL
assert attributes.pop(INPUT_MIME_TYPE) == JSON
assert isinstance(input_value := attributes.pop(INPUT_VALUE), str)
assert json.loads(input_value) == {"input": "input"}
assert attributes.pop(OUTPUT_MIME_TYPE) == TEXT
assert attributes.pop(OUTPUT_VALUE) == "None"
assert attributes.pop(TOOL_NAME) == "overridden-name"
assert isinstance(tool_parameters := attributes.pop(TOOL_PARAMETERS), str)
assert json.loads(tool_parameters) == {}
assert not attributes

def test_tool_with_zero_arguments_and_overridden_name_and_description(
self,
in_memory_span_exporter: InMemorySpanExporter,
Expand Down

0 comments on commit 143c56b

Please sign in to comment.