Google recently released a new endpoint for the Gemini API, aiming to simplify the migration process from OpenAI solutions to Gemini. This move is designed to provide developers with a more convenient way to take advantage of the power of Gemini. The new endpoint is currently in beta and supports only some features of the OpenAI API, such as chat completion and embed APIs, and provides sample code for using the Gemini model through REST calls or the official OpenAI SDK. This provides new options for developers to switch between different large language models and triggers industry discussions about future API standardization.
Google recently announced the launch of its new endpoint for its Gemini API, aiming to help developers who already adopt OpenAI solutions switch to Gemini more easily. This new endpoint is still in beta and only provides support for some OpenAI features.
According to Google, this new endpoint can replace OpenAI's endpoint with a direct REST call or OpenAI official SDK. For example, if you have a program written using the OpenAI SDK (such as Python), you can change the initialization through the following code, using Google's model:
from openai import OpenAI
client = OpenAI (
api_key="gemini_api_key",
base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
)
In the code, the developer needs to provide a Gemini API key, which can be written directly in the code or passed through the OPENAI_API_KEY environment variable. To generate text, you can use the Chat Completion API, as shown below, specifying the name of the Gemini model you want to use:
response = client.chat.completions.create (
model="gemini-1.5-flash",
n=1,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{
"role": "user",
"content": "Explain me how AI works"
}
]
)
print (response.choices [0].message)
In addition, the new Gemini endpoint supports OpenAI's embedded API to measure correlations between text strings. In short, the Embed API maps text into vectors of floating point numbers, which developers can use to search for specific values, cluster text, detect exceptions, and provide recommendations. The following code snippet shows how to use this feature in Gemini:
response = client.embeddings.create (
input="Your text string is here",
model="text-embedding-004"
)
print (response.data [0].embedding)
Currently, the Chat Completion API and Embed API are the only OpenAI features that can be used on the Gemini model through the new OpenAI endpoint. In addition, support for image upload and structured output is limited to limited functionality. Google said it plans to add more OpenAI features so developers can use Gemini as an alternative to OpenAI, but the specific time frame is not yet clear.
In Reddit discussion, commenters praised Google's move, believing it provides OpenAI API users with a solution to escape locking, although distances implement a standard API to facilitate easy switching between different model providers There is still a long way to go.
As a more general approach, the vLLM project is designed to support a variety of generation and embedding models and provide an OpenAI-compatible server. With vLLM, developers can use Mistral, Llama, Llava, and many other major models currently available.
Official introduction: https://developers.googleblog.com/en/gemini-is-now-accessible-from-the-openai-library/
Key points:
Google launches new endpoints for Gemini API to help developers switch to Gemini more easily.
The new endpoint supports OpenAI's chat completion and embedding API, but its functionality is not yet complete.
The vLLM project provides support for multiple models to improve API flexibility.
In short, the launch of Google's new endpoints provides developers with more flexible options, but its functions are still in the stage of improvement, and future development is worth looking forward to. Projects such as vLLM provide another way for developers seeking broader model support, promoting the sustainable development of the large language model ecosystem.