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

Fixed google ai default endpoint #118

Closed
wants to merge 1 commit into from

Conversation

ljgago
Copy link

@ljgago ljgago commented May 15, 2024

Hello!

In the ChatGoogleAI is wrong the default endpoint.

@default_base_url "https://generativelanguage.googleapis.com"
@default_api_version "v1beta"
@default_endpoint "#{@default_base_url}/#{@default_api_version}"

embedded_schema do
field :endpoint, :string, default: @default_endpoint
# The version of the API to use.
field :version, :string, default: @default_api_version

Then, when the final url is geneated, the version is added again:

@spec build_url(t()) :: String.t()
defp build_url(%ChatGoogleAI{endpoint: endpoint, version: version, model: model} = google_ai) do
"#{endpoint}/#{version}/models/#{model}:#{get_action(google_ai)}?key=#{get_api_key(google_ai)}"
|> use_sse(google_ai)
end

This PR only define @default_endpoint with the base url without the api version.

Thanks!

Copy link

@yeshan333 yeshan333 left a comment

Choose a reason for hiding this comment

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

I also encountered the same problem and solved it according to this modification.

@brainlid
Copy link
Owner

Thanks @ljgago! I'm not a Google AI user so I rely on others to help support and understand the issues.

Is this related to #85?

If so, I think the problem is there are two separate Google APIs that use the same structure/format for their messages and communication, but connections are made differently.

@ljgago
Copy link
Author

ljgago commented May 18, 2024

Hi @brainlid!

I checked and Google has two platforms:

  • Google AI Gemini API
  • Google Cloud Vertex AI Gemini API

Google AI Gemini API is public and can be used for free (with limitations) with any google account. API REST and the base endpoint is https://generativelanguage.googleapis.com

Google Cloud Vertex AI Gemini API is for Google Cloud platform API REST and the endpoint depends from the region, etc and the api may be different.

I think that ChatGoogleAI module is for Google AI Gemini API and the issue here is that the final url adds the version twice and the call fails.

Thanks!

@brainlid
Copy link
Owner

Thanks @ljgago for digging into that. What is needed to work well for both systems? Is it just a URL change? Or is there more?

@ljgago
Copy link
Author

ljgago commented May 20, 2024

Here some comparatives:

Google AI Gemini API

Google Cloud Vertex AI Gemini API

The two are very similar with the request model and response model, the main difference is with the url and the auth method.

@raulchedrese
Copy link
Contributor

@brainlid, @ljgago I had a bunch of trouble getting the existing ChatGoogleAI to work with Vertex AI. There are subtle differences in the request formats. For example Vertex seems to have stricter validation on which properties are included in the request and what their values are. I ended up writing a separate module that is working quite well for Gemini through Vertex AI.

I'm happy to contribute some of that code if you think it's helpful but thus far I'm not convinced it is feasible to have a single module handle both APIs.

@brainlid
Copy link
Owner

I had a bunch of trouble getting the existing ChatGoogleAI to work with Vertex AI. There are subtle differences in the request formats. For example Vertex seems to have stricter validation on which properties are included in the request and what their values are.

Leave it to Google to create two competing and incompatible tools to do the same thing. 🙄

From what you say @raulchedrese, it sounds like two separate versions may work out best. Can we base the new one on your implementation?

@raulchedrese
Copy link
Contributor

@brainlid yep. I can clean it up and open a PR if you like or feel free to grab the code yourself. Whatever is easiest.

@brainlid
Copy link
Owner

@raulchedrese I'd really appreciate it as a PR. Also, if you can write some tests around it that would be fantastic.

@raulchedrese
Copy link
Contributor

@brainlid created a PR here.

@brainlid
Copy link
Owner

brainlid commented Jun 6, 2024

@ljgago @raulchedrese contributed a specific VertextAI chat module to handle both the URL difference and other peculiarities between the two implementations.

#124

The PR has been merged. Would you please try it out and see if it meets your needs as well?

@ljgago
Copy link
Author

ljgago commented Jun 6, 2024

@ljgago @raulchedrese contributed a specific VertextAI chat module to handle both the URL difference and other peculiarities between the two implementations.

#124

The PR has been merged. Would you please try it out and see if it meets your needs as well?

Hello! I don't have Google Cloud access credentials to try VertexAI, I'm sorry. 😦

@brainlid
Copy link
Owner

brainlid commented Jun 7, 2024

Hello! I don't have Google Cloud access credentials to try VertexAI, I'm sorry. 😦

No worries! My mistake. I thought that what you were asking about.

@brainlid
Copy link
Owner

brainlid commented Jul 6, 2024

The ChatGoogleAI URL issues have been fixed in PR #152 and merged to main.

@brainlid brainlid closed this Jul 6, 2024
@ljgago ljgago deleted the google-ai-endpoint branch July 6, 2024 16:13
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.

4 participants