huggingface.js icon indicating copy to clipboard operation
huggingface.js copied to clipboard

[Type Conflict] The ChatCompletionOutputToolCall and the ChatCompletionStreamOutputDeltaToolCall incapable

Open whats2000 opened this issue 6 months ago • 0 comments

Here I found an issue when creating an inference tool from the JS API.

Version

"@huggingface/inference": "^2.8.0" with npm installation

Description

  1. 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;
}
  1. The ChatCompletionStreamOutputDelta.tool_calls type is ChatCompletionStreamOutputDeltaToolCall but might be a mistake as that should be the ChatCompletionStreamOutputDeltaToolCall[] (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

image image image

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

whats2000 avatar Jul 31 '24 13:07 whats2000