enum variant matching for oai
This commit is contained in:
@@ -71,9 +71,26 @@ pub struct Choice {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum ResponseEvent {
|
||||
ChatCompletionResponse(ChatCompletionResponse),
|
||||
ResponseError(ResponseError),
|
||||
// ChatCompletionResponse {
|
||||
// id: String,
|
||||
// object: String,
|
||||
// system_fingerprint: Option<String>,
|
||||
// created: i64,
|
||||
// model: String,
|
||||
// usage: Usage,
|
||||
// choices: Vec<Choice>,
|
||||
// },
|
||||
// ResponseError {
|
||||
// error: Option<ErrorDetails>,
|
||||
// message: Option<String>,
|
||||
// param: Option<String>,
|
||||
// #[serde(rename = "type")]
|
||||
// error_type: Option<String>,
|
||||
// },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -119,13 +136,18 @@ impl OAI {
|
||||
match response {
|
||||
Ok(response) => {
|
||||
let value = response.json::<Value>().await?;
|
||||
// let event: ResponseEvent = serde_json::from_value::<ResponseEvent>(value)?;
|
||||
// match event {
|
||||
// ResponseEvent::ChatCompletionResponse(response) => return Ok(response),
|
||||
// ResponseEvent::ResponseError(error) => return Err(ServiceError { status: 500, message: format!("Error: {}", error.message.unwrap()) })
|
||||
// }
|
||||
let res = serde_json::from_value::<ChatCompletionResponse>(value)?;
|
||||
return Ok(res);
|
||||
let event: ResponseEvent = serde_json::from_value::<ResponseEvent>(value)?;
|
||||
match event {
|
||||
ResponseEvent::ChatCompletionResponse(response) => {
|
||||
return Ok(response);
|
||||
},
|
||||
ResponseEvent::ResponseError(error) => {
|
||||
return Err(ServiceError {
|
||||
status: 500,
|
||||
message: format!("Error: {}", error.message.unwrap()),
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
return Err(ServiceError {
|
||||
|
||||
Reference in New Issue
Block a user