Download crates/forge_services/src/conversation.rs from SaylorTwift/forgecode: direct link, hf CLI and curl.
- Browser
- Download file 2.22 kB
-
https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_services/src/conversation.rs
- Command line
-
hf download hf://SaylorTwift/forgecode/crates/forge_services/src/conversation.rs
-
curl -L -o conversation.rs https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_services/src/conversation.rs
2.22 kB
| use std::sync::Arc; | |
| use anyhow::Result; | |
| use forge_app::ConversationService; | |
| use forge_app::domain::{Conversation, ConversationId}; | |
| use forge_domain::ConversationRepository; | |
| /// Service for managing conversations, including creation, retrieval, and | |
| /// updates | |
| pub struct ForgeConversationService<S> { | |
| conversation_repository: Arc<S>, | |
| } | |
| impl<S: ConversationRepository> ForgeConversationService<S> { | |
| /// Creates a new ForgeConversationService with the provided repository | |
| pub fn new(repo: Arc<S>) -> Self { | |
| Self { conversation_repository: repo } | |
| } | |
| } | |
| impl<S: ConversationRepository> ConversationService for ForgeConversationService<S> { | |
| async fn modify_conversation<F, T>(&self, id: &ConversationId, f: F) -> Result<T> | |
| where | |
| F: FnOnce(&mut Conversation) -> T + Send, | |
| T: Send, | |
| { | |
| let mut conversation = self | |
| .conversation_repository | |
| .get_conversation(id) | |
| .await? | |
| .ok_or_else(|| forge_app::domain::Error::ConversationNotFound(*id))?; | |
| let out = f(&mut conversation); | |
| let _ = self | |
| .conversation_repository | |
| .upsert_conversation(conversation) | |
| .await?; | |
| Ok(out) | |
| } | |
| async fn find_conversation(&self, id: &ConversationId) -> Result<Option<Conversation>> { | |
| self.conversation_repository.get_conversation(id).await | |
| } | |
| async fn upsert_conversation(&self, conversation: Conversation) -> Result<()> { | |
| let _ = self | |
| .conversation_repository | |
| .upsert_conversation(conversation) | |
| .await?; | |
| Ok(()) | |
| } | |
| async fn get_conversations(&self, limit: Option<usize>) -> Result<Option<Vec<Conversation>>> { | |
| self.conversation_repository | |
| .get_all_conversations(limit) | |
| .await | |
| } | |
| async fn last_conversation(&self) -> Result<Option<Conversation>> { | |
| self.conversation_repository.get_last_conversation().await | |
| } | |
| async fn delete_conversation(&self, conversation_id: &ConversationId) -> Result<()> { | |
| self.conversation_repository | |
| .delete_conversation(conversation_id) | |
| .await | |
| } | |
| } | |