Streamed tool-call deltas are typed as complete tool calls (ToolChoice), so documented deltas don't type-check
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Bắt đầu với lược đồ OpenAPI tại https://docs.together.ai/openapi.yaml, lần theo ChatCompletionChunk đến delta.tool_calls và tham chiếu ToolChoice của nó; sau đó kiểm tra cách repository này tạo các kiểu TypeScript từ đặc tả. Cập nhật kiểu delta được truyền theo luồng để các delta từng phần được tài liệu hóa vượt qua kiểm tra kiểu và các trường không có trong những delta tiếp theo là tùy chọn. Hoàn tất khi bản tái hiện biên dịch được bằng lệnh TypeScript đã nêu và ToolChoice không truyền theo luồng vẫn không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 73
- Fork
- 12
- Merge trung bình
- 10 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của togethercomputer/together-typescript
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
togethercomputer/together-typescript#173 · 1 bình luận ·
Tất cả issue của togethercomputer/together-typescript
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
laststance/design-world#98 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: KCM True crimeĐang mởapproved check:passed streams:add
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
triage: failed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
oxc-project/tsrs#1277 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ardia-browser/ardia#6798 ·
Maintainer thường phản hồi trong vòng 1 ngày