Skip to content

Commit d213cf7

Browse files
committed
Streaming chunks are our translated style
Even for Anthropic, we translate their tool calls into our own consistent format, but we were accidentally passing through a possible Anthropic style and documentating _that_.
1 parent 97e3a42 commit d213cf7

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

packages/ai/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ console.log(
8787

8888
The `@gel/ai` package supports tool calls, allowing you to extend the capabilities of the AI model with your own functions. Here's how to use them:
8989

90-
1. **Define your tools**: Create an array of `ToolDefinition` objects that describe your functions, their parameters, and what they do.
91-
2. **Send the request**: Call `queryRag` or `streamRag` with the user's prompt and the `tools` array. You can also use the `tool_choice` parameter to control how the model uses your tools.
92-
3. **Handle the tool call**: If the model decides to use a tool, it will return an `AssistantMessage` with a `tool_calls` array. Your code needs to:
93-
a. Parse the `tool_calls` array to identify the tool and its arguments.
94-
b. Execute the tool and get the result.
95-
c. Create a `ToolMessage` with the result.
96-
d. Send the `ToolMessage` back to the model in a new request.
97-
4. **Receive the final response**: The model will use the tool's output to generate a final response.
90+
1. **Define your tools**: Create an array of `ToolDefinition` objects that describe your functions, their parameters, and what they do.
91+
2. **Send the request**: Call `queryRag` or `streamRag` with the user's prompt and the `tools` array. You can also use the `tool_choice` parameter to control how the model uses your tools.
92+
3. **Handle the tool call**: If the model decides to use a tool, it will return an `AssistantMessage` with a `tool_calls` array. Your code needs to:
93+
a. Parse the `tool_calls` array to identify the tool and its arguments.
94+
b. Execute the tool and get the result.
95+
c. Create a `ToolMessage` with the result.
96+
d. Send the `ToolMessage` back to the model in a new request.
97+
4. **Receive the final response**: The model will use the tool's output to generate a final response.
9898

9999
### Example
100100

@@ -200,14 +200,14 @@ async function handleStreamingResponse(initialMessages: Message[]) {
200200
currentToolCall = {
201201
id: chunk.content_block.id!,
202202
name: chunk.content_block.name,
203-
arguments: "",
203+
arguments: chunk.content_block.args,
204204
};
205205
} else if (
206206
chunk.type === "content_block_delta" &&
207-
chunk.delta.type === "input_json_delta"
207+
chunk.delta.type === "tool_call_delta"
208208
) {
209209
if (currentToolCall) {
210-
currentToolCall.arguments += chunk.delta.partial_json;
210+
currentToolCall.arguments += chunk.delta.args;
211211
}
212212
} else if (chunk.type === "content_block_stop") {
213213
if (currentToolCall) {

packages/ai/src/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ export interface ContentBlockDelta {
124124
type: "text_delta";
125125
text: string;
126126
}
127-
| {
128-
type: "input_json_delta";
129-
partial_json: string;
130-
}
131127
| {
132128
type: "tool_call_delta";
133129
args: string;

0 commit comments

Comments
 (0)