Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 68 additions & 5 deletions docs/gen-ai/non-normative/examples-llm-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,19 @@ Span:
> The format of `gen_ai.output.messages` is not yet specified for built-in tool calls (check [#2585](https://github.com/open-telemetry/semantic-conventions/issues/2585)
> for the details).

This is an example of telemetry generated for a chat completion call with `code_interpreter` tool that results in
This is an example of telemetry generated for a responses call with `code_interpreter` tool that results in
a model provider executing a tool and returning response along with tool call details.

```py
response = client.responses.create(
model="gpt-4",
input="Write Python code that generates a random number, executes it, and returns the result.",
tools=[{"type": "code_interpreter"}],
include=['code_interpreter_call.outputs'],
tool_choice="required",
)
```

```mermaid
%%{init:
{
Expand All @@ -688,11 +698,11 @@ sequenceDiagram
participant I as Instrumented Client
participant M as Model

A ->>+ I:
A ->>+ I: #U+200D
I ->> M: input = [system: You are a helpful bot, user: Write Python code that generates a random number, executes it, and returns the result.]
Note left of I: GenAI Client span
I --> M: tool:code='import random ....'<br>assistant: The generated random number is 95.
I -->>- A:
I -->>- A: #U+200D
```

**GenAI client span:**
Expand All @@ -715,11 +725,64 @@ sequenceDiagram

<span id="gen-ai-input-messages-built-in-tools">`gen_ai.input.messages` value</span>

TODO
```json
[
{
"role": "system",
"parts": [
{
"type": "text",
"content": "You are a helpful bot"
}
]
},
{
"role": "user",
"parts": [
{
"type": "text",
"content": "Write Python code that generates a random number, executes it, and returns the result."
}
]
}
]
```

<span id="gen-ai-output-messages-built-in-tools">`gen_ai.output.messages` value</span>

TODO
```json
[
{
"role": "assistant",
"parts": [
{
"type": "tool_call",
"id": "call_VSPygqKTWdrhaFErNvMV18Yl",
"name": "code_interpreter",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to document the schema, not just the example, so that we know how to record different types of tools.

In this proposal shape tool call part would have to accommodate file search, code_interpreter and everything else without clear idea on what the format of each of them and which property is used as a discriminator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmolkova Are you suggesting having a discriminator that can distinguish which tool is called and based on the tool call schema can be inferred. For example, in below example , tool is code_interpreter and "code_interpreter" property is present only when tool_type is code_interpreter.

# Code Interpreter tool call part
{
    "type": "tool_call"
    "id": "id",
    "name": "code_interpreter",
    "tool_type": "code_interpreter", # discriminator
    "code_interpreter": {
        "arguments": {
          "code": "import random\n\n# Generate a random number\nrandom_number = random.randint(1, 100)\n\n# Execute some operation with the random number (e.g., squaring it)\nresult = random_number ** 2\n\nrandom_number, result",
          "container_id": "cntr_690bdbfed8688190884efd4c7ae6435b0db1f006442e8941",
        }
     }
}

For Function Tool Call

{
    "role": "assistant",
    "parts": [
      {
        "type": "tool_call",
        "id": "call_VSPygqKTWdrhaFErNvMV18Yl",
        "tool_type": "function",
       "function": {
             "name": "get_weather",
             "arguments": {
                  "location": "Paris"
             }
        },
       
      }
    ],
    "finish_reason": "tool_call"
  }

"arguments": {
"code": "import random\n\n# Generate a random number\nrandom_number = random.randint(1, 100)\n\n# Execute some operation with the random number (e.g., squaring it)\nresult = random_number ** 2\n\nrandom_number, result",
"container_id": "cntr_690bdbfed8688190884efd4c7ae6435b0db1f006442e8941",
}
},
{
"type": "tool_call_response",
"id": " call_VSPygqKTWdrhaFErNvMV18Yl",
"response": [
{
"logs": "(10, 20)",
"type": "logs"
}
],
},
{
"type": "text",
"content": "The generated random number is **89**, and the result of squaring it is **7921**"
}
],
"finish_reason": "stop"
}
]
```

## Chat completion with multiple choices

Expand Down
Loading