open_ai: Make OpenAI error message generic (#33383)

Context: In this PR: https://github.com/zed-industries/zed/pull/33362,
we started to use underlying open_ai crate for making api calls for
vercel as well. Now whenever we get the error we get something like the
below. Where on part of the error mentions OpenAI but the rest of the
error returns the actual error from provider. This PR tries to make the
error generic for now so that people don't get confused seeing OpenAI in
their v0 integration.

```
Error interacting with language model
Failed to connect to OpenAI API: 403 Forbidden {"success":false,"error":"Premium or Team plan required to access the v0 API: https://v0.dev/chat/settings/billing"}
```

Release Notes:

- N/A
This commit is contained in:
Umesh Yadav 2025-06-28 18:08:27 +05:30 committed by GitHub
parent 1d684c8890
commit 3f4098e87b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View file

@ -565,7 +565,7 @@ impl LmStudioEventMapper {
events.push(Ok(LanguageModelCompletionEvent::Stop(StopReason::ToolUse)));
}
Some(stop_reason) => {
log::error!("Unexpected OpenAI stop_reason: {stop_reason:?}",);
log::error!("Unexpected LMStudio stop_reason: {stop_reason:?}",);
events.push(Ok(LanguageModelCompletionEvent::Stop(StopReason::EndTurn)));
}
None => {}

View file

@ -445,12 +445,14 @@ pub async fn stream_completion(
match serde_json::from_str::<OpenAiResponse>(&body) {
Ok(response) if !response.error.message.is_empty() => Err(anyhow!(
"Failed to connect to OpenAI API: {}",
"API request to {} failed: {}",
api_url,
response.error.message,
)),
_ => anyhow::bail!(
"Failed to connect to OpenAI API: {} {}",
"API request to {} failed with status {}: {}",
api_url,
response.status(),
body,
),