Skip to content

Commit 21e5134

Browse files
committed
2 parents c2c3b1f + 776cc9f commit 21e5134

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ python3 -m venv .venv
3636
source .venv/bin/activate
3737
pip install -r requirements.txt
3838
```
39-
39+
Set up the `OPENAI_API_KEY` environment variable (for OpenAI) or the `AZURE_OPENAI_API_KEY`, `AZURE_API_VERSION` and `AZURE_API_BASE` environment variables (for Azure OpenAI).
4040
You can then run the optillm proxy as follows.
4141

4242
```bash
@@ -77,7 +77,7 @@ response = client.chat.completions.create(
7777

7878
print(response)
7979
```
80-
80+
The code above applies to both OpenAI and Azure OpenAI, just remember to populate the `OPENAI_API_KEY` env variable with the proper key.
8181
You can control the technique you use for optimization by prepending the slug to the model name `{slug}-model-name`. E.g. in the above code we are using `moa` or
8282
mixture of agents as the optimization approach. In the proxy logs you will see the following showing the `moa` is been used with the base model as `gpt-4o-mini`.
8383

optillm.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import secrets
55
from flask import Flask, request, jsonify
6-
from openai import OpenAI
6+
from openai import AzureOpenAI, OpenAI
77

88
# Import approach modules
99
from mcts import chat_with_mcts
@@ -26,9 +26,16 @@
2626
# Initialize Flask app
2727
app = Flask(__name__)
2828

29-
# OpenAI API configuration
30-
API_KEY = os.environ.get("OPENAI_API_KEY")
31-
default_client = OpenAI(api_key=API_KEY)
29+
# OpenAI or Azure API configuration
30+
if os.environ.get("OPENAI_API_KEY") != None:
31+
API_KEY = os.environ.get("OPENAI_API_KEY")
32+
default_client = OpenAI(api_key=API_KEY)
33+
else:
34+
default_client = AzureOpenAI(
35+
api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
36+
api_version=os.environ.get("AZURE_API_VERSION"),
37+
azure_endpoint=os.environ.get("AZURE_API_BASE"),
38+
)
3239

3340
# Server configuration
3441
server_config = {

0 commit comments

Comments
 (0)