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"}}
```
This commit is contained in:
mschoenb97IL 2024-08-22 13:10:51 -04:00 committed by GitHub
parent 29c873dd69
commit e499caa9cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: