Skip to content

Support UTF-8 characters (e.g. Hebrew) #43

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

Closed
orenagiv opened this issue Nov 19, 2023 · 6 comments · Fixed by #44
Closed

Support UTF-8 characters (e.g. Hebrew) #43

orenagiv opened this issue Nov 19, 2023 · 6 comments · Fixed by #44

Comments

@orenagiv
Copy link

Hey,
While using the LangChain.dart package, which uses the openapi_spec package, I've noticed that if the OpenAI response includes characters in Hebrew or other languages with special characters - it results with "gibberish".

This is most probably due to client.dart > lines 883 and 896, where json.decode is done over r.body:
https://github.com/search?q=repo%3Atazatechnology%2Fopenapi_spec+json.decode%28r.body%29&type=code

It seems that due to this Dart issue:
dart-lang/http#789

The json.decode should be done with utf8.decode over the r.bodyBytes, in order to properly handle the UTF-8 chars:

if (s.ref != null || returnType.startsWith('Union')) {
  decoder = "return $returnType.fromJson(json.decode(utf8.decode(r.bodyBytes)));";
} else {
  decoder = """
    final list = json.decode(utf8.decode(r.bodyBytes)) as List;
    return list.map((e) => ${s.items.ref}.fromJson(e)).toList();

I've manually manipulated the generated client.dart file - and it resolved the problem.
However, unfortunately, due to lack of time I'm unable to test this properly and submit a Pull Request...
I hope the maintainers will have to take a look soon.

@walsha2
Copy link
Contributor

walsha2 commented Nov 19, 2023

Looks like there is some confusion in the http package about the expected/default decode logic. I assumed that utf-8 was the default, but I suppose that is not the case.

@orenagiv this has been taken care of in #44 and successfully published to openapi_spec (v0.7.8). @davidmigloz should be able to integrate in to LangChain Dart soon.

@davidmigloz
Copy link
Contributor

Fixed in:

Thank you both!

@davidmigloz
Copy link
Contributor

@walsha2 we need to recreate the other clients as well (pinecone on your side and chromadb on my side).

@davidmigloz
Copy link
Contributor

chromadb recreated in:

@orenagiv
Copy link
Author

Thanks @davidmigloz @walsha2 !
Works great! 👍

@walsha2
Copy link
Contributor

walsha2 commented Nov 20, 2023

@walsha2 we need to recreate the other clients as well (pinecone on your side and chromadb on my side).

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.

3 participants