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

Fix encoding_for_model to return nil for unknown encoding #29

Merged
merged 2 commits into from
Apr 4, 2024

Conversation

rob-mindtrip
Copy link
Contributor

This pull request addresses issue #28.

Currently, when you pass an unrecognized model name to Tiktoken.encoding_for_model, instead of returning nil it returns an unexpected Hash, making it more difficult to detect whether the encoding is available. This seems to have been introduced by 0c1a45b

Added a simple spec to confirm.

Copy link
Owner

@IAPark IAPark left a comment

Choose a reason for hiding this comment

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

Could you fix the linter issues. Otherwise seems reasonable to me

end
encoding && get_encoding(encoding)
Copy link
Owner

Choose a reason for hiding this comment

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

I'd prefer

if encoding
  get_encoding(encoding) 
else
  nil
end

but only weakly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking care of that. I didn't mean to leave this hanging, but it's a pretty simple change.

@IAPark IAPark self-requested a review April 4, 2024 18:15
Copy link
Owner

@IAPark IAPark left a comment

Choose a reason for hiding this comment

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

Not sure if I should actually get another reviewer on this, but this seems fine now

@IAPark IAPark merged commit c4ba093 into IAPark:main Apr 4, 2024
6 checks passed
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.

2 participants