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

Tiktoken package for openai script not working #1306

Closed
azmathr opened this issue Feb 15, 2024 · 3 comments
Closed

Tiktoken package for openai script not working #1306

azmathr opened this issue Feb 15, 2024 · 3 comments

Comments

@azmathr
Copy link

azmathr commented Feb 15, 2024

In my pthon script I have tiktoken enabled which essencially converts characters to openai tokens. Its a common module used in openai. Here is an associated code.

encoding = tiktoken.get_encoding("cl100k_base")

`def num_tokens_from_string(string: str, encoding_name: str) -> int:
"""Returns the number of tokens in a text string."""
encoding = tiktoken.get_encoding(encoding_name)
num_tokens = len(encoding.encode(string))
return num_tokens

def get_text_until_limit(elements, limit):
text = ''
for element in elements:
new_text = text + ' ' + element.get_text()
if num_tokens_from_string(new_text, "cl100k_base") <= limit:
text = new_text
else:
break
return text
`
Unfortunately this is not working through zappa. I am getting error

 encoding = tiktoken.get_encoding("cl100k_base")   File "/var/task/tiktoken/registry.py", line 64, in get_encoding     _find_constructors()   File "/var/task/tiktoken/registry.py", line 44, in _find_constructors     raise ValueError( [1707923842317] [DEBUG] 2024-02-1

warmhandler error

@souravjamwal77
Copy link
Collaborator

@azmathr Can you please post the full error trace?

@azmathr
Copy link
Author

azmathr commented Feb 23, 2024 via email

@monkut
Copy link
Collaborator

monkut commented Mar 13, 2024

closing this issue as it was resolved by the op.

@monkut monkut closed this as completed Mar 13, 2024
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

3 participants