langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
92.3k stars 14.75k forks source link

tool_choice='required' is now supported by Azure but blocked in langchain #25864

Open meliascosta opened 2 weeks ago

meliascosta commented 2 weeks ago

Checked other resources

Example Code

In line 662 here: https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/chat_models/azure.py#L662

we can see that tool_choice = 'required' is explicitly filtered out

and a note in a comment saying:

As of 05/2024 Azure OpenAI doesn't support tool_choice="required".

    # TODO: Update this condition once tool_choice="required" is supported.

It is now supported in the preview API from July https://learn.microsoft.com/en-us/rest/api/azureopenai/operation-groups?view=rest-azureopenai-2024-07-01-preview&preserve-view=true

Error Message and Stack Trace (if applicable)

ValueError("Azure OpenAI does not currently support tool_choice='required'. Should be one of 'auto', 'none', or the name of the tool to call.")

Description

I would like to use the setting

System Info

System Information

OS: Linux OS Version: #1 SMP Fri Mar 29 23:14:13 UTC 2024 Python Version: 3.12.3 (main, May 23 2024, 22:52:35) [GCC 9.4.0]

Package Information

langchain_core: 0.2.33 langchain: 0.2.14 langchain_community: 0.2.12 langsmith: 0.1.99 langchain_openai: 0.1.22 langchain_postgres: 0.0.6 langchain_text_splitters: 0.2.2 langgraph: 0.0.65 langserve: 0.2.2

Other Dependencies

aiohttp: 3.10.3 async-timeout: Installed. No version info available. dataclasses-json: 0.6.7 fastapi: 0.109.2 httpx: 0.27.0 jsonpatch: 1.33 numpy: 1.26.4 openai: 1.41.0 orjson: 3.10.7 packaging: 24.1 pgvector: 0.2.5 psycopg: 3.2.1 psycopg-pool: 3.2.2 pydantic: 2.8.2 pyproject-toml: 0.0.10 PyYAML: 6.0.2 requests: 2.32.3 sqlalchemy: 2.0.32 SQLAlchemy: 2.0.32 sse-starlette: 1.8.2 tenacity: 8.5.0 tiktoken: 0.7.0 typing-extensions: 4.12.2

prasanjeevi commented 2 weeks ago

I'm also facing the same issue