Using Azure OpenAI keys instead of OpenAI keys
Hi, Great work. I wanted to test out the simulation, for an academic project. I built the docker image. I exported my Azure OpenAI keys instead of OpenAI.
I get the following error:
********************************************************************************
* LLMSim initialized
********************************************************************************
>>> agent.plan_with_functions("Move the red glass to Felix")
ERROR:root:❌ OpenAI error, retrying (Error code: 401 - {'error': {'message': 'Incorrect API key provided: 9abd3af7********************13e4. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}})
ERROR:root:❌ OpenAI error, retrying (Error code: 401 - {'error': {'message': 'Incorrect API key provided: 9abd3af7********************13e4. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}})
ERROR:root:❌ OpenAI error, retrying (Error code: 401 - {'error': {'message': 'Incorrect API key provided: 9abd3af7********************13e4. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/attentive_support/src/tool_agent.py", line 151, in plan_with_functions
response = self._query_llm(self.messages)
File "/attentive_support/src/tool_agent.py", line 146, in _query_llm
raise Exception(f"❌ {retries} OpenAI errors, aborting.")
Exception: ❌ 3 OpenAI errors, aborting.
I assume the Azure OpenAI didn't work here. Can you guide me what changes should I do in the source to make this work with those keys? Thanks.
hi,
right now, the system expects an actual openai api key. you can switch to azure using the AzureOpenAI client, though, see the official instructions
for this, you have to replace the client, here line 102 in tool_agent.py, with the following:
self.openai_client = openai.AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version="your-version",
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT")
)
when using docker, make sure to pass the respective env variables AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT.
let us know if this works for you
hi @harshal-14. as this issue has been inactive for a while since my reply, i will close it for now. feel free to reopen if needed. thanks!