spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/1.0-SNAPSHOT/index.html
Apache License 2.0
2.88k stars 721 forks source link

Does not support google gemini #1252

Open KotlinFactory opened 3 weeks ago

KotlinFactory commented 3 weeks ago

Google Gemini Pro 1.5 (especially the new experimental version) is one of the top models in the the LLM leaderboard, showcasing its exceptional capabilities and potential.

Bildschirmfoto 2024-08-20 um 13 03 46 Bildschirmfoto 2024-08-20 um 13 04 59

The model performs well especially in non-english languages such as German or English.

Bildschirmfoto 2024-08-20 um 12 40 09

However currently, Spring AI only supports accessing Google Gemini through Google Vertex AI. This requires users to manage authentication through Google Cloud and prevents the use of the standalone Gemini API.

Another user also brought this up in #1247

This leads to:

The lack of support for the standalone Gemini API in Spring AI is a significant limitation and forces users to either abandon Spring AI or refactor their codebase to use the Google Cloud SDK directly.

Expected behavior

Spring AI should provide support for the standalone Google Gemini API, similar to how other language models are integrated. This would include: Configuration options for specifying API keys and endpoints. Abstractions similar to existing language model integrations to streamline usage and maintain consistency. Documentation outlining how to configure and use the standalone Gemini API within the Spring AI framework.

Additional context

In the ReadMe of the project the relatively minor role of Java in the AI landscape is acknowledged. Tools like LangChain have gained immense popularity by focusing on developer-friendliness and providing a smooth onboarding experience. By removing barriers to entry and simplifying integrations, like enabling access to the standalone Google Gemini API, Spring AI can attract a wider audience and solidify its position as a leading framework for AI development (not just) in Java/ the JVM space.

ziodave commented 3 weeks ago

Let's see how it goes for you 😇

youngmoneee commented 3 weeks ago

I wanted to try it out as well. I’m just waiting for the branch to open. 👍

tzolov commented 3 weeks ago

@KotlinFactory , @ziodave, @youngmoneee the truth of the matter is, Google Gemini API does NOT provide Java Client. So I guess you should raise an issue somewhere on their GitHub repose (good luck to find anything reliable there).

The other option is to try to build a low-level Spring AI Gemini client on top of the REST API, as we've done for many other providers including the , now deprecated, Google Vertex PaLM2 To commit time and resources for the later we need some re-assurance that this API won't disappear in next 6 months.

Honestly Google's Dev docs and API management is amongst the most confusing out there. Would appreciate if you can point me to reliable doc and code sources.

youngmoneee commented 3 weeks ago

@tzolov in situations where Google’s APIs and models frequently change or get deprecated, how about creating an adapter interface like GoogleAiApi and simply swapping out the implementation when needed?

This approach could allow us to call methods from various implementations like PaLM2 or Gemini through bridge methods. While it’s true that Google’s API endpoints often change, it seems like the functionality they offer doesn’t differ significantly apart from performance or naming variations.

Similarly, Hugging Face supports multiple implementations through a unified interface, and it seems to work well without major issues. Maybe we could take a similar approach?

KotlinFactory commented 3 weeks ago

@KotlinFactory , @ziodave, @youngmoneee the truth of the matter is, Google Gemini API does NOT provide Java Client. So I guess you should raise an issue somewhere on their GitHub repose (good luck to find anything reliable there).

The other option is to try to build a low-level Spring AI Gemini client on top of the REST API, as we've done for many other providers including the , now deprecated, Google Vertex PaLM2 To commit time and resources for the later we need some re-assurance that this API won't disappear in next 6 months.

Honestly Google's Dev docs and API management is amongst the most confusing out there. Would appreciate if you can point me to reliable doc and code sources.

I totally agree with you, that google tends to provide horrible documentation for their APIs. Quite frankly I don't see the problem with using their Rest-API. It seems to be really straight forward to implement. Their SDKs are usually not great either, so it might actually be a benefit not having to use their SDKs.

