Skip to content

Commit

Permalink
Transcription / Summary / Sentiment analysis with OpenAI (#33)
Browse files Browse the repository at this point in the history
* wip: openai whisper integration

* feat: working implementation of transcription

* feat: launch subtask for transcription

* feat: summarize

* feat: summarize and extract sentiment
  • Loading branch information
RulerOfCakes authored Dec 15, 2024
1 parent 10316e4 commit 3a8f1fc
Show file tree
Hide file tree
Showing 11 changed files with 391 additions and 20 deletions.
4 changes: 4 additions & 0 deletions Recordiary/Recordiary/Models/Diary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct DiaryModel: Decodable {
let userId: String
let audioLink: String
let summary: String?
let transcription: String?
let emotion: String?
let isPrivate: Bool

enum CodingKeys: String, CodingKey {
Expand All @@ -23,6 +25,8 @@ struct DiaryModel: Decodable {
case userId = "user_id"
case audioLink = "audio_link"
case summary
case transcription
case emotion
case isPrivate = "is_private"
}
}
110 changes: 107 additions & 3 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ tower-http = { version = "0.6.1", features = ["limit", "trace"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
itertools = "0.13.0"
tempfile = "3.14.0"
openai-api-rs = "5.2.3"
46 changes: 42 additions & 4 deletions backend/src/db/diary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub struct Diary {
user_id: Uuid,
audio_link: Option<String>,
summary: Option<String>,
transcription: Option<String>,
emotion: Option<String>,
is_private: bool,
}

Expand Down Expand Up @@ -94,25 +96,61 @@ pub async fn update_diary(
id: i64,
audio_link: Option<String>,
summary: Option<String>,
transcription: Option<String>,
emotion: Option<String>,
is_private: Option<bool>,
) -> anyhow::Result<()> {
if audio_link.is_none() && summary.is_none() && is_private.is_none() {
if audio_link.is_none()
&& summary.is_none()
&& transcription.is_none()
&& is_private.is_none()
&& emotion.is_none()
{
return Ok(());
}
let mut qry_builder: sqlx::QueryBuilder<'_, Postgres> =
sqlx::query_builder::QueryBuilder::new("UPDATE diary SET ");
let mut separated = qry_builder.separated(", ");
let mut first = true;

if let Some(audio_link) = audio_link {
if !first {
separated.push_unseparated(", ");
}
separated.push_unseparated("audio_link = ");
separated.push_bind(audio_link);
separated.push_bind_unseparated(audio_link);
first = false;
}
if let Some(summary) = summary {
if !first {
separated.push_unseparated(", ");
}
separated.push_unseparated("summary = ");
separated.push_bind(summary);
separated.push_bind_unseparated(summary);
first = false;
}
if let Some(transcription) = transcription {
if !first {
separated.push_unseparated(", ");
}
separated.push_unseparated("transcription = ");
separated.push_bind_unseparated(transcription);
first = false;
}
if let Some(emotion) = emotion {
if !first {
separated.push_unseparated(", ");
}
separated.push_unseparated("emotion = ");
separated.push_bind_unseparated(emotion);
first = false;
}
if let Some(is_private) = is_private {
if !first {
separated.push_unseparated(", ");
}
separated.push_unseparated("is_private = ");
separated.push_bind(is_private);
separated.push_bind_unseparated(is_private);
}

qry_builder.push(" WHERE id = ").push_bind(id);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/deco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub async fn create_deco(
};
// upload model to storage
let url = storage_client
.upload_model(model_bytes.to_vec(), params.name.clone())
.upload_model(model_bytes.to_vec(), &params.name)
.await?;

let deco = crate::db::deco::create_deco(
Expand Down
Loading

0 comments on commit 3a8f1fc

Please sign in to comment.