Add builders for GenerateContent and CountToken
This commit is contained in:
@@ -15,12 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
);
|
||||
|
||||
let prompt = "What is the airspeed of an unladen swallow?";
|
||||
let request = CountTokensRequest {
|
||||
contents: Content {
|
||||
role: Some("user".to_string()),
|
||||
parts: Some(vec![Part::Text(prompt.to_string())]),
|
||||
},
|
||||
};
|
||||
let request = CountTokensRequestBuilder::from_prompt(prompt).build();
|
||||
let result = gemini.count_tokens(&request, "gemini-pro").await?;
|
||||
println!("Response: {:?}", result);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let request = GenerateContentRequest {
|
||||
contents: vec![Content {
|
||||
role: Some("user".to_string()),
|
||||
role: Some(Role::User),
|
||||
parts: Some(vec![Part::Text(prompt.to_string())]),
|
||||
}],
|
||||
tools: Some(vec![Tools {
|
||||
|
||||
@@ -18,7 +18,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let prompt = "Generate 10 ideas of blog posts with a title and decription for each idea.";
|
||||
let request = GenerateContentRequest {
|
||||
contents: vec![Content {
|
||||
role: Some("user".to_string()),
|
||||
role: Some(Role::User),
|
||||
parts: Some(vec![Part::Text(prompt.to_string())]),
|
||||
}],
|
||||
generation_config: Some(GenerationConfig {
|
||||
|
||||
@@ -20,7 +20,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let request = GenerateContentRequest {
|
||||
contents: vec![Content {
|
||||
role: Some("user".to_string()),
|
||||
role: Some(Role::User),
|
||||
parts: Some(vec![Part::Text(prompt.to_string())]),
|
||||
}],
|
||||
safety_settings: Some(vec![SafetySetting {
|
||||
|
||||
@@ -20,7 +20,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let request = GenerateContentRequest {
|
||||
contents: vec![Content {
|
||||
role: Some("user".to_string()),
|
||||
role: Some(Role::User),
|
||||
parts: Some(vec![Part::Text(prompt.to_string())]),
|
||||
}],
|
||||
system_instruction: Some(Content {
|
||||
|
||||
@@ -15,8 +15,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
);
|
||||
|
||||
let prompt = "What is the airspeed of an unladen swallow?";
|
||||
let result = gemini.prompt_text(prompt, None).await?;
|
||||
println!("Response: {}", result);
|
||||
let request = GenerateContentRequest::builder().with_prompt(prompt).build();
|
||||
let response = gemini.generate_content(&request, "gemini-pro").await?;
|
||||
println!("Response: {:?}", response.candidates[0].get_text().unwrap());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user