Skip to content

Commit e10cdf4

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents 5983fa0 + 0f676c4 commit e10cdf4

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ OPENAI_API_KEY=
44
# CODEBOX_API_KEY=
55
# (set True to enable logging)
66
VERBOSE=False
7+
# (optional, required for Azure OpenAI)
8+
# OPENAI_API_TYPE=azure
9+
# OPENAI_API_VERSION=2023-07-01-preview
10+
# OPENAI_API_BASE=
11+
# DEPLOYMENT_NAME=

.github/workflows/code-check.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: code-check
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
410

511
jobs:
612
pre-commit:

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,23 @@ For deployments, you can use `pip install codeinterpreterapi` instead which does
2727

2828
## Usage
2929

30-
Make sure to set the `OPENAI_API_KEY` environment variable (or use a `.env` file)
30+
To configure OpenAI and Azure OpenAI, ensure that you set the appropriate environment variables (or use a .env file):
31+
32+
For OpenAI, set the OPENAI_API_KEY environment variable:
33+
```
34+
export OPENAI_API_KEY=your_openai_api_key
35+
```
36+
37+
For Azure OpenAI, set the following environment variables:
38+
```
39+
export OPENAI_API_TYPE=azure
40+
export OPENAI_API_VERSION=your_api_version
41+
export OPENAI_API_BASE=your_api_base
42+
export OPENAI_API_KEY=your_azure_openai_api_key
43+
export DEPLOYMENT_NAME=your_deployment_name
44+
```
45+
46+
Remember to replace the placeholders with your actual API keys and other required information.
3147

3248
```python
3349
from codeinterpreterapi import CodeInterpreterSession

codeinterpreterapi/session.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ConversationalAgent,
1515
ConversationalChatAgent,
1616
)
17-
from langchain.chat_models import ChatAnthropic, ChatOpenAI
17+
from langchain.chat_models import AzureChatOpenAI, ChatAnthropic, ChatOpenAI
1818
from langchain.chat_models.base import BaseChatModel
1919
from langchain.memory import ConversationBufferMemory
2020
from langchain.prompts.chat import MessagesPlaceholder
@@ -90,13 +90,33 @@ def _choose_llm(
9090
"OpenAI API key missing. Set OPENAI_API_KEY env variable "
9191
"or pass `openai_api_key` to session."
9292
)
93-
return ChatOpenAI(
94-
temperature=0.03,
95-
model=model,
96-
openai_api_key=openai_api_key,
97-
max_retries=3,
98-
request_timeout=60 * 3,
99-
) # type: ignore
93+
openai_api_version = getenv("OPENAI_API_VERSION")
94+
openai_api_base = getenv("OPENAI_API_BASE")
95+
deployment_name = getenv("DEPLOYMENT_NAME")
96+
openapi_type = getenv("OPENAI_API_TYPE")
97+
if (
98+
openapi_type == "azure"
99+
and openai_api_version
100+
and openai_api_base
101+
and deployment_name
102+
):
103+
return AzureChatOpenAI(
104+
temperature=0.03,
105+
openai_api_base=openai_api_base,
106+
openai_api_version=openai_api_version,
107+
deployment_name=deployment_name,
108+
openai_api_key=openai_api_key,
109+
max_retries=3,
110+
request_timeout=60 * 3,
111+
)
112+
else:
113+
return ChatOpenAI(
114+
temperature=0.03,
115+
model=model,
116+
openai_api_key=openai_api_key,
117+
max_retries=3,
118+
request_timeout=60 * 3,
119+
)
100120
elif "claude" in model:
101121
return ChatAnthropic(model=model)
102122
else:

0 commit comments

Comments
 (0)