huggingface.js
huggingface.js copied to clipboard
[Type Conflict] The ChatCompletionOutputToolCall and the ChatCompletionStreamOutputDeltaToolCall incapable
Here I found an issue when creating an inference tool from the JS API.
Version
"@huggingface/inference": "^2.8.0" with npm installation
Description
- The issue is that the delta of the tool call (
ChatCompletionStreamOutputDeltaToolCall
) is a type of "number", but the full result (ChatCompletionStreamOutputDeltaToolCall
) is identified by "string"
// At @huggingface\tasks\src\tasks\chat-completion
export interface ChatCompletionOutputToolCall {
function: ChatCompletionOutputFunctionDefinition;
id: number;
type: string;
[property: string]: unknown;
}
// At @huggingface\tasks\src\tasks\chat-completion
export interface ChatCompletionStreamOutputDeltaToolCall {
function: ChatCompletionStreamOutputFunction;
id: string;
index: number;
type: string;
[property: string]: unknown;
}
- The
ChatCompletionStreamOutputDelta.tool_calls
type isChatCompletionStreamOutputDeltaToolCall
but might be a mistake as that should be theChatCompletionStreamOutputDeltaToolCall[]
(Array of calls instead of a single object, this one needs some help of explanation.
- Is the current API endpoint with stream only support a single tool result?
- But the full one is an Array
ChatCompletionOutputMessage.tool_calls: ChatCompletionOutputToolCall[]
// At @huggingface\tasks\src\tasks\chat-completion
export interface ChatCompletionStreamOutputDelta {
content?: string;
role: string;
tool_calls?: ChatCompletionStreamOutputDeltaToolCall;
[property: string]: unknown;
}
// At @huggingface\tasks\src\tasks\chat-completion
export interface ChatCompletionOutputMessage {
content?: string;
name?: string;
role: string;
tool_calls?: ChatCompletionOutputToolCall[];
[property: string]: unknown;
}
ScreenShot
Reference Link
If you want to check it out, here is the link can compare to almost the same code for OpenAI and HuggingFace. And the HuggingFace one have the above issue (OpenAI one is correctly work, hope can help to debug) OpenAI Tool Use Inference HuggingFace Tool Use Inference