Skip to content

Commit

Permalink
Move the Python client library instructions into a quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyll committed Sep 9, 2024
1 parent 73bc67e commit 9b46b29
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
19 changes: 0 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,6 @@ $ curl http://127.0.0.1:5555/v1/embeddings \
}
```

OpenAI client library could be configured to use the proxy:

```python
from openai import OpenAI

client = OpenAI(
base_url="http://127.0.0.1:5555/v1", # or set OPENAI_BASE_URL environmental variable
)
chat_completion = client.chat.completions.create(
model = "gemini-1.5-pro",
messages=[
{
"role": "user",
"content": "Say this is a test",
}
],
)
```

### Known OpenAI Limitations

* Only [chat completions](https://platform.openai.com/docs/api-reference/chat) and [embeddings](https://platform.openai.com/docs/api-reference/embeddings/create) are planned to be supported.
Expand Down
42 changes: 42 additions & 0 deletions docs/quickstart.md
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
```

0 comments on commit 9b46b29

Please sign in to comment.