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

Translate max_tokens_to_sample for OpenAI #583

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

scottcmoore
Copy link

@scottcmoore scottcmoore commented Apr 19, 2024

While attempting to use the semantic chunker with OpenAI, I ran into this issue:

[2] pry(main)> url = "https://www.scottcmoore.com"
data = Langchain::Loader.load(url).value
llm = LlmFactory.create!("OpenAI")
Langchain::Chunker::Semantic.new(
  data,
  llm: llm
DEPRECATED: `Langchain::LLM::OpenAI#complete` is deprecated, and will be removed in the next major version. Use `Langchain::LLM::OpenAI#chat` instead.
ArgumentError: unknown keyword: :max_tokens_to_sample

OpenAI expects this parameter as 'max_tokens', while other providers appear to expect 'max_tokens_to_sample'. This PR updates the OpenAI chat method to accept either version of the parameter.
Let me know what you think of this approach, thanks!

OpenAI expects this parameter as 'max_tokens', while other providers
expect 'max_tokens_to_sample'. Update the chat method to accept either
version of the parameter.
Copy link
Contributor

@codenamev codenamev left a comment

Choose a reason for hiding this comment

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

This looks good, although should start thinking about unifying the LLM api for this reason.

@andreibondarev
Copy link
Collaborator

andreibondarev commented Apr 19, 2024

@scottcmoore Which LLM are you using if you don't mind me asking? If instead of this we dropped the max_tokens_to_sample: 50000 from this line, would it still work for you?

The way I'm thinking about this is that OpenAI sets the "gold-standard" in terms of API interfaces and we adapt all other LLM provider interfaces to match it.

In practice this looks like the following... Every Langchain::LLM::Base subclass implements the following interface:

def chat(
  messages: [],
  model: defaults[:chat_completion_model_name],
  max_tokens: nil
  ...
)

But the underlying calls, depending on the LLM class, may need to remap to their respective maxTokens or max_tokens_to_sample, etc.

I won't claim that this is implemented everywhere with 100% accuracy but this is where I'd like it to converge towards.

@scottcmoore
Copy link
Author

@andreibondarev I was using gpt-3.5-turbo when testing this.
If the max_tokens_to_sample: 50000 were dropped I think it would work fine for our use case.

Just to make sure, am I understanding correctly that you'd like to keep the OpenAI provider interface as it is, and update the others to accept max tokens as a param to their chat methods, and do any necessary translation of parameter names in those providers?

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.

None yet

3 participants