Streamed tool-call deltas are typed as complete tool calls (ToolChoice), so documented deltas don't type-check
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- backend-api-design
Direzione di ricerca
Inizia dallo schema OpenAPI all’indirizzo https://docs.together.ai/openapi.yaml, segui ChatCompletionChunk fino a delta.tool_calls e al relativo riferimento a ToolChoice; poi verifica come questo repository genera i tipi TypeScript dalla specifica. Aggiorna il tipo dei delta trasmessi in modo che i delta parziali documentati superino il controllo dei tipi e i campi assenti dai delta successivi siano facoltativi. Il lavoro è completato quando la riproduzione viene compilata con il comando TypeScript indicato e ToolChoice per le risposte non trasmesse rimane invariato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 73
- Fork
- 12
- Merge medio
- 10g 21h
- PR unite (30g)
- 2
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di togethercomputer/together-typescript
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
togethercomputer/together-typescript#173 · 1 commento ·
Tutte le issue di togethercomputer/together-typescript
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
laststance/design-world#98 ·
I maintainer di solito rispondono entro 1 giorno
-
Add: KCM True crimeApertaapproved check:passed streams:add
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
triage: failed
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
oxc-project/tsrs#1277 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ardia-browser/ardia#6798 ·
I maintainer di solito rispondono entro 1 giorno