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

Add OpenAI latest models to TokenValidator #595

Merged

Conversation

kokuyouwind
Copy link
Contributor

@kokuyouwind kokuyouwind commented Apr 26, 2024

Description

fix #594

Based on OpenAI's most recent list of models, the missing models were added and updates to existing models were reflected.
I checked the specs for OpenAIValidator and I don't think it needs to be updated.

I ran the code in the original Issue and confirmed that the error no longer occurs.

> llm = Langchain::LLM::OpenAI.new(
   api_key: ENV.fetch('OPENAI_API_KEY', nil),
      default_options: {
        chat_completion_model_name: 'gpt-4-turbo'
    })
> llm.chat(messages: [{ role: 'user', content: 'hello'}])
=>
#<Langchain::LLM::OpenAIResponse:0x000000012b239340
 @model=nil,
 @raw_response=
  {"id"=>"chatcmpl-9IBSpkOQdaXUcax5Y58IVYEHKNvQd",
   "object"=>"chat.completion",
   "created"=>1714120999,
   "model"=>"gpt-4-turbo-2024-04-09",
   "choices"=>
    [{"index"=>0, "message"=>{"role"=>"assistant", "content"=>"Hello! How can I assist you today?"}, "logprobs"=>nil, "finish_reason"=>"stop"}],
   "usage"=>{"prompt_tokens"=>8, "completion_tokens"=>9, "total_tokens"=>17},
   "system_fingerprint"=>"fp_ea6eb70039"}>

"gpt-3.5-turbo" => 4096,
"gpt-3.5-turbo" => 16385,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

📝
gpt-3.5-turbo is now aliased to gpt-3.5-turbo-0125, so I aligned it there.

@kokuyouwind kokuyouwind changed the title OpenAI's latest model is reflected in TokenValidator Add OpenAI's latest models to TokenValidator Apr 26, 2024
@kokuyouwind kokuyouwind changed the title Add OpenAI's latest models to TokenValidator Add OpenAI latest models to TokenValidator Apr 26, 2024
@andreibondarev
Copy link
Collaborator

@kokuyouwind Do you find there's value in this token length validation? I've been thinking of disabling it by default.

@andreibondarev andreibondarev merged commit 696fb30 into patterns-ai-core:main Apr 26, 2024
5 checks passed
@kokuyouwind kokuyouwind deleted the fix-openai-gpt-4-turbo branch April 26, 2024 15:32
@kokuyouwind
Copy link
Contributor Author

@andreibondarev

@kokuyouwind Do you find there's value in this token length validation? I've been thinking of disabling it by default.

I have created this PR with respect to the existing implementation, but I too think this validation is unnecessary.
If there is a problem with the number of tokens, the OpenAI API will return an error, and I don't think there is a particular need to save the number of API runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants