Add shortcuts for commonly used functions

This commit is contained in:
2024-11-27 15:57:18 +00:00
parent db5a01afef
commit 56d6b95c53
5 changed files with 20 additions and 24 deletions

View File

@@ -18,17 +18,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let system_instruction = "Answer as if you were Yoda";
let prompt = "What is the airspeed of an unladen swallow?";
let request = GenerateContentRequest {
contents: vec![Content {
role: Some(Role::User),
parts: Some(vec![Part::Text(prompt.to_string())]),
}],
system_instruction: Some(Content {
role: None,
parts: Some(vec![Part::Text(system_instruction.to_string())]),
}),
..Default::default()
};
let request = GenerateContentRequest::builder()
.add_text_content(Role::User, prompt)
.system_instruction_text(system_instruction)
.build();
let result = gemini
.generate_content(&request, "gemini-1.0-pro-002")

View File

@@ -16,12 +16,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let prompt = "Tell me the story of the genesis of the universe as a bedtime story.";
let request = GenerateContentRequest::builder()
.add_content(
Content::builder()
.role(Role::User)
.add_part(Part::Text(prompt.to_string()))
.build(),
)
.add_text_content(Role::User, prompt)
.build();
let queue = gemini.stream_generate_content(&request, "gemini-pro").await;

View File

@@ -16,12 +16,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let prompt = "What is the airspeed of an unladen swallow?";
let request = GenerateContentRequest::builder()
.add_content(
Content::builder()
.role(Role::User)
.add_part(Part::Text(prompt.to_string()))
.build(),
)
.add_text_content(Role::User, prompt)
.build();
let response = gemini.generate_content(&request, "gemini-pro").await?;
println!("Response: {:?}", response.candidates[0].get_text().unwrap());