Skip to main content

llmrix_rust_sdk/resources/
conversations.rs

1use std::sync::Arc;
2use crate::{error::Result, model::*, transport::*};
3
4/// Operations on the Conversations API. Obtain via [`LlmrixClient::conversations`].
5pub struct ConversationsResource {
6    pub(crate) t: Arc<Transport>,
7}
8
9impl ConversationsResource {
10    /// Create a new conversation.
11    pub async fn create(&self, req: ConversationCreateRequest) -> Result<Conversation> {
12        self.t.post(&path_conversations(), &req).await
13    }
14
15    /// List conversations (cursor pagination). Pass `last_id = 0` to start from the beginning.
16    pub async fn list(&self, last_id: i64, size: u32) -> Result<PageResult<Conversation>> {
17        let path = format!("{}?lastId={}&size={}", path_conversations(), last_id, size);
18        self.t.get(&path).await
19    }
20
21    /// Retrieve a single conversation by ID.
22    pub async fn get(&self, id: &str) -> Result<Conversation> {
23        self.t.get(&path_conversation(id)).await
24    }
25
26    /// Update a conversation's metadata (title).
27    pub async fn update(&self, id: &str, req: ConversationUpdateRequest) -> Result<Conversation> {
28        self.t.patch(&path_conversation(id), &req).await
29    }
30
31    /// Permanently delete a conversation and all of its messages.
32    pub async fn delete(&self, id: &str) -> Result<()> {
33        self.t.delete(&path_conversation(id)).await
34    }
35
36    /// Return a page of messages in the given conversation.
37    pub async fn messages(&self, id: &str, last_id: i64, size: u32) -> Result<PageResult<Message>> {
38        let path = format!("{}?lastId={}&size={}", path_messages(id), last_id, size);
39        self.t.get(&path).await
40    }
41}