-
Notifications
You must be signed in to change notification settings - Fork 1.5k
How can I use the azure openai api? #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There are some ways described in https://openai.github.io/openai-agents-python/models/#using-other-llm-providers The easiest way is probably this:
|
Feel free to reopen if needed. |
This works for me: # For running on jupyter notebook
# import nest_asyncio
# nest_asyncio.apply()
from openai import AsyncOpenAI,AsyncAzureOpenAI,AzureOpenAI
from agents import OpenAIChatCompletionsModel,Agent,Runner
from agents.model_settings import ModelSettings
from agents import set_default_openai_client, set_tracing_disabled
openai_client = AsyncAzureOpenAI(
api_key=OPENAI_API_KEY,
api_version="2024-06-01",
azure_endpoint="https://xxxx.openai.azure.com",
azure_deployment="gpt-4o-mini"
)
# chat_completion = await openai_client.chat.completions.create(messages=[dict(role="user",content="Hello")],
# model='gpt-4o-mini')
# print(chat_completion)
set_default_openai_client(openai_client)
set_tracing_disabled(True)
agent = Agent(
name="Chinese agent",
instructions="You only speak Chinese.",
model=OpenAIChatCompletionsModel(
model="gpt-4o-mini",
openai_client=openai_client,
),
model_settings=ModelSettings(temperature=0.5),
)
result = Runner.run_sync(agent, "Write a haiku about recursion in programming.") |
I got an error when I used this method to provide LLM services,Not only qwen, but also deepseek and other services have the same error
|
@LeonG7 我遇到过这样的问题,当使用external_client = AsyncOpenAI()时,你必须在终端导入环境变量:export OPENAI_API_KEY=""。OPENAI_API_KEY可以为空,可以为任何东西,但你必须导入它。 |
No description provided.
The text was updated successfully, but these errors were encountered: