mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-08-23 15:48:07 +00:00
Remove Option
This commit is contained in:
@ -9,7 +9,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
model: chat_completion::GPT4.to_string(),
|
model: chat_completion::GPT4.to_string(),
|
||||||
messages: vec![chat_completion::ChatCompletionMessage {
|
messages: vec![chat_completion::ChatCompletionMessage {
|
||||||
role: chat_completion::MessageRole::user,
|
role: chat_completion::MessageRole::user,
|
||||||
content: Some(String::from("What is Bitcoin?")),
|
content: String::from("What is Bitcoin?"),
|
||||||
name: None,
|
name: None,
|
||||||
function_call: None,
|
function_call: None,
|
||||||
}],
|
}],
|
||||||
|
@ -7,7 +7,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());
|
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());
|
||||||
let req = CompletionRequest {
|
let req = CompletionRequest {
|
||||||
model: completion::GPT3_TEXT_DAVINCI_003.to_string(),
|
model: completion::GPT3_TEXT_DAVINCI_003.to_string(),
|
||||||
prompt: Some(String::from("What is Bitcoin?")),
|
prompt: String::from("What is Bitcoin?"),
|
||||||
suffix: None,
|
suffix: None,
|
||||||
max_tokens: Some(3000),
|
max_tokens: Some(3000),
|
||||||
temperature: Some(0.9),
|
temperature: Some(0.9),
|
||||||
|
@ -34,18 +34,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
model: chat_completion::GPT3_5_TURBO_0613.to_string(),
|
model: chat_completion::GPT3_5_TURBO_0613.to_string(),
|
||||||
messages: vec![chat_completion::ChatCompletionMessage {
|
messages: vec![chat_completion::ChatCompletionMessage {
|
||||||
role: chat_completion::MessageRole::user,
|
role: chat_completion::MessageRole::user,
|
||||||
content: Some(String::from("What is the price of Ethereum?")),
|
content: String::from("What is the price of Ethereum?"),
|
||||||
name: None,
|
name: None,
|
||||||
function_call: None,
|
function_call: None,
|
||||||
}],
|
}],
|
||||||
functions: Some(vec![chat_completion::Function {
|
functions: Some(vec![chat_completion::Function {
|
||||||
name: String::from("get_coin_price"),
|
name: String::from("get_coin_price"),
|
||||||
description: Some(String::from("Get the price of a cryptocurrency")),
|
description: Some(String::from("Get the price of a cryptocurrency")),
|
||||||
parameters: Some(chat_completion::FunctionParameters {
|
parameters: chat_completion::FunctionParameters {
|
||||||
schema_type: chat_completion::JSONSchemaType::Object,
|
schema_type: chat_completion::JSONSchemaType::Object,
|
||||||
properties: Some(properties),
|
properties: Some(properties),
|
||||||
required: Some(vec![String::from("coin")]),
|
required: Some(vec![String::from("coin")]),
|
||||||
}),
|
},
|
||||||
}]),
|
}]),
|
||||||
function_call: Some("auto".to_string()),
|
function_call: Some("auto".to_string()),
|
||||||
temperature: None,
|
temperature: None,
|
||||||
|
@ -34,18 +34,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
model: chat_completion::GPT3_5_TURBO_0613.to_string(),
|
model: chat_completion::GPT3_5_TURBO_0613.to_string(),
|
||||||
messages: vec![chat_completion::ChatCompletionMessage {
|
messages: vec![chat_completion::ChatCompletionMessage {
|
||||||
role: chat_completion::MessageRole::user,
|
role: chat_completion::MessageRole::user,
|
||||||
content: Some(String::from("What is the price of Ethereum?")),
|
content: String::from("What is the price of Ethereum?"),
|
||||||
name: None,
|
name: None,
|
||||||
function_call: None,
|
function_call: None,
|
||||||
}],
|
}],
|
||||||
functions: Some(vec![chat_completion::Function {
|
functions: Some(vec![chat_completion::Function {
|
||||||
name: String::from("get_coin_price"),
|
name: String::from("get_coin_price"),
|
||||||
description: Some(String::from("Get the price of a cryptocurrency")),
|
description: Some(String::from("Get the price of a cryptocurrency")),
|
||||||
parameters: Some(chat_completion::FunctionParameters {
|
parameters: chat_completion::FunctionParameters {
|
||||||
schema_type: chat_completion::JSONSchemaType::Object,
|
schema_type: chat_completion::JSONSchemaType::Object,
|
||||||
properties: Some(properties),
|
properties: Some(properties),
|
||||||
required: Some(vec![String::from("coin")]),
|
required: Some(vec![String::from("coin")]),
|
||||||
}),
|
},
|
||||||
}]),
|
}]),
|
||||||
function_call: None,
|
function_call: None,
|
||||||
temperature: None,
|
temperature: None,
|
||||||
@ -86,13 +86,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
messages: vec![
|
messages: vec![
|
||||||
chat_completion::ChatCompletionMessage {
|
chat_completion::ChatCompletionMessage {
|
||||||
role: chat_completion::MessageRole::user,
|
role: chat_completion::MessageRole::user,
|
||||||
content: Some(String::from("What is the price of Ethereum?")),
|
content: String::from("What is the price of Ethereum?"),
|
||||||
name: None,
|
name: None,
|
||||||
function_call: None,
|
function_call: None,
|
||||||
},
|
},
|
||||||
chat_completion::ChatCompletionMessage {
|
chat_completion::ChatCompletionMessage {
|
||||||
role: chat_completion::MessageRole::function,
|
role: chat_completion::MessageRole::function,
|
||||||
content: Some({
|
content: ({
|
||||||
let price = get_coin_price(&coin).await;
|
let price = get_coin_price(&coin).await;
|
||||||
format!("{{\"price\": {}}}", price)
|
format!("{{\"price\": {}}}", price)
|
||||||
}),
|
}),
|
||||||
|
@ -4,8 +4,8 @@ pub const WHISPER_1: &str = "whisper-1";
|
|||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct AudioTranscriptionRequest {
|
pub struct AudioTranscriptionRequest {
|
||||||
pub model: String,
|
|
||||||
pub file: String,
|
pub file: String,
|
||||||
|
pub model: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub prompt: Option<String>,
|
pub prompt: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@ -23,8 +23,8 @@ pub struct AudioTranscriptionResponse {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct AudioTranslationRequest {
|
pub struct AudioTranslationRequest {
|
||||||
pub model: String,
|
|
||||||
pub file: String,
|
pub file: String,
|
||||||
|
pub model: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub prompt: Option<String>,
|
pub prompt: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
@ -43,7 +43,7 @@ pub struct ChatCompletionRequest {
|
|||||||
pub user: Option<String>,
|
pub user: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
pub enum MessageRole {
|
pub enum MessageRole {
|
||||||
user,
|
user,
|
||||||
@ -52,11 +52,10 @@ pub enum MessageRole {
|
|||||||
function,
|
function,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ChatCompletionMessage {
|
pub struct ChatCompletionMessage {
|
||||||
pub role: MessageRole,
|
pub role: MessageRole,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
pub content: String,
|
||||||
pub content: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@ -85,8 +84,7 @@ pub struct Function {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
pub parameters: FunctionParameters,
|
||||||
pub parameters: Option<FunctionParameters>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@ -136,7 +134,7 @@ pub enum FinishReason {
|
|||||||
null,
|
null,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct FunctionCall {
|
pub struct FunctionCall {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
@ -20,8 +20,7 @@ pub const GPT3_BABBAGE: &str = "babbage";
|
|||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct CompletionRequest {
|
pub struct CompletionRequest {
|
||||||
pub model: String,
|
pub model: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
pub prompt: String,
|
||||||
pub prompt: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub suffix: Option<String>,
|
pub suffix: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
@ -3,6 +3,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct CreateModerationRequest {
|
pub struct CreateModerationRequest {
|
||||||
pub input: String,
|
pub input: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub model: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
Reference in New Issue
Block a user