-
Notifications
You must be signed in to change notification settings - Fork 111
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
Eliminate OpenAI -> Gemini Model Mapping #38
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# Gemini-OpenAI-Proxy | ||
|
||
Gemini-OpenAI-Proxy is a proxy designed to convert the OpenAI API protocol to the Google Gemini Pro protocol. This enables seamless integration of OpenAI-powered functionalities into applications using the Gemini Pro protocol. | ||
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. | ||
|
||
This is a fork of zhu327/gemini-openai-proxy that eliminates the mapping of openAI models to gemini models and directly exposes the underlying gemini models to the api endpoints directly. I've also added support for Google's embeddings model. This was motivated by my own issues with using Google's [openAI API Compatible Endpoint](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/call-gemini-using-openai-library). | ||
|
||
--- | ||
|
||
|
@@ -30,11 +32,24 @@ go build -o gemini main.go | |
|
||
We recommend deploying Gemini-OpenAI-Proxy using Docker for a straightforward setup. Follow these steps to deploy with Docker: | ||
|
||
```bash | ||
docker run --restart=always -it -d -p 8080:8080 --name gemini zhu327/gemini-openai-proxy:latest | ||
``` | ||
You can either do this on the command line: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GitHub Actions will automatically build Docker images, so we can just use the existing image here. |
||
```bash | ||
docker run --restart=unless-stopped -it -d -p 8080:8080 --name gemini ghcr.io/ekatiyar/gemini-openai-proxy:latest | ||
``` | ||
|
||
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. | ||
Or with the following docker-compose config: | ||
```yaml | ||
version: '3' | ||
services: | ||
gemini: | ||
container_name: gemini | ||
ports: | ||
- "8080:8080" | ||
image: ghcr.io/ekatiyar/gemini-openai-proxy:latest | ||
restart: unless-stopped | ||
``` | ||
|
||
Adjust the port mapping (e.g., `-p 5001:8080`) as needed, and ensure that the Docker image version aligns with your requirements. If you only want the added embedding model support and still want open ai model mapping, use `ghcr.io/ekatiyar/gemini-openai-proxy:embedding` instead | ||
|
||
--- | ||
|
||
|
@@ -51,13 +66,13 @@ Gemini-OpenAI-Proxy offers a straightforward way to integrate OpenAI functionali | |
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 API Request (Assuming the proxy is hosted at `http://localhost:8080`): | ||
Example Chat Completion API Request (Assuming the proxy is hosted at `http://localhost:8080`): | ||
```bash | ||
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", | ||
"model": "gemini-1.0-pro-latest", | ||
"messages": [{"role": "user", "content": "Say this is a test!"}], | ||
"temperature": 0.7 | ||
}' | ||
|
@@ -70,7 +85,7 @@ Gemini-OpenAI-Proxy offers a straightforward way to integrate OpenAI functionali | |
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $YOUR_GOOGLE_AI_STUDIO_API_KEY" \ | ||
-d '{ | ||
"model": "gpt-4-vision-preview", | ||
"model": "gemini-1.5-vision-latest", | ||
"messages": [{"role": "user", "content": [ | ||
{"type": "text", "text": "What’s in this image?"}, | ||
{ | ||
|
@@ -83,6 +98,7 @@ Gemini-OpenAI-Proxy offers a straightforward way to integrate OpenAI functionali | |
"temperature": 0.7 | ||
}' | ||
``` | ||
If you wish to map `gemini-1.5-vision-latest` to `gemini-1.5-pro-latest`, you can configure the environment variable `GEMINI_VISION_PREVIEW = gemini-1.5-pro-latest`. This is because `gemini-1.5-pro-latest` now also supports multi-modal data. Otherwise, the default is to use the `gemini-1.5-flash-latest` model | ||
|
||
If you already have access to the Gemini 1.5 Pro api, you can use: | ||
|
||
|
@@ -91,22 +107,36 @@ Gemini-OpenAI-Proxy offers a straightforward way to integrate OpenAI functionali | |
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $YOUR_GOOGLE_AI_STUDIO_API_KEY" \ | ||
-d '{ | ||
"model": "gpt-4-turbo-preview", | ||
"model": "gemini-1.5-pro-latest", | ||
"messages": [{"role": "user", "content": "Say this is a test!"}], | ||
"temperature": 0.7 | ||
}' | ||
``` | ||
|
||
Model Mapping: | ||
Example Embeddings API Request: | ||
|
||
| GPT Model | Gemini Model | | ||
|---|---| | ||
| gpt-3.5-turbo | gemini-1.0-pro-latest | | ||
| gpt-4 | gemini-1.5-flash-latest | | ||
| gpt-4-turbo-preview | gemini-1.5-pro-latest | | ||
| gpt-4-vision-preview | gemini-1.0-pro-vision-latest | | ||
```bash | ||
curl http://localhost:8080/v1/embeddings \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $YOUR_GOOGLE_AI_STUDIO_API_KEY" \ | ||
-d '{ | ||
"model": "text-embedding-004", | ||
"input": "This is a test sentence." | ||
}' | ||
``` | ||
|
||
You can also pass in multiple input strings as a list: | ||
|
||
```bash | ||
curl http://localhost:8080/v1/embeddings \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $YOUR_GOOGLE_AI_STUDIO_API_KEY" \ | ||
-d '{ | ||
"model": "text-embedding-004", | ||
"input": ["This is a test sentence.", "This is another test sentence"] | ||
}' | ||
``` | ||
|
||
If you wish to map `gpt-4-vision-preview` to `gemini-1.5-pro-latest`, you can configure the environment variable `GPT_4_VISION_PREVIEW = gemini-1.5-pro-latest`. This is because `gemini-1.5-pro-latest` now also supports multi-modal data. | ||
|
||
4. **Handle Responses:** | ||
Process the responses from the Gemini-OpenAI-Proxy in the same way you would handle responses from OpenAI. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the steps about forking from the README.