From e499caa9cd3f44d9ff843159eb18402bcd7b7c34 Mon Sep 17 00:00:00 2001 From: mschoenb97IL Date: Thu, 22 Aug 2024 13:10:51 -0400 Subject: [PATCH] community: Give more context on DeepInfra 500 errors (#25671) Description: DeepInfra 500 errors have useful information in the text field that isn't being exposed to the user. I updated the error message to fix this. As an example, this code ``` from langchain_community.chat_models import ChatDeepInfra from langchain_core.messages import HumanMessage model = "meta-llama/Meta-Llama-3-70B-Instruct" deepinfra_api_token = "..." model = ChatDeepInfra(model=model, deepinfra_api_token=deepinfra_api_token) messages = [HumanMessage("All work and no play makes Jack a dull boy\n" * 9000)] response = model.invoke(messages) ``` Currently gives this error: ``` langchain_community.chat_models.deepinfra.ChatDeepInfraException: DeepInfra Server: Error 500 ``` This change would give the following error: ``` langchain_community.chat_models.deepinfra.ChatDeepInfraException: DeepInfra Server error status 500: {"error":{"message":"Requested input length 99009 exceeds maximum input length 8192"}} ``` --- libs/community/langchain_community/chat_models/deepinfra.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/chat_models/deepinfra.py b/libs/community/langchain_community/chat_models/deepinfra.py index 41da4adc9d8..ee670248a67 100644 --- a/libs/community/langchain_community/chat_models/deepinfra.py +++ b/libs/community/langchain_community/chat_models/deepinfra.py @@ -449,7 +449,9 @@ class ChatDeepInfra(BaseChatModel): def _handle_status(self, code: int, text: Any) -> None: if code >= 500: - raise ChatDeepInfraException(f"DeepInfra Server: Error {code}") + raise ChatDeepInfraException( + f"DeepInfra Server error status {code}: {text}" + ) elif code >= 400: raise ValueError(f"DeepInfra received an invalid payload: {text}") elif code != 200: