artifacts: move some of the artifacts code into its own module

This commit is contained in:
2026-06-09 19:16:41 +02:00
parent ad90df7767
commit 7f2dd6f8b2
4 changed files with 52 additions and 37 deletions
+45
View File
@@ -0,0 +1,45 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum Artifact {
Bandcamp(BandcampResult),
BeetsTrack(serde_json::Value)
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum BandcampResult {
Artist { name: String, bio: Option<String>, location: Option<String> },
Album { title: String, about: Option<String>, credits: Option<String>, release_date: DateTime<Utc>, artist: String }
}
impl Into<BandcampResult> for bandcamp::Artist {
fn into(self) -> BandcampResult {
BandcampResult::Artist { name: self.name, bio: self.bio, location: self.location }
}
}
impl Into<BandcampResult> for bandcamp::Album {
fn into(self) -> BandcampResult {
BandcampResult::Album {
about: self.about,
title: self.title,
artist: self.band.name,
credits: self.credits,
release_date: self.release_date
}
}
}
impl Into<Artifact> for bandcamp::Album {
fn into(self) -> Artifact {
Artifact::Bandcamp(self.into())
}
}
impl Into<Artifact> for bandcamp::Artist {
fn into(self) -> Artifact {
Artifact::Bandcamp(self.into())
}
}
+1
View File
@@ -21,6 +21,7 @@ mod transcription;
mod tts; mod tts;
mod prediction; mod prediction;
mod audio; mod audio;
mod artifacts;
// TODO: We should be able to delete entries from the conversation, or at least go back and edit something I said. // TODO: We should be able to delete entries from the conversation, or at least go back and edit something I said.
// TODO: I want a "mark" command or keyboard shortcut, that inserts a marker into the log, so I know where to come back for the next speaking segment. // TODO: I want a "mark" command or keyboard shortcut, that inserts a marker into the log, so I know where to come back for the next speaking segment.
+5 -30
View File
@@ -2,13 +2,12 @@ use std::process::{Command, Stdio};
use async_openai::{Client, config::OpenAIConfig, types::chat::{ChatCompletionMessageToolCalls, ChatCompletionRequestAssistantMessageArgs, ChatCompletionRequestMessage, ChatCompletionRequestSystemMessageArgs, ChatCompletionRequestToolMessageArgs, ChatCompletionTool, ChatCompletionTools, CreateChatCompletionRequestArgs, FinishReason, FunctionObjectArgs, ResponseFormat, ResponseFormatJsonSchema}}; use async_openai::{Client, config::OpenAIConfig, types::chat::{ChatCompletionMessageToolCalls, ChatCompletionRequestAssistantMessageArgs, ChatCompletionRequestMessage, ChatCompletionRequestSystemMessageArgs, ChatCompletionRequestToolMessageArgs, ChatCompletionTool, ChatCompletionTools, CreateChatCompletionRequestArgs, FinishReason, FunctionObjectArgs, ResponseFormat, ResponseFormatJsonSchema}};
use bandcamp::SearchResultItem; use bandcamp::SearchResultItem;
use chrono::{DateTime, Utc};
use schemars::{JsonSchema, schema_for}; use schemars::{JsonSchema, schema_for};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{Serializer, ser::CompactFormatter}; use serde_json::{Serializer, ser::CompactFormatter};
use tokio::sync::{mpsc, watch}; use tokio::sync::{mpsc, watch};
use crate::{SaveData, scene::{Artifact, ConversationEntry, PredictionAction, Scene, Scenery, StageDirection}}; use crate::{SaveData, artifacts::{Artifact, BandcampResult}, scene::{ConversationEntry, PredictionAction, Scene, Scenery, StageDirection}};
const SYSTEM_PROMPT: &str = include_str!("system-prompt.txt"); const SYSTEM_PROMPT: &str = include_str!("system-prompt.txt");
@@ -62,30 +61,6 @@ struct BandcampQueryArgs {
query: String query: String
} }
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum BandcampResult {
Artist { name: String, bio: Option<String>, location: Option<String> },
Album { title: String, about: Option<String>, credits: Option<String>, release_date: DateTime<Utc>, artist: String }
}
impl Into<BandcampResult> for bandcamp::Artist {
fn into(self) -> BandcampResult {
BandcampResult::Artist { name: self.name, bio: self.bio, location: self.location }
}
}
impl Into<BandcampResult> for bandcamp::Album {
fn into(self) -> BandcampResult {
BandcampResult::Album {
about: self.about,
title: self.title,
artist: self.band.name,
credits: self.credits,
release_date: self.release_date
}
}
}
#[derive(Default, Debug)] #[derive(Default, Debug)]
struct ToolResults { struct ToolResults {
result: Option<String>, result: Option<String>,
@@ -133,12 +108,12 @@ impl Session {
for result in results { for result in results {
match result { match result {
SearchResultItem::Artist(data) => { SearchResultItem::Artist(data) => {
let result: BandcampResult = bandcamp::fetch_artist(data.artist_id).await.unwrap().into(); let result = bandcamp::fetch_artist(data.artist_id).await.unwrap().into();
json_results.push(Artifact::Bandcamp(result)); json_results.push(result);
}, },
SearchResultItem::Album(data) => { SearchResultItem::Album(data) => {
let result: BandcampResult = bandcamp::fetch_album(data.band_id, data.album_id).await.unwrap().into(); let result = bandcamp::fetch_album(data.band_id, data.album_id).await.unwrap().into();
json_results.push(Artifact::Bandcamp(result)); json_results.push(result);
} }
_ => () _ => ()
} }
+1 -7
View File
@@ -3,7 +3,7 @@ use chrono::{DateTime, Duration, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sqlite::OpenFlags; use sqlite::OpenFlags;
use crate::prediction::{BandcampResult, GeneratedResponses, PossibleResponse}; use crate::{artifacts::Artifact, prediction::{GeneratedResponses, PossibleResponse}};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ConversationEntry { pub enum ConversationEntry {
@@ -74,12 +74,6 @@ impl Default for StageDirection {
} }
} }
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum Artifact {
Bandcamp(BandcampResult),
BeetsTrack(serde_json::Value)
}
#[derive(Debug, Default, Serialize, Deserialize, Clone)] #[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct Scenery { pub struct Scenery {
pub artifacts: Vec<Artifact> pub artifacts: Vec<Artifact>