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

Crash on React Native: SyntaxError: Invalid RegExp: Invalid escape #82

Open
julian-hecker opened this issue Dec 1, 2023 · 2 comments
Open

Comments

@julian-hecker
Copy link

julian-hecker commented Dec 1, 2023

I'm working on integrating LangChain and OpenAI in Expo React Native. I've run into quite a number of issues, but it's getting there.

Now, I'm facing the following issue:

When a response from OpenAI has streamed and completed, LangChain uses TikToken to try to count the total number of tokens used.

When the response is getting encoded in TikToken, it tries to create the following RegExp on this line: /('s|'S|'t|'T|'re|'rE|'Re|'RE|'ve|'vE|'Ve|'VE|'m|'M|'ll|'lL|'Ll|'LL|'d|'D)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+/gu. Then plug that into http://regexr.com/, and it'll tell you the \p feature might not be supported in all browsers. Pretty sure this isn't supported in the React Native Hermes runtime.

Let me know what we can do about this, maybe I can help :)

Edit: I have also raised an issue in the langchain-js repo.

@asp3
Copy link

asp3 commented Jan 11, 2024

having the same issue, any workarounds? @julian-hecker

@julian-hecker
Copy link
Author

@asp3 My workaround until the issue was fixed in Langchain was to change the code inside node_modules using patch-package. I believe my solution of wrapping the encode method in a try/catch throws out the token count, however.

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

No branches or pull requests

2 participants