Streamed tool-call deltas are typed as complete tool calls (ToolChoice), so documented deltas don't type-check
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend-api-design
Research direction
Start with the OpenAPI schema at https://docs.together.ai/openapi.yaml, following ChatCompletionChunk to delta.tool_calls and its ToolChoice reference; then check how this repository generates TypeScript types from the spec. Update the streamed delta type so the documented partial deltas type-check and fields absent from later deltas are optional. Done when the reproduction compiles under the stated TypeScript command and non-streamed ToolChoice remains unchanged.
Written by the indexing model from the issue text.
Description
In [email protected], streamed tool-call deltas are typed as ToolChoice, the complete tool call. ChatCompletionChunk.Choice.Delta.tool_calls is Array<ToolChoice>, and ToolChoice requires id, type, index, function.name and function.arguments.
Only the first delta of a call has all of those. Together's own streaming example (https://docs.together.ai/docs/inference/function-calling/single-call, "delta 2") sends later deltas as { index, function: { arguments } }. So:
- the documented delta doesn't type-check, and
delta.tool_calls[0].idis typedstringbut isundefinedfor every delta after the first, so code that relies on it compiles and then breaks at runtime.
Reproduction
npm i [email protected] typescript, then npx tsc --noEmit --strict --module nodenext --moduleResolution nodenext --skipLibCheck repro.ts (TypeScript 7.0.2):
import type { ChatCompletionChunk } from "together-ai/resources/chat/completions";
type ToolCallDelta = NonNullable<ChatCompletionChunk.Choice.Delta["tool_calls"]>[number];
// The two deltas from the "Streaming" example in
// https://docs.together.ai/docs/inference/function-calling/single-call
const delta1: ToolCallDelta = {
index: 0,
id: "call_fwbx4e156wigo9ayq7tszngh",
type: "function",
function: { name: "get_weather", arguments: "" },
};
const delta2: ToolCallDelta = {
index: 0,
function: { arguments: '{"location":"New York City, USA"}' },
};
// Adding a name moves the error to `id` and `type`.
const delta2WithName: ToolCallDelta = {
index: 0,
function: { name: "get_weather", arguments: '{"location":"New York City, USA"}' },
};
// This compiles, but for delta 2 the value is undefined at runtime.
declare const chunk: ChatCompletionChunk;
const id: string = chunk.choices[0]!.delta.tool_calls![0]!.id;
export { delta1, delta2, delta2WithName, id };
Output:
repro.ts(15,3): error TS2741: Property 'name' is missing in type '{ arguments: string; }' but required in type 'Function'.
repro.ts(19,7): error TS2739: Type '{ index: number; function: { name: string; arguments: string; }; }' is missing the following properties from type 'ToolChoice': id, type
Cause
The types come from the OpenAPI spec (https://docs.together.ai/openapi.yaml). ChatCompletionChunk → delta.tool_calls → $ref: '#/components/schemas/ToolChoice', which has required: [id, type, function, index] and function.required: [name, arguments]. The spec even has # TODO: is this the right place for index? on that schema.
Suggested fix
Give stream deltas their own schema, the way the OpenAI SDK does with ChatCompletionChunk.Choice.Delta.ToolCall: index required, and id, type, function.name and function.arguments optional. ToolChoice can stay as is for non-streamed responses.
I checked this repo's issues for "ToolChoice", "tool_calls delta" and "stream tool_calls id" and didn't find an existing report.
- Dominant language
- TypeScript
- Stars
- 73
- Forks
- 12
- Avg merge
- 10d 21h
- Merged PRs (30d)
- 2
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from togethercomputer/together-typescript
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
togethercomputer/together-typescript#173 · 1 comment ·
All issues in togethercomputer/together-typescript
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ranxianglei/billion-context#8319 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JimLiu/open-artifact#126 ·
-
bug repro-ready
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
mksglu/context-mode#1454 ·
-
pending triage
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
laststance/design-world#98 ·
Maintainers usually reply within 1 day