mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-08-22 23:25:39 +00:00
feat: add chain method to create Request instance
This commit is contained in:
@ -29,35 +29,24 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}),
|
||||
);
|
||||
|
||||
let req = ChatCompletionRequest {
|
||||
model: chat_completion::GPT3_5_TURBO_0613.to_string(),
|
||||
messages: vec![chat_completion::ChatCompletionMessage {
|
||||
let req = ChatCompletionRequest::new(
|
||||
chat_completion::GPT3_5_TURBO_0613.to_string(),
|
||||
vec![chat_completion::ChatCompletionMessage {
|
||||
role: chat_completion::MessageRole::user,
|
||||
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: chat_completion::FunctionParameters {
|
||||
schema_type: chat_completion::JSONSchemaType::Object,
|
||||
properties: Some(properties),
|
||||
required: Some(vec![String::from("coin")]),
|
||||
},
|
||||
}]),
|
||||
function_call: None,
|
||||
temperature: None,
|
||||
top_p: None,
|
||||
n: None,
|
||||
stream: None,
|
||||
stop: None,
|
||||
max_tokens: None,
|
||||
presence_penalty: None,
|
||||
frequency_penalty: None,
|
||||
logit_bias: None,
|
||||
user: None,
|
||||
};
|
||||
)
|
||||
.functions(vec![chat_completion::Function {
|
||||
name: String::from("get_coin_price"),
|
||||
description: Some(String::from("Get the price of a cryptocurrency")),
|
||||
parameters: chat_completion::FunctionParameters {
|
||||
schema_type: chat_completion::JSONSchemaType::Object,
|
||||
properties: Some(properties),
|
||||
required: Some(vec![String::from("coin")]),
|
||||
},
|
||||
}]);
|
||||
|
||||
let result = client.chat_completion(req)?;
|
||||
|
||||
@ -80,9 +69,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let c: Currency = serde_json::from_str(&arguments)?;
|
||||
let coin = c.coin;
|
||||
|
||||
let req = ChatCompletionRequest {
|
||||
model: chat_completion::GPT3_5_TURBO_0613.to_string(),
|
||||
messages: vec![
|
||||
let req = ChatCompletionRequest::new(
|
||||
chat_completion::GPT3_5_TURBO_0613.to_string(),
|
||||
vec![
|
||||
chat_completion::ChatCompletionMessage {
|
||||
role: chat_completion::MessageRole::user,
|
||||
content: String::from("What is the price of Ethereum?"),
|
||||
@ -99,19 +88,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
function_call: None,
|
||||
},
|
||||
],
|
||||
functions: None,
|
||||
function_call: None,
|
||||
temperature: None,
|
||||
top_p: None,
|
||||
n: None,
|
||||
stream: None,
|
||||
stop: None,
|
||||
max_tokens: None,
|
||||
presence_penalty: None,
|
||||
frequency_penalty: None,
|
||||
logit_bias: None,
|
||||
user: None,
|
||||
};
|
||||
);
|
||||
|
||||
let result = client.chat_completion(req)?;
|
||||
println!("{:?}", result.choices[0].message.content);
|
||||
}
|
||||
|
Reference in New Issue
Block a user