Skip to content

Commit

Permalink
birthday: Better prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
trygvis committed Jan 15, 2025
1 parent a556542 commit 5d0b289
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions backend/src/birthday_bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::model::Employee;
use anyhow::{anyhow, Result};
use async_openai::config::OpenAIConfig;
use async_openai::types::*;
use time::OffsetDateTime;
use tracing::{info, instrument};

type Client = async_openai::Client<OpenAIConfig>;
Expand All @@ -22,9 +23,22 @@ impl BirthdayBot {

#[instrument(skip(self))]
pub(crate) async fn create_message(self: &Self, e: &Employee) -> Result<String> {
let dob = e
.dob
.ok_or(anyhow!("Employee doesn't have an date of birth set"))?;

let (now_year, now_day) = OffsetDateTime::now_utc().to_ordinal_date();
let (dob_year, dob_day) = dob.to_ordinal_date();

let mut age = now_year - dob_year;

if now_day < dob_day {
age -= 1;
}

let input = format!(
"Lag en morsom \"gratulerer med dagen\"-melding til {} som har bursdag i dag!",
e.name
"Det er {} som har bursdag i dag! Vedkommende blir {} år",
e.name, age
);

let (run, message) = self.run_message(input).await?;
Expand Down

0 comments on commit 5d0b289

Please sign in to comment.