-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
fix: preserve prompt_cache_key in Responses API, escape \n in tagContent (#517, #515) #518
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -472,7 +472,7 @@ export async function handleComboChat({ | |
| // SDKs close the connection on finish_reason, so anything sent after | ||
| // that marker is silently dropped. | ||
| if (!res.body) return res; | ||
| const tagContent = `\n<omniModel>${modelStr}</omniModel>\n`; | ||
| const tagContent = `\\n<omniModel>${modelStr}</omniModel>\\n`; | ||
|
||
| const encoder = new TextEncoder(); | ||
| const decoder = new TextDecoder(); | ||
| let tagInjected = false; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change fixes the JSON injection for streaming responses by escaping the newline characters. However, this breaks another usage of
tagContentin theflushpart of theTransformStream(line 514), where it's used in aJSON.stringifycall.With this change,
tagContentis a string containing a literal backslash and 'n' (e.g.,"\\n..."). WhenJSON.stringify({ content: tagContent })is called, the backslash is also escaped, resulting in"\\\\n..."in the JSON output. The client will then parse this as a literal\nstring, not a newline character.To address this,
tagContentshould contain raw newlines when passed toJSON.stringify. A comprehensive fix would involve defining the raw content and escaping it only for the regex injection. Since that requires changing code outside this diff, a more localized fix would be to un-escapetagContentat line 514 before it's stringified. For example:delta: { content: tagContent.replace(/\\n/g, '\n') }.Please adjust the implementation to ensure both use cases are handled correctly.