-
Notifications
You must be signed in to change notification settings - Fork 710
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
agents.exceptions.UserError: Hosted tools are not supported with the ChatCompletions API. FGot tool type: <class 'agents.tool.WebSearchTool'>, tool: WebSearchTool(user_location={'type': 'approximate', 'city': '西安'}, search_context_size='medium') #194
Comments
Hi, to use web search with the ChatCompletions API, you should adopt the specific model. import asyncio
from agents import OpenAIChatCompletionsModel, AsyncOpenAI, Agent, Runner
async def main():
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant.",
model=OpenAIChatCompletionsModel(
model="gpt-4o-search-preview-2025-03-11",
openai_client=AsyncOpenAI()
)
)
result = await Runner.run(agent, "What is the news in the world today?")
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main()) or directly with the from openai import OpenAI
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-4o-search-preview",
web_search_options={},
messages=[
{
"role": "user",
"content": "What was a positive news story from today?",
}
],
)
print(completion.choices[0].message.content) |
from agents import set_default_openai_api set_default_openai_api("chat_completions") it will be use ChatCompletions API |
Thank you @DanieleMorotti and @hovofn! More info here as well: https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat |
my code : import asyncio client = AsyncOpenAI(api_key="fxxxxx",base_url="https://api.360.cn/v1") async def main():
if name == "main": it looks like right ,but error always Hosted tools are not supported with the ChatCompletions API. FGot tool type: <class 'agents.tool.WebSearchTool'> why.... |
Yes, you can't use |
Question
inner tools used error :
agents.exceptions.UserError: Hosted tools are not supported with the ChatCompletions API. FGot tool type: <class 'agents.tool.WebSearchTool'>, tool: WebSearchTool(user_location={'type': 'approximate', 'city': '西安'}, search_context_size='medium')
it seems ChatCompletions API compared Response API is incompatible,how to resolve this matter? thx
The text was updated successfully, but these errors were encountered: