|
25 | 25 | set_trace_processors, |
26 | 26 | trace, |
27 | 27 | ) |
| 28 | +from openai.types.responses import FunctionTool # noqa: E402 |
28 | 29 |
|
29 | 30 | from opentelemetry.instrumentation.openai_agents import ( # noqa: E402 |
30 | 31 | OpenAIAgentsInstrumentor, |
|
62 | 63 | GEN_AI_OUTPUT_MESSAGES = getattr( |
63 | 64 | GenAI, "GEN_AI_OUTPUT_MESSAGES", "gen_ai.output.messages" |
64 | 65 | ) |
| 66 | +GEN_AI_TOOL_DEFINITIONS = getattr( |
| 67 | + GenAI, "GEN_AI_TOOL_DEFINITIONS", "gen_ai.tool.definitions" |
| 68 | +) |
65 | 69 |
|
66 | 70 |
|
67 | 71 | def _instrument_with_provider(**instrument_kwargs): |
@@ -484,26 +488,24 @@ def __init__(self, input_tokens: int, output_tokens: int) -> None: |
484 | 488 | self.input_tokens = input_tokens |
485 | 489 | self.output_tokens = output_tokens |
486 | 490 |
|
487 | | - class _FunctionTool: |
488 | | - def __init__(self) -> None: |
489 | | - self.name = "get_current_weather" |
490 | | - self.type = "function" |
491 | | - self.description = "Get the current weather in a given location" |
492 | | - self.parameters = { |
493 | | - "type": "object", |
494 | | - "properties": { |
495 | | - "location": {"title": "Location", "type": "string"}, |
496 | | - }, |
497 | | - "required": ["location"], |
498 | | - } |
499 | | - |
500 | 491 | class _Response: |
501 | 492 | def __init__(self) -> None: |
502 | 493 | self.id = "resp-123" |
503 | 494 | self.instructions = "You are a helpful assistant." |
504 | 495 | self.model = "gpt-4o-mini" |
505 | 496 | self.usage = _Usage(42, 9) |
506 | | - self.tools = [_FunctionTool()] |
| 497 | + self.tools = [FunctionTool( |
| 498 | + name="get_current_weather", |
| 499 | + type="function", |
| 500 | + description="Get the current weather in a given location", |
| 501 | + parameters={ |
| 502 | + "type": "object", |
| 503 | + "properties": { |
| 504 | + "location": {"title": "Location", "type": "string"}, |
| 505 | + }, |
| 506 | + "required": ["location"], |
| 507 | + }, |
| 508 | + )] |
507 | 509 | self.output = [{"finish_reason": "stop"}] |
508 | 510 |
|
509 | 511 | try: |
@@ -539,7 +541,7 @@ def __init__(self) -> None: |
539 | 541 | {"type": "text", "content": "You are a helpful assistant."} |
540 | 542 | ] |
541 | 543 | tool_definitions = json.loads( |
542 | | - response.attributes[GenAI.GEN_AI_TOOL_DEFINITIONS] |
| 544 | + response.attributes[GEN_AI_TOOL_DEFINITIONS] |
543 | 545 | ) |
544 | 546 | assert tool_definitions == [ |
545 | 547 | { |
|
0 commit comments