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

patch(js): utf-8 encode multipart parts #1487

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

angus-langchain
Copy link
Contributor

No description provided.

js/src/client.ts Outdated
@@ -1144,10 +1145,11 @@ export class Client implements LangSmithTracingClientInterface {
const fields = { inputs, outputs, events };
// encode the main run payload
const stringifiedPayload = stringifyForTracing(payload);
const valueBytes = encoder.encode(stringifiedPayload).length;
Copy link
Collaborator

@jacoblee93 jacoblee93 Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Shouldn't/can't stringifyForTracing already return a properly encoded string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is necessary. The stringify function itself doesn't actually encode anything. It converts the js object into a JSON string.
JSON.stringify() produces a JavaScript string, which is always UTF-16.

Copy link
Collaborator

@jacoblee93 jacoblee93 Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but could/should our stringifyForTracing wrapper serialize it as a utf-8 string?

Then we could pass it directly into the Blob constructor?

I think that may save us some bugs in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don’t need to parse a length=... parameter (just application/json), then JSON.stringify(...) should be sufficient. The browser will treat it as a UTF-8 text blob, and the server sees it as JSON with no mismatch in length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I can add an explicit encoding

Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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 this pull request may close these issues.

3 participants