More builder refactoring

This commit is contained in:
2024-11-27 16:20:53 +00:00
parent 56d6b95c53
commit fd1223da59
4 changed files with 25 additions and 24 deletions

View File

@@ -15,12 +15,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
location_id,
);
let system_instruction = "Answer as if you were Yoda";
let prompt = "What is the airspeed of an unladen swallow?";
let system_instruction = Content::builder()
.add_text_part("Answer as if you were Yoda")
.build();
let user_prompt = vec![Content::builder()
.role(Role::User)
.add_text_part("What is the airspeed of an unladen swallow?")
.build()];
let request = GenerateContentRequest::builder()
.add_text_content(Role::User, prompt)
.system_instruction_text(system_instruction)
.contents(user_prompt)
.system_instruction(system_instruction)
.build();
let result = gemini

View File

@@ -14,10 +14,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
location_id,
);
let prompt = "Tell me the story of the genesis of the universe as a bedtime story.";
let request = GenerateContentRequest::builder()
.add_text_content(Role::User, prompt)
.build();
let prompt = vec![Content::builder()
.role(Role::User)
.add_text_part("Tell me the story of the genesis of the universe as a bedtime story.")
.build()];
let request = GenerateContentRequest::builder().contents(prompt).build();
let queue = gemini.stream_generate_content(&request, "gemini-pro").await;

View File

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