Skip to content

Commit

Permalink
update openai docs
Browse files Browse the repository at this point in the history
Signed-off-by: oilbeater <[email protected]>
  • Loading branch information
oilbeater committed Oct 23, 2024
1 parent 723d094 commit ca9f107
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ It is written in **TypeScript**: ensuring adaptability to the rapidly evolving A

### Supported LLM Providers

- [OpenAI](./docs/openai.md)
- [Azure OpenAI](./docs/azure_openai.md)
- [DeepSeek](./docs/deepseek.md)

Expand Down
29 changes: 29 additions & 0 deletions docs/openai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# OpenAI

To leverage the advanced features provided by Malacca while using the OpenAI API, you only need to adjust the `base_url` configuration in the original SDK. This simple change allows you to benefit from Malacca's capabilities such as caching, virtual key management, rate limiting, logging and all other features.

You need to get the following parameters:

- `Worker_Domain`: The domain url where your Worker is accessible, you can find it in your worker Settings.
- `Virtual_Key`: The virtual key that protect your real API key.

## Python Example

You can use [OpenAI Python SDK](https://github.com/openai/openai-python) to visit OpenAI with Malacca endpoint.

```python
from openai import OpenAI

client = OpenAI(api_key="{Virtual_Key}", base_url="https://{Worker_Domain}/openai/")

response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Tell me a very short story about Malacca."},
],
stream=False
)

print(response.choices[0].message.content)
```

0 comments on commit ca9f107

Please sign in to comment.