Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```
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).
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)
or `AZURE_API_VERSION` and `AZURE_API_BASE` environment variables + `az login` for Azure OpenAI with Managed Entra.

You can then run the optillm proxy as follows.

```bash
Expand Down
23 changes: 18 additions & 5 deletions optillm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@
API_KEY = os.environ.get("OPENAI_API_KEY")
default_client = OpenAI(api_key=API_KEY)
else:
default_client = AzureOpenAI(
api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
api_version=os.environ.get("AZURE_API_VERSION"),
azure_endpoint=os.environ.get("AZURE_API_BASE"),
)
API_KEY = os.environ.get("AZURE_OPENAI_API_KEY")
API_VERSION = os.environ.get("AZURE_API_VERSION")
AZURE_ENDPOINT = os.environ.get("AZURE_API_BASE")
if API_KEY is not None:
default_client = AzureOpenAI(
api_key=API_KEY,
api_version=API_VERSION,
azure_endpoint=AZURE_ENDPOINT,
)
else:
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
azure_credential = DefaultAzureCredential()
token_provider = get_bearer_token_provider(azure_credential, "https://cognitiveservices.azure.com/.default")
default_client = AzureOpenAI(
api_version=API_VERSION,
azure_endpoint=AZURE_ENDPOINT,
azure_ad_token_provider=token_provider
)

# Server configuration
server_config = {
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ networkx
openai
z3-solver
aiohttp
flask
flask
azure.identity