Skip to content

Commit

Permalink
add system prompt for Gemini
Browse files Browse the repository at this point in the history
  • Loading branch information
jelni committed Aug 26, 2024
1 parent 2042911 commit fc2ba3e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/apis/makersuite.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::time::Duration;
use std::{env, fmt};

Expand Down Expand Up @@ -122,18 +123,19 @@ pub async fn upload_file(
struct GenerateContentRequest<'a> {
contents: &'a [Content<'a>],
safety_settings: &'static [SafetySetting],
system_instruction: Content<'a>,
generation_config: GenerationConfig,
}

#[derive(Serialize)]
struct Content<'a> {
parts: &'a [Part],
parts: &'a [Part<'a>],
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub enum Part {
Text(String),
pub enum Part<'a> {
Text(Cow<'a, str>),
FileData(FileData),
}

Expand Down Expand Up @@ -225,7 +227,7 @@ pub async fn stream_generate_content(
http_client: reqwest::Client,
tx: mpsc::UnboundedSender<Result<GenerateContentResponse, GenerationError>>,
model: &str,
parts: &[Part],
parts: &[Part<'_>],
max_output_tokens: u16,
) {
let url = format!(
Expand All @@ -251,6 +253,11 @@ pub async fn stream_generate_content(
},
SafetySetting { category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE" },
],
system_instruction: Content {
parts: &[Part::Text(Cow::Borrowed(
"Be concise and precise. Don't be verbose. Answer in the user's language.",
))],
},
generation_config: GenerationConfig { max_output_tokens },
})
.send()
Expand Down
3 changes: 2 additions & 1 deletion src/commands/makersuite.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::fmt::Write;
use std::time::Duration;

Expand Down Expand Up @@ -42,7 +43,7 @@ impl CommandTrait for GoogleGemini {
let mut parts = Vec::new();

if let Some(prompt) = prompt {
parts.push(Part::Text(prompt.0));
parts.push(Part::Text(Cow::Owned(prompt.0)));
}

if let Some(message_image) =
Expand Down

0 comments on commit fc2ba3e

Please sign in to comment.