patterns-ai-core / langchainrb

Build LLM-powered applications in Ruby
https://rubydoc.info/gems/langchainrb
MIT License
1.39k stars 194 forks source link

undefined method `URI' for #<Langchain::LLM::GoogleGemini> #753

Closed palladius closed 2 months ago

palladius commented 2 months ago

Gem version: 0.15.2 Seems like URI dependency is overlooked for this:

input

llm = Langchain::LLM::GoogleGemini.new(api_key: ENV["GEMINI_API_KEY"])
llm.chat(messages: [{role: "user", content: "What is the meaning of life?"}]).completion

output - should Summarize the text:

irb(main):014> llm.chat(messages: [{role: "user", content: "What is the meaning of life?"}])
/usr/local/google/home/ricc/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/langchainrb-0.15.2/lib/langchain/llm/google_gemini.rb:61:in `chat': undefined method `URI' for #<Langchain::LLM::GoogleGemini:0x00007f8e13229a18 @api_key="REDACTED", @defaults={:chat_completion_model_name=>"gemini-1.5-pro-latest", :embeddings_model_name=>"text-embedding-004", :temperature=>0.0}, @chat_parameters=#<Langchain::LLM::UnifiedParameters:0x00007f8e14506500 @schema={:messages=>{}, :model=>{:default=>"gemini-1.5-pro-latest"}, :prompt=>{}, :system=>{}, :response_format=>{}, :stop=>{}, :stream=>{}, :max_tokens=>{}, :temperature=>{:default=>0.0}, :top_p=>{}, :top_k=>{}, :frequency_penalty=>{}, :presence_penalty=>{}, :repetition_penalty=>{}, :seed=>{}, :tools=>{:default=>[]}, :tool_choice=>{}, :logit_bias=>{}, :generation_config=>{:default=>nil}, :safety_settings=>{:default=>nil}, :contents=>{}, :system_instruction=>{}, :tool_config=>{}}, @aliases={}, @remapped={:messages=>:contents, :system=>:system_instruction, :tool_choice=>:tool_config}, @ignored=#<Set: {}>, @parameters={:model=>"gemini-1.5-pro-latest", :contents=>[{:role=>"user", :content=>"What is the meaning of life?"}], :generation_config=>{:temperature=>0.0}}>> (NoMethodError)

      uri = URI("https://generativelanguage.googleapis.com/v1beta/models/#{parameters[:model]}:generateContent?key=#{api_key}")
            ^^^
andreibondarev commented 2 months ago

@palladius I dropped a fix in. Btw -- the proper syntax for the messages hash is the following:

irb(main):002> llm.chat(messages: [{role: "user", parts: {text: "What is the meaning of life?"}}]).chat_completion