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

400 Error on Vanilla use of function calling API? #28

Open
DGaffney opened this issue Sep 23, 2024 · 0 comments
Open

400 Error on Vanilla use of function calling API? #28

DGaffney opened this issue Sep 23, 2024 · 0 comments

Comments

@DGaffney
Copy link

Hello!

Just getting started here - I've created an API key via https://aistudio.google.com/app/apikey and done nothing else to configure - I have my API key from that site - and I run the code as follows (and API key is set correctly). The function calling example doesn't work, but the toy demo they provide does workj

client = Gemini.new(
  credentials: {
    service: 'generative-language-api',
    api_key: ENV['GOOGLE_API_KEY']
  },
  options: { model: 'gemini-pro', server_sent_events: true }
)
input = {
  tools: {
    function_declarations: [
      {
        name: 'date_and_time',
        description: 'Returns the current date and time in the ISO 8601 format for a given timezone.',
        parameters: {
          type: 'object',
          properties: {
            timezone: {
              type: 'string',
              description: 'A string represents the timezone to be used for providing a datetime, following the IANA (Internet Assigned Numbers Authority) Time Zone Database. Examples include "Asia/Tokyo" and "Europe/Paris". If not provided, the default timezone is the user\'s current timezone.'
            }
          }
        }
      }
    ]
  },
  contents: [
    { role: 'user', parts: { text: 'What time is it?' } }
  ]
}
irb(main):068:0> result = client.stream_generate_content(input)                                                                                                                                                                                                                                                                                                                                                                          
ETHON: performed EASY effective_url=https://generativelanguage.googleapis.com/v1/models/gemini-1.0-pro:streamGenerateContent?alt=sse&key=XXX response_code=400 return_code=ok total_time=0.038375                                                                                                                                                                                                    
/usr/local/lib/ruby/gems/3.1.0/gems/faraday-2.12.0/lib/faraday/response/raise_error.rb:30:in `on_complete': the server responded with status 400 (Faraday::BadRequestError)                                                                                                                                                                                                                                                              

The basic toy demo works fine:

irb(main):077:0> input = {"contents":[{"parts":[{"text":"Explain how AI works"}]}]}
=> {:contents=>[{:parts=>[{:text=>"Explain how AI works"}]}]}
irb(main):078:0> result = client.stream_generate_content(input)
ETHON: performed EASY effective_url=https://generativelanguage.googleapis.com/v1/models/vertex-ai-api:streamGenerateContent?key=XXX response_code=404 return_code=ok total_time=0.093008
/usr/local/lib/ruby/gems/3.1.0/gems/faraday-2.12.0/lib/faraday/response/raise_error.rb:30:in `on_complete': the server responded with status 404 (Faraday::ResourceNotFound)
irb(main):079:0> result
=> 
[{"candidates"=>                          
   [{"content"=>{"parts"=>[{"text"=>"**Artificial Intelligence (AI)** is the simulation of human intelligence processes by machines,"}], "role"=>"model"},
     "finishReason"=>"STOP",              
     "index"=>0,                          
     "safetyRatings"=>                    

I'm guessing I'm missing some configuration for my account - any leads on what the likely error is here?

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

No branches or pull requests

1 participant