enum variant matching for oai
This commit is contained in:
@@ -68,9 +68,8 @@ The following packages must be installed for [serenity-rs/songbird](https://gith
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Running Locally
|
### Running Locally
|
||||||
1. Build the [Docker](https://www.docker.com/) containers with `make build`
|
1. Start the backend containers with `make refresh`
|
||||||
2. Start the utility containers with `make utils`
|
2. Start the application with `make run`
|
||||||
3. Start the application with `cargo run`
|
|
||||||
|
|
||||||
The application can also be tested from within a Docker container:
|
The application can also be tested from within a Docker container:
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -24,4 +24,4 @@ DATA_DIR_PATH= # OPTIONAL
|
|||||||
|
|
||||||
DISCORD_TOKEN= # OPTIONAL
|
DISCORD_TOKEN= # OPTIONAL
|
||||||
OPENAI_API_KEY= # OPTIONAL
|
OPENAI_API_KEY= # OPTIONAL
|
||||||
OPENAI_API_MODEL=gpt-3.5-turbo-0125
|
OPENAI_API_MODEL=gpt-3.5-turbo
|
||||||
|
|||||||
@@ -71,9 +71,26 @@ pub struct Choice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
enum ResponseEvent {
|
enum ResponseEvent {
|
||||||
ChatCompletionResponse(ChatCompletionResponse),
|
ChatCompletionResponse(ChatCompletionResponse),
|
||||||
ResponseError(ResponseError),
|
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)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -119,13 +136,18 @@ impl OAI {
|
|||||||
match response {
|
match response {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let value = response.json::<Value>().await?;
|
let value = response.json::<Value>().await?;
|
||||||
// let event: ResponseEvent = serde_json::from_value::<ResponseEvent>(value)?;
|
let event: ResponseEvent = serde_json::from_value::<ResponseEvent>(value)?;
|
||||||
// match event {
|
match event {
|
||||||
// ResponseEvent::ChatCompletionResponse(response) => return Ok(response),
|
ResponseEvent::ChatCompletionResponse(response) => {
|
||||||
// ResponseEvent::ResponseError(error) => return Err(ServiceError { status: 500, message: format!("Error: {}", error.message.unwrap()) })
|
return Ok(response);
|
||||||
// }
|
},
|
||||||
let res = serde_json::from_value::<ChatCompletionResponse>(value)?;
|
ResponseEvent::ResponseError(error) => {
|
||||||
return Ok(res);
|
return Err(ServiceError {
|
||||||
|
status: 500,
|
||||||
|
message: format!("Error: {}", error.message.unwrap()),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Err(ServiceError {
|
return Err(ServiceError {
|
||||||
|
|||||||
Reference in New Issue
Block a user