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

Model can generate enormous amounts of newlines and then the structured output is truncated #1185

Open
1 task done
uriva opened this issue Nov 12, 2024 · 5 comments
Open
1 task done
Labels
openai api Related to underlying OpenAI API

Comments

@uriva
Copy link

uriva commented Nov 12, 2024

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

When using json_schema, sometimes the model outputs thousands of newlines.

At some point it reaches the max output length and stops, causing it to sometimes return a non valid json object (it didn't finish writing it).

Because of how this library is structured, the developer can't see the problem (the output is not logged).

I've found that including

logit_bias: { "1734": -100 }, // Prevent model from generating newlines.

will solve this.

To Reproduce

happens randomly when using json_schema

Code snippets

No response

OS

irrelevant

Node version

irrelevant

Library version

4.71.1

@uriva uriva added the bug Something isn't working label Nov 12, 2024
@uriva
Copy link
Author

uriva commented Nov 12, 2024

I suggest to include this by default, and exposing the content to the user when JSON.parse fails.

@uriva
Copy link
Author

uriva commented Nov 12, 2024

the exception looks like this:

error: Uncaught (in promise) SyntaxError: Expected double-quoted property name in JSON at position 18943 (line 1899 column 9)

    at JSON.parse (<anonymous>)
    at Object.<anonymous> (file:///home/uri/.cache/deno/npm/registry.npmjs.org/openai/4.67.3/helpers/zod.mjs:58:42)
    at parseResponseFormat (file:///home/uri/.cache/deno/npm/registry.npmjs.org/openai/4.71.1/lib/parser.mjs:80:36)
    at file:///home/uri/.cache/deno/npm/registry.npmjs.org/openai/4.71.1/lib/parser.mjs:66:21
    at Array.map (<anonymous>)
    at parseChatCompletion (file:///home/uri/.cache/deno/npm/registry.npmjs.org/openai/4.71.1/lib/parser.mjs:53:40)
    at file:///home/uri/.cache/deno/npm/registry.npmjs.org/openai/4.71.1/resources/beta/chat/completions.mjs:22:42
    at file:///home/uri/.cache/deno/npm/registry.npmjs.org/openai/4.71.1/core.mjs:74:84

@uriva
Copy link
Author

uriva commented Nov 12, 2024

a better fix is adding to the prompt "make the output json as short as possible, no redundant whitespace."

@RobertCraigie
Copy link
Collaborator

Thanks for the report, which model are you using? and do you have a request ID you could share?

@RobertCraigie RobertCraigie added openai api Related to underlying OpenAI API and removed bug Something isn't working labels Nov 12, 2024
@uriva
Copy link
Author

uriva commented Nov 12, 2024

id chatcmpl-ASoSnbTtNnpIcQnEZ09NBz5y7t4f2

system fingerprint fp_159d8341cc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openai api Related to underlying OpenAI API
Projects
None yet
Development

No branches or pull requests

2 participants