-
-
Notifications
You must be signed in to change notification settings - Fork 147
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 support for Groq LLM #565
Comments
I'll give it a try. This might already work using Langchain::LLM::OpenAI since the Groq technical FAQ says:
Something like this, although this doesn't seem to work yet: 3.2.2 :019 > llm = Langchain::LLM::OpenAI.new(api_key: 'gsk_xxxx', llm_options: { uri_base: 'https:/
/api.groq.com/openai/', model: 'mixtral-8x7b-32768'})
=>
#<Langchain::LLM::OpenAI:0x0000000107b0ee08
...
3.2.2 :020 > llm.chat(messages: [{role: "user", content: "What is the meaning of life?"}]).completion
OpenAI HTTP Error (spotted in ruby-openai 6.4.0): {"error"=>{"message"=>"The model `gpt-3.5-turbo` does not exist or you do not have access to it.", "type"=>"invalid_request_error", "code"=>"model_not_found"}}
/Users/mattlindsey/.rvm/gems/ruby-3.2.2/gems/faraday-2.9.0/lib/faraday/response/raise_error.rb:22:in `on_complete': the server responded with status 404 (Faraday::ResourceNotFound) Possibly the ruby-openai gem needs to support it somewhere around here: https://github.com/alexrudall/ruby-openai/blob/f8a4482f7012e27f791c9259bde6fb1cda191e82/lib/openai/http.rb#L87 |
@mattlindsey There's no way they're hosting OpenAI models, because other than GPT-2 none of them are open source. Only open-source ones: https://console.groq.com/docs/models. |
@andreibondarev
Output:
So it should work by fixing something. The initializer doesn't seem to be respecting the |
@mattlindsey I don't think it's a good idea. It would be kind of odd to instantiate an |
@andreibondarev That seem to be what they tell you to do in their FAQ, and it works (with a fix, it seems). But maybe you'd prefer a Groq LLM class. |
I discovered using parameters as follows works currently, in case anyone needs it now: llm = Langchain::LLM::OpenAI.new(api_key: 'your_groq_key_here', llm_options: { uri_base: 'https:/
/api.groq.com/openai/'})
llm.chat(messages: [{role: "user", content: "Tell me a story?"}], model: 'mixtral-8x7b-32768').completion This does not work, however (gives : llm.embed(text: "foo bar", model: 'mixtral-8x7b-32768').embedding |
For now (for chat completion) it seems Groq Cloud is matching OpenAI's API. So the Langchain Groq adapter could use the existing The Currently it is: I'd suggest creating a Langchain Groq class (at least to explicitly document what features are known to be available and are documented) and try using |
@andreibondarev The following should work pretty easily, and I can do a PR if you want: module Langchain::LLM
# LLM interface for Groq OpenAI compatible services
#
# Usage:
# groq = Langchain::LLM::GroqOpenAI.new(
# api_key: ENV["GROQ_API_KEY"],
# llm_options: {},
# default_options: {}
# )
class GroqOpenAI < OpenAI P.S. The Assistant and Weather tool appear to work well using OpenAI class now with |
For anyone else who just wants a quick Groq solution who might not know where the diff defaults/overrides go (e.g. me) this seems to work: @groq = llm = Langchain::LLM::OpenAI.new(
api_key: ENV["GROQ_API_KEY"],
llm_options: {
uri_base: "https://api.groq.com/openai/"
},
default_options: {
chat_completion_model_name: "llama3-70b-8192"
}
)
messages = [{:role=>"system", :content=>"I like to solve maths problems."}, {"role"=>"user", "content"=>"What is 2+2?"}]
@groq.chat(messages:).completion
# => "That's an easy one! The answer is... 4!" |
No description provided.
The text was updated successfully, but these errors were encountered: