|
| 1 | +//! Provides access to the API endpoints for managing a single conversation model. |
| 2 | +//! |
| 3 | +//! An instance of `Model` is created via the `client.conversations().model("model_id")` method. |
| 4 | +
|
| 5 | +use crate::{Client, Error, execute_wrapper, models}; |
| 6 | +use typesense_codegen::apis::conversations_api; |
| 7 | + |
| 8 | +/// Provides methods for interacting with a specific conversation model. |
| 9 | +/// |
| 10 | +/// This struct is created by calling `client.conversations().model("model_id")`. |
| 11 | +pub struct Model<'a> { |
| 12 | + pub(super) client: &'a Client, |
| 13 | + pub(super) model_id: &'a str, |
| 14 | +} |
| 15 | + |
| 16 | +impl<'a> Model<'a> { |
| 17 | + /// Creates a new `Model` instance for a specific model ID. |
| 18 | + #[inline] |
| 19 | + pub(super) fn new(client: &'a Client, model_id: &'a str) -> Self { |
| 20 | + Self { client, model_id } |
| 21 | + } |
| 22 | + |
| 23 | + /// Retrieves the details of this specific conversation model. |
| 24 | + pub async fn retrieve( |
| 25 | + &self, |
| 26 | + ) -> Result< |
| 27 | + models::ConversationModelSchema, |
| 28 | + Error<conversations_api::RetrieveConversationModelError>, |
| 29 | + > { |
| 30 | + let params = conversations_api::RetrieveConversationModelParams { |
| 31 | + model_id: self.model_id.to_owned(), |
| 32 | + }; |
| 33 | + execute_wrapper!(self, conversations_api::retrieve_conversation_model, params) |
| 34 | + } |
| 35 | + |
| 36 | + /// Updates this specific conversation model. |
| 37 | + /// |
| 38 | + /// # Arguments |
| 39 | + /// * `schema` - A `ConversationModelUpdateSchema` object with the fields to update. |
| 40 | + pub async fn update( |
| 41 | + &self, |
| 42 | + schema: models::ConversationModelUpdateSchema, |
| 43 | + ) -> Result< |
| 44 | + models::ConversationModelSchema, |
| 45 | + Error<conversations_api::UpdateConversationModelError>, |
| 46 | + > { |
| 47 | + let params = conversations_api::UpdateConversationModelParams { |
| 48 | + model_id: self.model_id.to_owned(), |
| 49 | + conversation_model_update_schema: schema, |
| 50 | + }; |
| 51 | + execute_wrapper!(self, conversations_api::update_conversation_model, params) |
| 52 | + } |
| 53 | + |
| 54 | + /// Deletes this specific conversation model. |
| 55 | + pub async fn delete( |
| 56 | + &self, |
| 57 | + ) -> Result< |
| 58 | + models::ConversationModelSchema, |
| 59 | + Error<conversations_api::DeleteConversationModelError>, |
| 60 | + > { |
| 61 | + let params = conversations_api::DeleteConversationModelParams { |
| 62 | + model_id: self.model_id.to_owned(), |
| 63 | + }; |
| 64 | + execute_wrapper!(self, conversations_api::delete_conversation_model, params) |
| 65 | + } |
| 66 | +} |
0 commit comments