Streamed tool-call deltas are typed as complete tool calls (ToolChoice), so documented deltas don't type-check

未关闭 适合新手
#264 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@Kinfe123 已经在做这个了。

开始于 2026年12月1日。

  • #265 来自 @Kinfe123 —— 未关闭

评估

难度
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].id is typed string but is undefined for 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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

togethercomputer/together-typescript 的其他 Issue

查看 togethercomputer/together-typescript 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。