-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the Python client library instructions into a quickstart
- Loading branch information
Showing
2 changed files
with
42 additions
and
19 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Quickstart | ||
|
||
## OpenAI API | ||
|
||
Obtain a Gemini API key from the [AI Studio](https://aistudio.google.com/). | ||
Then set the following environmental variable to the key and run the proxy: | ||
|
||
```sh | ||
$ export GEMINI_API_KEY=<YOUR_API_KEY> | ||
$ docker run -p 5555:5555 -e GEMINI_API_KEY=$GEMINI_API_KEY googlegemini/proxy-to-gemini | ||
``` | ||
|
||
Set the following environment variable to the proxy: | ||
|
||
```sh | ||
$ export OPENAI_BASE_URL="http://127.0.0.1:5555/v1" | ||
``` | ||
|
||
Then the OpenAI Python client library will use the proxy. | ||
Save the following code in test.py: | ||
|
||
```python | ||
from openai import OpenAI | ||
|
||
client = OpenAI() | ||
chat_completion = client.chat.completions.create( | ||
model = "gemini-1.5-pro", | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": "Say this is a test", | ||
} | ||
], | ||
) | ||
print(chat_completion) | ||
``` | ||
|
||
Run the Python file: | ||
|
||
```sh | ||
$ python3 test.py | ||
``` |