tzolov commented 3 weeks ago

@KotlinFactory, I'm not sure the REST API reference doc event exists: https://ai.google.dev/api ?

KotlinFactory commented 3 weeks ago

Hey @tzolov it surely does. I build my own gemini client a few month ago I believe. It was based on this incomplete documentation from their side.

curl \ -X POST https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-exp-0801:generateContent?key=${API_KEY} \ -H 'Content-Type: application/json' \ -d @<(echo '{ "contents": [ { "role": "user", "parts": [ { "text": "INSERT_INPUT_HERE" } ] } ], "generationConfig": { "temperature": 1, "topK": 64, "topP": 0.95, "maxOutputTokens": 8192, "responseMimeType": "text/plain" } }')

tzolov commented 3 weeks ago

@KotlinFactory so, can you point me to this "incomplete" Google Gemini REST API documentation?

My point is that, if a billions worth company, with zillions employees can't put their ** together to add a simple API doc, why should anyone take this API seriously? Without a "stable" API with Docs I'm afraid that any efforts to reverse engineer and maintain Google APIs are likely to face API deprecated in few months - as it already happen with our efforts on Google PaLM2.

tzolov commented 3 weeks ago

@KotlinFactory, Having said this, I would be very interested to spend some time in exploring this. Unfortunately my time is stretch with some hight priority tasks. If you have time to contribute (and hopefully maintain) Spring AI Gemini (REST-based) API, it would be highly appreciated ;)

KotlinFactory commented 3 weeks ago

@tzolov Yeah I've heard about and seen the poor documentation of google APIs in various instances. Its really annoying.

Bildschirmfoto 2024-08-21 um 17 24 05

Regarding the documentation Ive just used the "get code" button.

Yes, I would love l be contributing some gemini client to Spring AI. Just one question, how feature complete does it need to be considered. I've already some simple Java based Rest client for the GeminiAPI.

KotlinFactory commented 3 weeks ago

I will try ask them for an openapi spec. Perhaps they will respond.

youngmoneee commented 3 weeks ago

Regarding the documentation Ive just used the "get code" button. Yes, I would love l be contributing some gemini client to Spring AI. Just one question, how feature complete does it need to be considered. I've already some simple Java based Rest client for the GeminiAPI.

I will join when the branch opens.

KotlinFactory commented 3 weeks ago

Okay, apparently there at least was a more complete documentation at some point.

Bildschirmfoto 2024-08-21 um 17 41 30

https://discuss.ai.google.dev/t/gemini-rest-documentation-disappeared/36825/2

tzolov commented 3 weeks ago

Thanks for digging further @KotlinFactory

I found this Migrate from Gemini on Google AI to Vertex AI documentation: https://cloud.google.com/vertex-ai/generative-ai/docs/migrate/migrate-google-ai

Apparently, unlike Vertex AI, no Enterprise support nor MLOps for Google AI Gemini API is expected. Not very encouraging to commit to this API.

If I understand correct the primary reason for someone to consider Gemini API over Vertex AI API is the API key authentication former support and later lacks?

Otherwise, you can use any of the available models (including 1.5 pro & flash) with the Spring AI Vertex Gemini Chat model. Any other differences?

KotlinFactory commented 3 weeks ago

Yeah thats the primary concern. I dont beliebe users should be forced to use GCP just to use gemini.

There is also some response from their side. It appears like we can obtain an openapi spec given the instructions.

See https://github.com/google-gemini/cookbook/issues/261

KotlinFactory commented 3 weeks ago

@tzolov Perhaps it would be an idea to reuse some parts of the vertex.ai module? I think except for authentication its basically identical.

markpollack commented 1 week ago

Given the enterprise customer base we focus on, I don't see us having bandwidth to devote to this in the short term. Is'nt it really more of an issue using an API key than 'using GCP' @KotlinFactory (neat handle name btw)