Make content role optional
This commit is contained in:
@@ -17,7 +17,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let prompt = "What is the airspeed of an unladen swallow?";
|
let prompt = "What is the airspeed of an unladen swallow?";
|
||||||
let request = CountTokensRequest {
|
let request = CountTokensRequest {
|
||||||
contents: Content {
|
contents: Content {
|
||||||
role: "user".to_string(),
|
role: Some("user".to_string()),
|
||||||
parts: Some(vec![Part::Text(prompt.to_string())]),
|
parts: Some(vec![Part::Text(prompt.to_string())]),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,16 +15,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
location_id,
|
location_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let system_instruction = "Answer as if you were Winston Churchill";
|
let system_instruction = "Answer as if you were Yoda";
|
||||||
let prompt = "What is the airspeed of an unladen swallow?";
|
let prompt = "What is the airspeed of an unladen swallow?";
|
||||||
|
|
||||||
let request = GenerateContentRequest {
|
let request = GenerateContentRequest {
|
||||||
contents: vec![Content {
|
contents: vec![Content {
|
||||||
role: "user".to_string(),
|
role: Some("user".to_string()),
|
||||||
parts: Some(vec![Part::Text(prompt.to_string())]),
|
parts: Some(vec![Part::Text(prompt.to_string())]),
|
||||||
}],
|
}],
|
||||||
system_instruction: Some(Content {
|
system_instruction: Some(Content {
|
||||||
role: "system".to_string(),
|
role: None,
|
||||||
parts: Some(vec![Part::Text(system_instruction.to_string())]),
|
parts: Some(vec![Part::Text(system_instruction.to_string())]),
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ impl<T: TokenProvider + Clone> GeminiClient<T> {
|
|||||||
contents: messages
|
contents: messages
|
||||||
.iter()
|
.iter()
|
||||||
.map(|m| Content {
|
.map(|m| Content {
|
||||||
role: m.role.to_string(),
|
role: Some(m.role.to_string()),
|
||||||
parts: Some(vec![Part::Text(m.text.clone())]),
|
parts: Some(vec![Part::Text(m.text.clone())]),
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -181,7 +181,7 @@ impl<T: TokenProvider + Clone> GeminiClient<T> {
|
|||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
let request = GenerateContentRequest {
|
let request = GenerateContentRequest {
|
||||||
contents: vec![Content {
|
contents: vec![Content {
|
||||||
role: "user".to_string(),
|
role: Some("user".to_string()),
|
||||||
parts: Some(vec![Part::Text(prompt.to_string())]),
|
parts: Some(vec![Part::Text(prompt.to_string())]),
|
||||||
}],
|
}],
|
||||||
generation_config: generation_config.cloned(),
|
generation_config: generation_config.cloned(),
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct Content {
|
pub struct Content {
|
||||||
pub role: String,
|
pub role: Option<String>,
|
||||||
pub parts: Option<Vec<Part>>,
|
pub parts: Option<Vec<Part>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ impl GenerateContentRequest {
|
|||||||
pub fn from_prompt(prompt: &str, generation_config: Option<GenerationConfig>) -> Self {
|
pub fn from_prompt(prompt: &str, generation_config: Option<GenerationConfig>) -> Self {
|
||||||
GenerateContentRequest {
|
GenerateContentRequest {
|
||||||
contents: vec![Content {
|
contents: vec![Content {
|
||||||
role: "user".to_string(),
|
role: Some("user".to_string()),
|
||||||
parts: Some(vec![Part::Text(prompt.to_string())]),
|
parts: Some(vec![Part::Text(prompt.to_string())]),
|
||||||
}],
|
}],
|
||||||
generation_config,
|
generation_config,
|
||||||
|
|||||||
Reference in New Issue
Block a user