Skip to content

Commit fe97056

Browse files
authored
Fix AzureVisionAgent (#133)
1 parent bdb2662 commit fe97056

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,25 @@ ensure the documentation is in the same format above with description, `Paramete
182182
`Returns:`, and `Example\n-------`. You can find an example use case [here](examples/custom_tools/).
183183

184184
### Azure Setup
185-
If you want to use Azure OpenAI models, you can set the environment variable:
185+
If you want to use Azure OpenAI models, you need to have two OpenAI model deployments:
186+
187+
1. OpenAI GPT-4o model
188+
2. OpenAI text embedding model
189+
190+
191+
Then you can set the following environment variables:
186192

187193
```bash
188194
export AZURE_OPENAI_API_KEY="your-api-key"
189195
export AZURE_OPENAI_ENDPOINT="your-endpoint"
196+
# The deployment name of your OpenAI chat model
197+
export AZURE_OPENAI_CHAT_MODEL_DEPLOYMENT_NAME="your_gpt4o_model_deployment_name"
198+
# The deployment name of your OpenAI text embedding model
199+
export AZURE_OPENAI_EMBEDDING_MODEL_DEPLOYMENT_NAME="your_embedding_model_deployment_name"
190200
```
191201

202+
> NOTE: make sure your Azure model deployment have enough quota (token per minute) to support it.
203+
192204
You can then run Vision Agent using the Azure OpenAI models:
193205

194206
```python

vision_agent/lmm/lmm.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def generate_image_qa_tool(self, question: str) -> Callable:
233233
class AzureOpenAILMM(OpenAILMM):
234234
def __init__(
235235
self,
236-
model_name: str = "gpt-4o",
236+
model_name: Optional[str] = None,
237237
api_key: Optional[str] = None,
238238
api_version: str = "2024-02-01",
239239
azure_endpoint: Optional[str] = None,
@@ -245,14 +245,20 @@ def __init__(
245245
api_key = os.getenv("AZURE_OPENAI_API_KEY")
246246
if not azure_endpoint:
247247
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
248+
if not model_name:
249+
model_name = os.getenv("AZURE_OPENAI_CHAT_MODEL_DEPLOYMENT_NAME")
248250

249251
if not api_key:
250252
raise ValueError("OpenAI API key is required.")
251253
if not azure_endpoint:
252254
raise ValueError("Azure OpenAI endpoint is required.")
255+
if not model_name:
256+
raise ValueError("Azure OpenAI chat model deployment name is required.")
253257

254258
self.client = AzureOpenAI(
255-
api_key=api_key, api_version=api_version, azure_endpoint=azure_endpoint
259+
api_key=api_key,
260+
api_version=api_version,
261+
azure_endpoint=azure_endpoint,
256262
)
257263
self.model_name = model_name
258264

vision_agent/utils/sim.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,23 @@ def __init__(
8787
api_key: Optional[str] = None,
8888
api_version: str = "2024-02-01",
8989
azure_endpoint: Optional[str] = None,
90-
model: str = "text-embedding-3-small",
90+
model: Optional[str] = None,
9191
) -> None:
9292
if not api_key:
9393
api_key = os.getenv("AZURE_OPENAI_API_KEY")
9494
if not azure_endpoint:
9595
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
96+
if not model:
97+
model = os.getenv("AZURE_OPENAI_EMBEDDING_MODEL_DEPLOYMENT_NAME")
9698

9799
if not api_key:
98100
raise ValueError("Azure OpenAI API key is required.")
99101
if not azure_endpoint:
100102
raise ValueError("Azure OpenAI endpoint is required.")
103+
if not model:
104+
raise ValueError(
105+
"Azure OpenAI embedding model deployment name is required."
106+
)
101107

102108
self.df = df
103109
self.client = AzureOpenAI(

0 commit comments

Comments
 (0)