langchain-ai / langchain

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

AzureMLChatOnlineEndpoint - outdated endpoint_url validation #25702

Closed psaks closed 1 week ago

psaks commented 2 weeks ago

Checked other resources

Example Code

The following code:

chat = AzureMLChatOnlineEndpoint(
    endpoint_url="https://Mistral-large-2407-rag.swedencentral.models.ai.azure.com/chat/completions",
    endpoint_api_type=AzureMLEndpointApiType.serverless,
    endpoint_api_key="xxxxxxxxxxxxxxx"
)

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):

File ~/opt/miniconda3/envs/envml/lib/python3.11/site-packages/spyder_kernels/py3compat.py:356 in compat_exec exec(code, globals, locals)

File ~/Programming/temp/test_mistral_2407.py:26 chat = AzureMLChatOnlineEndpoint(

File ~/opt/miniconda3/envs/envml/lib/python3.11/site-packages/langchain_core/load/serializable.py:113 in init super().init(*args, **kwargs)

File pydantic/main.py:341 in pydantic.main.BaseModel.init

ValidationError: 1 validation error for AzureMLChatOnlineEndpoint endpoint_api_type Endpoints of type serverless should follow the format https://<your-endpoint>.<your_region>.inference.ml.azure.com/v1/chat/completions or https://<your-endpoint>.<your_region>.inference.ml.azure.com/v1/chat/completions (type=value_error)

Description

Azure have updated their endpoint urls to exclude v1 from /v1/chat/completions.

The broken code is in (ln 457);

https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/llms/azureml_endpoint.py

        if field_value == AzureMLEndpointApiType.serverless and not (
            endpoint_url.endswith("/v1/completions")  # type: ignore[union-attr]
            or endpoint_url.endswith("/v1/chat/completions")  # type: ignore[union-attr]
        ):

Easy to fix by removing v1.

System Info

langchain==0.2.14 langchain-aws==0.1.6 langchain-community==0.2.12 langchain-core==0.2.34 langchain-openai==0.1.8 langchain-text-splitters==0.2.1

Python 3.11.4

ashvin-a commented 2 weeks ago

I have addressed this issue in #25725