mirror of
https://github.com/SilasMarvin/lsp-ai.git
synced 2024-09-11 12:25:48 +03:00
Improve error responses from apis
This commit is contained in:
parent
cbaed9a0c4
commit
b4ed5b8c96
@ -1,3 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Context;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
@ -52,6 +54,9 @@ struct AnthropicChatMessage {
|
||||
struct AnthropicChatResponse {
|
||||
content: Option<Vec<AnthropicChatMessage>>,
|
||||
error: Option<Value>,
|
||||
#[serde(default)]
|
||||
#[serde(flatten)]
|
||||
pub other: HashMap<String, Value>,
|
||||
}
|
||||
|
||||
impl Anthropic {
|
||||
@ -103,7 +108,10 @@ impl Anthropic {
|
||||
} else if let Some(mut content) = res.content {
|
||||
Ok(std::mem::take(&mut content[0].text))
|
||||
} else {
|
||||
anyhow::bail!("Uknown error while making request to OpenAI")
|
||||
anyhow::bail!(
|
||||
"Uknown error while making request to Anthropic: {:?}",
|
||||
res.other
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,10 @@ impl MistralFIM {
|
||||
} else if let Some(choices) = res.choices {
|
||||
Ok(choices[0].message.content.clone())
|
||||
} else {
|
||||
anyhow::bail!("Unknown error while making request to OpenAI")
|
||||
anyhow::bail!(
|
||||
"Unknown error while making request to MistralFIM: {:?}",
|
||||
res.other
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Context;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
@ -64,6 +66,9 @@ struct OpenAICompletionsChoice {
|
||||
struct OpenAICompletionsResponse {
|
||||
choices: Option<Vec<OpenAICompletionsChoice>>,
|
||||
error: Option<Value>,
|
||||
#[serde(default)]
|
||||
#[serde(flatten)]
|
||||
pub other: HashMap<String, Value>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@ -75,6 +80,9 @@ pub struct OpenAIChatChoices {
|
||||
pub struct OpenAIChatResponse {
|
||||
pub choices: Option<Vec<OpenAIChatChoices>>,
|
||||
pub error: Option<Value>,
|
||||
#[serde(default)]
|
||||
#[serde(flatten)]
|
||||
pub other: HashMap<String, Value>,
|
||||
}
|
||||
|
||||
impl OpenAI {
|
||||
@ -130,7 +138,10 @@ impl OpenAI {
|
||||
} else if let Some(mut choices) = res.choices {
|
||||
Ok(std::mem::take(&mut choices[0].text))
|
||||
} else {
|
||||
anyhow::bail!("Uknown error while making request to OpenAI")
|
||||
anyhow::bail!(
|
||||
"Uknown error while making request to OpenAI: {:?}",
|
||||
res.other
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,7 +181,10 @@ impl OpenAI {
|
||||
} else if let Some(choices) = res.choices {
|
||||
Ok(choices[0].message.content.clone())
|
||||
} else {
|
||||
anyhow::bail!("Unknown error while making request to OpenAI")
|
||||
anyhow::bail!(
|
||||
"Unknown error while making request to OpenAI: {:?}",
|
||||
res.other
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user