Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A proxy for converting the OpenAI API protocol to the Google Gemini Pro protocol.

License

NotificationsYou must be signed in to change notification settings

zhu327/gemini-openai-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gemini-OpenAI-Proxy is a proxy designed to convert the OpenAI API protocol to the Google Gemini protocol. This enables applications built for the OpenAI API to seamlessly communicate with the Gemini protocol, including support for Chat Completion, Embeddings, and Model(s) endpoints.


Table of Contents


Build

To build the Gemini-OpenAI-Proxy, follow these steps:

go build -o gemini main.go

Deploy

We recommend deploying Gemini-OpenAI-Proxy using Docker for a straightforward setup. Follow these steps to deploy with Docker:

You can either do this on the command line:

docker run --restart=unless-stopped -it -d -p 8080:8080 --name gemini zhu327/gemini-openai-proxy:latest

Or with the following docker-compose config:

version:'3'services:gemini:container_name:geminienvironment:# Set Environment Variables here. Defaults listed below         -GPT_4_VISION_PREVIEW=gemini-1.5-flash-latest         -DISABLE_MODEL_MAPPING=0ports:         -"8080:8080"image:zhu327/gemini-openai-proxy:latestrestart:unless-stopped

Adjust the port mapping (e.g.,-p 8080:8080) as needed, and ensure that the Docker image version (zhu327/gemini-openai-proxy:latest) aligns with your requirements.


Usage

Gemini-OpenAI-Proxy offers a straightforward way to integrate OpenAI functionalities into any application that supports custom OpenAI API endpoints. Follow these steps to leverage the capabilities of this proxy:

  1. Set Up OpenAI Endpoint:Ensure your application is configured to use a custom OpenAI API endpoint. Gemini-OpenAI-Proxy seamlessly works with any OpenAI-compatible endpoint.

  2. Get Google AI Studio API Key:Before using the proxy, you'll need to obtain an API key fromai.google.dev. Treat this API key as your OpenAI API key when interacting with Gemini-OpenAI-Proxy.

  3. Integrate the Proxy into Your Application:Modify your application's API requests to target the Gemini-OpenAI-Proxy, providing the acquired Google AI Studio API key as if it were your OpenAI API key.

    Example Chat Completion API Request (Assuming the proxy is hosted athttp://localhost:8080):

    curl http://localhost:8080/v1/chat/completions \ -H"Content-Type: application/json" \ -H"Authorization: Bearer$YOUR_GOOGLE_AI_STUDIO_API_KEY" \ -d'{     "model": "gpt-3.5-turbo",     "messages": [{"role": "user", "content": "Say this is a test!"}],     "temperature": 0.7 }'

    Alternatively, use Gemini Pro Vision:

    curl http://localhost:8080/v1/chat/completions \ -H"Content-Type: application/json" \ -H"Authorization: Bearer$YOUR_GOOGLE_AI_STUDIO_API_KEY" \ -d'{     "model": "gpt-4-vision-preview",     "messages": [{"role": "user", "content": [        {"type": "text", "text": "What’s in this image?"},        {          "type": "image_url",          "image_url": {            "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"          }        }     ]}],     "temperature": 0.7 }'

    If you wish to mapgpt-4-vision-preview togemini-1.5-pro-latest, you can configure the environment variableGPT_4_VISION_PREVIEW = gemini-1.5-pro-latest. This is becausegemini-1.5-pro-latest now also supports multi-modal data. Otherwise, the default uses thegemini-1.5-flash-latest model

    If you already have access to the Gemini 1.5 Pro api, you can use:

    curl http://localhost:8080/v1/chat/completions \ -H"Content-Type: application/json" \ -H"Authorization: Bearer$YOUR_GOOGLE_AI_STUDIO_API_KEY" \ -d'{     "model": "gpt-4-turbo-preview",     "messages": [{"role": "user", "content": "Say this is a test!"}],     "temperature": 0.7 }'

    Example Embeddings API Request:

    curl http://localhost:8080/v1/embeddings \ -H"Content-Type: application/json" \ -H"Authorization: Bearer$YOUR_GOOGLE_AI_STUDIO_API_KEY" \ -d'{    "model": "text-embedding-ada-002",    "input": "This is a test sentence." }'

    You can also pass in multiple input strings as a list:

    curl http://localhost:8080/v1/embeddings \ -H"Content-Type: application/json" \ -H"Authorization: Bearer$YOUR_GOOGLE_AI_STUDIO_API_KEY" \ -d'{    "model": "text-embedding-ada-002",    "input": ["This is a test sentence.", "This is another test sentence"] }'

    Model Mapping:

    GPT ModelGemini Model
    gpt-4gemini-1.5-flash-002
    gpt-4-turbo-previewgemini-1.5-pro-latest
    gpt-4ogemini-2.0-flash-exp
    text-embedding-ada-002text-embedding-004

    If you want to disable model mapping, configure the environment variableDISABLE_MODEL_MAPPING=1. This will allow you to refer to the Gemini models directly.

    Here is an example API request with model mapping disabled:

    curl http://localhost:8080/v1/chat/completions \ -H"Content-Type: application/json" \ -H"Authorization: Bearer$YOUR_GOOGLE_AI_STUDIO_API_KEY" \ -d'{     "model": "gemini-1.0-pro-latest",     "messages": [{"role": "user", "content": "Say this is a test!"}],     "temperature": 0.7 }'
  4. Handle Responses:Process the responses from the Gemini-OpenAI-Proxy in the same way you would handle responses from OpenAI.

Now, your application is equipped to leverage OpenAI functionality through the Gemini-OpenAI-Proxy, bridging the gap between OpenAI and applications using the Google Gemini Pro protocol.

Compatibility

Important Notice

Google AI Studio now provides an OpenAI-compatible API endpoint. Users of this project are recommended to use the officially provided compatibility API. Documentation is available at:

https://ai.google.dev/gemini-api/docs/openai


License

Gemini-OpenAI-Proxy is licensed under the MIT License - see theLICENSE file for details.

About

A proxy for converting the OpenAI API protocol to the Google Gemini Pro protocol.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp