mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-08-22 15:15:34 +00:00
@ -9,7 +9,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
model: chat_completion::GPT4.to_string(),
|
||||
messages: vec![chat_completion::ChatCompletionMessage {
|
||||
role: chat_completion::MessageRole::user,
|
||||
content: Some(String::from("What is Bitcoin?")),
|
||||
content: String::from("What is Bitcoin?"),
|
||||
name: 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 req = CompletionRequest {
|
||||
model: completion::GPT3_TEXT_DAVINCI_003.to_string(),
|
||||
prompt: Some(String::from("What is Bitcoin?")),
|
||||
prompt: String::from("What is Bitcoin?"),
|
||||
suffix: None,
|
||||
max_tokens: Some(3000),
|
||||
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(),
|
||||
messages: vec![chat_completion::ChatCompletionMessage {
|
||||
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,
|
||||
function_call: None,
|
||||
}],
|
||||
functions: Some(vec![chat_completion::Function {
|
||||
name: String::from("get_coin_price"),
|
||||
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,
|
||||
properties: Some(properties),
|
||||
required: Some(vec![String::from("coin")]),
|
||||
}),
|
||||
},
|
||||
}]),
|
||||
function_call: Some("auto".to_string()),
|
||||
temperature: None,
|
||||
|
@ -34,18 +34,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
model: chat_completion::GPT3_5_TURBO_0613.to_string(),
|
||||
messages: vec![chat_completion::ChatCompletionMessage {
|
||||
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,
|
||||
function_call: None,
|
||||
}],
|
||||
functions: Some(vec![chat_completion::Function {
|
||||
name: String::from("get_coin_price"),
|
||||
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,
|
||||
properties: Some(properties),
|
||||
required: Some(vec![String::from("coin")]),
|
||||
}),
|
||||
},
|
||||
}]),
|
||||
function_call: None,
|
||||
temperature: None,
|
||||
@ -86,16 +86,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
messages: vec![
|
||||
chat_completion::ChatCompletionMessage {
|
||||
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,
|
||||
function_call: None,
|
||||
},
|
||||
chat_completion::ChatCompletionMessage {
|
||||
role: chat_completion::MessageRole::function,
|
||||
content: Some({
|
||||
content: {
|
||||
let price = get_coin_price(&coin).await;
|
||||
format!("{{\"price\": {}}}", price)
|
||||
}),
|
||||
},
|
||||
name: Some(String::from("get_coin_price")),
|
||||
function_call: None,
|
||||
},
|
||||
|
@ -4,8 +4,8 @@ pub const WHISPER_1: &str = "whisper-1";
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct AudioTranscriptionRequest {
|
||||
pub model: String,
|
||||
pub file: String,
|
||||
pub model: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prompt: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -23,8 +23,8 @@ pub struct AudioTranscriptionResponse {
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct AudioTranslationRequest {
|
||||
pub model: String,
|
||||
pub file: String,
|
||||
pub model: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prompt: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
@ -43,7 +43,7 @@ pub struct ChatCompletionRequest {
|
||||
pub user: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum MessageRole {
|
||||
user,
|
||||
@ -52,8 +52,18 @@ pub enum MessageRole {
|
||||
function,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ChatCompletionMessage {
|
||||
pub role: MessageRole,
|
||||
pub content: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub function_call: Option<FunctionCall>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ChatCompletionMessageForResponse {
|
||||
pub role: MessageRole,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub content: Option<String>,
|
||||
@ -66,7 +76,7 @@ pub struct ChatCompletionMessage {
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionChoice {
|
||||
pub index: i64,
|
||||
pub message: ChatCompletionMessage,
|
||||
pub message: ChatCompletionMessageForResponse,
|
||||
pub finish_reason: FinishReason,
|
||||
}
|
||||
|
||||
@ -85,8 +95,7 @@ pub struct Function {
|
||||
pub name: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parameters: Option<FunctionParameters>,
|
||||
pub parameters: FunctionParameters,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -136,7 +145,7 @@ pub enum FinishReason {
|
||||
null,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct FunctionCall {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
|
@ -20,8 +20,7 @@ pub const GPT3_BABBAGE: &str = "babbage";
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct CompletionRequest {
|
||||
pub model: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prompt: Option<String>,
|
||||
pub prompt: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub suffix: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
@ -3,6 +3,8 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct CreateModerationRequest {
|
||||
pub input: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub model: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
Reference in New Issue
Block a user