Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: HFInference.chatCompletionStream throws [object Object] for errors instead of readable messages #1079

Open
chelsey-datasaur opened this issue Dec 18, 2024 · 0 comments · May be fixed by #1080

Comments

@chelsey-datasaur
Copy link

Hi there, found a bug on HFInference.chatCompletionStream implementation specified below:

Environment

Library: @huggingface/inference
version: "^2.8.0"
Function: chatCompletionStream in streamingRequest

Problem

In the HFInference.chatCompletionStream implementation, the streamingRequest function throws errors incorrectly when the data.error field is an object. Specifically, the following code causes the error message to display [object Object] instead of the actual error content:

for (const event of events) {
  if (event.data.length > 0) {
    if (event.data === "[DONE]") {
      return;
    }
    const data = JSON.parse(event.data);
    if (typeof data === "object" && data !== null && "error" in data) {
      throw new Error(data.error); // This causes [object Object] to be thrown
    }
    yield data as T;
  }
}

The error should contain the message field or be stringified to provide readable error information, such as:

Error: Input validation error: inputs tokens + max_new_tokens must be <= 4096. Given: 48 inputs tokens and 4096 max_new_tokens

Suggested Fix

change
throw new Error(data.error);
to explicitly stringify the error message:
throw new Error(data.error.message || JSON.stringify(data.error));

Thanks!

@coyotte508 coyotte508 linked a pull request Dec 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant