Streamed tool-call deltas are typed as complete tool calls (ToolChoice), so documented deltas don't type-check
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
从 OpenAPI schema https://docs.together.ai/openapi.yaml 开始,沿着 ChatCompletionChunk 查到 delta.tool_calls 及其对 ToolChoice 的引用;然后检查此仓库如何根据规范生成 TypeScript 类型。更新流式 delta 类型,使文档中描述的部分 delta 通过类型检查,并将后续 delta 中缺失的字段设为可选。完成标准是:复现代码能通过指定的 TypeScript 命令编译,且非流式的 ToolChoice 保持不变。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 73
- 派生
- 12
- 平均合并
- 10 天 21 小时
- 30 天内合并 PR
- 2
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
togethercomputer/together-typescript 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 35/100
togethercomputer/together-typescript#173 · 1 条评论 ·
查看 togethercomputer/together-typescript 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
laststance/design-world#98 ·
维护者通常 1 天内回复
-
approved check:passed streams:add
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
triage: failed
难度 2/5 1-3 小时 新手友好度 68/100
oxc-project/tsrs#1277 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
ardia-browser/ardia#6798 ·
维护者通常 1 天内回复