Skip to content

Commit

Permalink
always use gemini-1.5-flash
Browse files Browse the repository at this point in the history
  • Loading branch information
jelni committed Jul 20, 2024
1 parent 015e3cd commit b60b03c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ COPY Cargo.toml Cargo.lock ./
COPY src src
COPY .cargo .cargo
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=target \
cargo build --release \
&& cp target/release/craiyon-bot craiyon-bot
Expand Down
12 changes: 9 additions & 3 deletions src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ impl Bot {
}
}

if let Err(err) = self.state.config.lock().unwrap().save() {
let result = self.state.config.lock().unwrap().save();

if let Err(err) = result {
log::error!("failed to save bot config: {err}");
}

if let Err(err) = markov_chain_manager::save(&self.state.markov_chain.lock().unwrap()) {
let result = markov_chain_manager::save(&self.state.markov_chain.lock().unwrap());

if let Err(err) = result {
log::error!("failed to save Markov chain: {err}");
}
}
Expand Down Expand Up @@ -238,7 +242,9 @@ impl Bot {
fn on_chat_member(&self, update: UpdateChatMember) {
if let MessageSender::User(user) = &update.new_chat_member.member_id {
if self.my_id.is_some_and(|my_id| user.user_id == my_id) {
if let Some(chat) = self.state.cache.lock().unwrap().get_chat(update.chat_id) {
let chat = self.state.cache.lock().unwrap().get_chat(update.chat_id);

if let Some(chat) = chat {
telegram_utils::log_status_update(&update, &chat);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/commands/makersuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ impl CommandTrait for GoogleGemini {

ctx.send_typing().await?;

let mut model = "gemini-1.0-pro-latest";
let mut parts = Vec::new();

if let Some(prompt) = prompt {
Expand All @@ -56,8 +55,6 @@ impl CommandTrait for GoogleGemini {
return Err(CommandError::Custom("the image cannot be larger than 4 MiB.".into()));
}

model = "gemini-1.0-pro-vision-latest";

let File::File(file) =
functions::download_file(message_image.file.id, 1, 0, 0, true, ctx.client_id)
.await?;
Expand All @@ -78,7 +75,8 @@ impl CommandTrait for GoogleGemini {
let (tx, mut rx) = mpsc::unbounded_channel();

tokio::spawn(async move {
makersuite::stream_generate_content(http_client, tx, model, &parts, 512).await;
makersuite::stream_generate_content(http_client, tx, "gemini-1.5-flash", &parts, 512)
.await;
});

let mut next_update = Instant::now() + Duration::from_secs(5);
Expand Down
4 changes: 3 additions & 1 deletion src/utilities/bot_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ impl BotState {
member_id: i64,
client_id: i32,
) -> TdResult<ChatMemberStatus> {
if let Some(status) = self.cache.lock().unwrap().get_member_status(chat_id, member_id) {
let status = self.cache.lock().unwrap().get_member_status(chat_id, member_id);

if let Some(status) = status {
return Ok(status);
}

Expand Down
4 changes: 3 additions & 1 deletion src/utilities/message_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ impl MessageQueue {
),
};

if let Some(tx) = self.queue.lock().unwrap().remove(&old_message_id) {
let tx = self.queue.lock().unwrap().remove(&old_message_id);

if let Some(tx) = tx {
tx.send(result).unwrap();
}
}
Expand Down

0 comments on commit b60b03c

Please sign in to comment.