You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was getting the error as: openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
when i try calling the azure openai on the autogen.
autogen-agentchat 0.6.2
autogen-core 0.6.2
autogen-ext 0.6.2
sample code:
import os
import asyncio
from dotenv import load_dotenv
from autogen_agentchat.agents import AssistantAgent, UserProxyAgent
from autogen_core.tools import FunctionTool
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.messages import TextMessage
print("🔐 Using API:", api_key)
print("🌐 Base URL:", api_base)
print("🧠 Deployment:", deployment)
print("📅 API version:", api_version)
✅ Correct Azure-compatible model client
model_client = OpenAIChatCompletionClient(
model=deployment, # Logical model name (same as deployment)
api_key=api_key,
base_url=api_base,
api_version=api_version,
api_type="azure",
deployment_name=deployment # 🔥 CRITICAL for Azure deployments
)
✅ Tool function
async def multiply(a: int, b: int) -> int:
"""Multiply two integers."""
return a * b
tool = FunctionTool(multiply, description="Multiplies two integers")
✅ Agent setup
assistant = AssistantAgent(
name="assistant",
model_client=model_client,
tools=[tool],
system_message="You are a helpful assistant that uses tools to solve math problems."
)
user = UserProxyAgent(name="user")
✅ Message loop
async def main():
print("💬 Sending message to assistant...")
async for event in assistant.on_messages_stream(
messages=[TextMessage(content="Multiply 8 and 5", source=user.name)],
cancellation_token=None
):
print(f"\n🧠 [{event.class.name}]:\n{event.content}")
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I was getting the error as: openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
when i try calling the azure openai on the autogen.
autogen-agentchat 0.6.2
autogen-core 0.6.2
autogen-ext 0.6.2
sample code:
import os
import asyncio
from dotenv import load_dotenv
from autogen_agentchat.agents import AssistantAgent, UserProxyAgent
from autogen_core.tools import FunctionTool
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.messages import TextMessage
Load API keys and configs
load_dotenv()
Azure OpenAI configuration
api_key = os.getenv("AZURE_OPENAI_API_KEY")
deployment = os.getenv("AZURE_OPENAI_DEPLOYMENT")
api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
api_version = os.getenv("AZURE_OPENAI_API_VERSION")
print("🔐 Using API:", api_key)
print("🌐 Base URL:", api_base)
print("🧠 Deployment:", deployment)
print("📅 API version:", api_version)
✅ Correct Azure-compatible model client
model_client = OpenAIChatCompletionClient(
model=deployment, # Logical model name (same as deployment)
api_key=api_key,
base_url=api_base,
api_version=api_version,
api_type="azure",
deployment_name=deployment # 🔥 CRITICAL for Azure deployments
)
✅ Tool function
async def multiply(a: int, b: int) -> int:
"""Multiply two integers."""
return a * b
tool = FunctionTool(multiply, description="Multiplies two integers")
✅ Agent setup
assistant = AssistantAgent(
name="assistant",
model_client=model_client,
tools=[tool],
system_message="You are a helpful assistant that uses tools to solve math problems."
)
user = UserProxyAgent(name="user")
✅ Message loop
async def main():
print("💬 Sending message to assistant...")
async for event in assistant.on_messages_stream(
messages=[TextMessage(content="Multiply 8 and 5", source=user.name)],
cancellation_token=None
):
print(f"\n🧠 [{event.class.name}]:\n{event.content}")
✅ Run
if name == "main":
asyncio.run(main())
Beta Was this translation helpful? Give feedback.
All reactions