mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-08-22 15:15:34 +00:00
Update ChatCompletionChoice with optional finish_reason and finish_details
This commit is contained in:
@ -50,21 +50,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}])
|
||||
.function_call(FunctionCallType::Auto);
|
||||
|
||||
// debug reuqest json
|
||||
// debug request json
|
||||
// let serialized = serde_json::to_string(&req).unwrap();
|
||||
// println!("{}", serialized);
|
||||
|
||||
let result = client.chat_completion(req)?;
|
||||
|
||||
match result.choices[0].finish_reason {
|
||||
chat_completion::FinishReason::stop => {
|
||||
None => {
|
||||
println!("No finish_reason");
|
||||
println!("{:?}", result.choices[0].message.content);
|
||||
}
|
||||
Some(chat_completion::FinishReason::stop) => {
|
||||
println!("Stop");
|
||||
println!("{:?}", result.choices[0].message.content);
|
||||
}
|
||||
chat_completion::FinishReason::length => {
|
||||
Some(chat_completion::FinishReason::length) => {
|
||||
println!("Length");
|
||||
}
|
||||
chat_completion::FinishReason::function_call => {
|
||||
Some(chat_completion::FinishReason::function_call) => {
|
||||
println!("FunctionCall");
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Currency {
|
||||
@ -80,10 +84,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("{} price: {}", coin, price);
|
||||
}
|
||||
}
|
||||
chat_completion::FinishReason::content_filter => {
|
||||
Some(chat_completion::FinishReason::content_filter) => {
|
||||
println!("ContentFilter");
|
||||
}
|
||||
chat_completion::FinishReason::null => {
|
||||
Some(chat_completion::FinishReason::null) => {
|
||||
println!("Null");
|
||||
}
|
||||
}
|
||||
|
@ -52,14 +52,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let result = client.chat_completion(req)?;
|
||||
|
||||
match result.choices[0].finish_reason {
|
||||
chat_completion::FinishReason::stop => {
|
||||
None => {
|
||||
println!("No finish_reason");
|
||||
println!("{:?}", result.choices[0].message.content);
|
||||
}
|
||||
Some(chat_completion::FinishReason::stop) => {
|
||||
println!("Stop");
|
||||
println!("{:?}", result.choices[0].message.content);
|
||||
}
|
||||
chat_completion::FinishReason::length => {
|
||||
Some(chat_completion::FinishReason::length) => {
|
||||
println!("Length");
|
||||
}
|
||||
chat_completion::FinishReason::function_call => {
|
||||
Some(chat_completion::FinishReason::function_call) => {
|
||||
println!("FunctionCall");
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Currency {
|
||||
@ -94,10 +98,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let result = client.chat_completion(req)?;
|
||||
println!("{:?}", result.choices[0].message.content);
|
||||
}
|
||||
chat_completion::FinishReason::content_filter => {
|
||||
Some(chat_completion::FinishReason::content_filter) => {
|
||||
println!("ContentFilter");
|
||||
}
|
||||
chat_completion::FinishReason::null => {
|
||||
Some(chat_completion::FinishReason::null) => {
|
||||
println!("Null");
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,8 @@ pub struct ChatCompletionMessageForResponse {
|
||||
pub struct ChatCompletionChoice {
|
||||
pub index: i64,
|
||||
pub message: ChatCompletionMessageForResponse,
|
||||
pub finish_reason: FinishReason,
|
||||
pub finish_reason: Option<FinishReason>,
|
||||
pub finish_details: Option<FinishDetails>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@ -187,6 +188,13 @@ pub enum FinishReason {
|
||||
null,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct FinishDetails {
|
||||
pub r#type: FinishReason,
|
||||
pub stop: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct FunctionCall {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
Reference in New Issue
Block a user