Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions preprocessed_openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2974,6 +2974,8 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
x-rust-body-is-raw-text: true
x-supports-plain-text: true
/nl_search_models:
get:
tags:
Expand Down
44 changes: 44 additions & 0 deletions typesense/src/client/conversations/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Provides access to the API endpoints for managing conversation models.
//!
//! An `Conversations` instance is created via the main `client.conversations()` method.

use super::Client;
use model::Model;
use models::Models;

mod model;
mod models;

/// Provides methods for managing Typesense conversation models.
///
/// This struct is created by calling `client.conversations()`.
pub struct Conversations<'a> {
pub(super) client: &'a Client,
}

impl<'a> Conversations<'a> {
/// Creates a new `Conversations` instance.
#[inline]
pub(super) fn new(client: &'a Client) -> Self {
Self { client }
}

/// Provides access to endpoints for managing the collection of conversation models.
///
/// Example: `client.conversations().models().list().await`
#[inline]
pub fn models(&self) -> Models<'a> {
Models::new(self.client)
}

/// Provides access to endpoints for managing a single conversation model.
///
/// # Arguments
/// * `model_id` - The ID of the conversation model to manage.
///
/// Example: `client.conversations().model("...").get().await`
#[inline]
pub fn model(&self, model_id: &'a str) -> Model<'a> {
Model::new(self.client, model_id)
}
}
66 changes: 66 additions & 0 deletions typesense/src/client/conversations/model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//! Provides access to the API endpoints for managing a single conversation model.
//!
//! An instance of `Model` is created via the `client.conversations().model("model_id")` method.

use crate::{Client, Error, execute_wrapper, models};
use typesense_codegen::apis::conversations_api;

/// Provides methods for interacting with a specific conversation model.
///
/// This struct is created by calling `client.conversations().model("model_id")`.
pub struct Model<'a> {
pub(super) client: &'a Client,
pub(super) model_id: &'a str,
}

impl<'a> Model<'a> {
/// Creates a new `Model` instance for a specific model ID.
#[inline]
pub(super) fn new(client: &'a Client, model_id: &'a str) -> Self {
Self { client, model_id }
}

/// Retrieves the details of this specific conversation model.
pub async fn retrieve(
&self,
) -> Result<
models::ConversationModelSchema,
Error<conversations_api::RetrieveConversationModelError>,
> {
let params = conversations_api::RetrieveConversationModelParams {
model_id: self.model_id.to_owned(),
};
execute_wrapper!(self, conversations_api::retrieve_conversation_model, params)
}

/// Updates this specific conversation model.
///
/// # Arguments
/// * `schema` - A `ConversationModelUpdateSchema` object with the fields to update.
pub async fn update(
&self,
schema: models::ConversationModelUpdateSchema,
) -> Result<
models::ConversationModelSchema,
Error<conversations_api::UpdateConversationModelError>,
> {
let params = conversations_api::UpdateConversationModelParams {
model_id: self.model_id.to_owned(),
conversation_model_update_schema: schema,
};
execute_wrapper!(self, conversations_api::update_conversation_model, params)
}

/// Deletes this specific conversation model.
pub async fn delete(
&self,
) -> Result<
models::ConversationModelSchema,
Error<conversations_api::DeleteConversationModelError>,
> {
let params = conversations_api::DeleteConversationModelParams {
model_id: self.model_id.to_owned(),
};
execute_wrapper!(self, conversations_api::delete_conversation_model, params)
}
}
48 changes: 48 additions & 0 deletions typesense/src/client/conversations/models.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! Provides access to the API endpoints for managing conversation models.
//!
//! An instance of `Models` is created via the `client.conversations().models()` method.

use crate::{Client, Error, execute_wrapper, models};
use typesense_codegen::apis::conversations_api;

/// Provides methods for creating and listing conversation models.
///
/// This struct is created by calling `client.conversations().models()`.
pub struct Models<'a> {
pub(super) client: &'a Client,
}

impl<'a> Models<'a> {
/// Creates a new `Models` instance.
#[inline]
pub(super) fn new(client: &'a Client) -> Self {
Self { client }
}

/// Creates a new conversation model.
///
/// # Arguments
/// * `schema` - A `ConversationModelCreateSchema` object describing the model.
pub async fn create(
&self,
schema: models::ConversationModelCreateSchema,
) -> Result<
models::ConversationModelSchema,
Error<conversations_api::CreateConversationModelError>,
> {
let params = conversations_api::CreateConversationModelParams {
conversation_model_create_schema: schema,
};
execute_wrapper!(self, conversations_api::create_conversation_model, params)
}

/// Retrieves a summary of all conversation models.
pub async fn retrieve(
&self,
) -> Result<
Vec<models::ConversationModelSchema>,
Error<conversations_api::RetrieveAllConversationModelsError>,
> {
execute_wrapper!(self, conversations_api::retrieve_all_conversation_models)
}
}
54 changes: 54 additions & 0 deletions typesense/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@
mod aliases;
mod collection;
mod collections;
mod conversations;
mod key;
mod keys;
mod multi_search;
mod operations;
mod preset;
mod presets;
mod stemming;
mod stopword;
mod stopwords;

Expand All @@ -124,11 +126,13 @@
use aliases::Aliases;
use collection::Collection;
use collections::Collections;
use conversations::Conversations;
use key::Key;
use keys::Keys;
use operations::Operations;
use preset::Preset;
use presets::Presets;
use stemming::Stemming;
use stopword::Stopword;
use stopwords::Stopwords;

Expand Down Expand Up @@ -227,10 +231,10 @@
healthcheck_interval: Duration,
#[builder(default = ExponentialBackoff::builder().build_with_max_retries(3))]
/// The retry policy for transient network errors on a *single* node.
retry_policy: ExponentialBackoff,

Check warning on line 234 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `retry_policy`

Check warning on line 234 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `retry_policy`

Check warning on line 234 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `retry_policy`
#[builder(default = Duration::from_secs(5))]
/// The timeout for each individual network request.
connection_timeout: Duration,

Check warning on line 237 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `connection_timeout`

Check warning on line 237 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `connection_timeout`

Check warning on line 237 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `connection_timeout`
) -> Result<Self, &'static str> {
let is_nearest_node_set = nearest_node.is_some();

Expand Down Expand Up @@ -564,6 +568,30 @@
Collection::new(self, collection_name)
}

/// Returns a `Conversations` instance for managing conversation models.
/// # Example
/// ```no_run
/// # #[cfg(not(target_family = "wasm"))]
/// # {
/// # use typesense::Client;
/// #
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// # let client = Client::builder()
/// # .nodes(vec!["http://localhost:8108"])
/// # .api_key("xyz")
/// # .build()
/// # .unwrap();
/// let conversation = client.conversations().models().retrieve().await.unwrap();
/// # Ok(())
/// # }
/// # }
/// ```
#[inline]
pub fn conversations(&self) -> Conversations<'_> {
Conversations::new(self)
}

/// Provides access to endpoints for managing the collection of API keys.
///
/// # Example
Expand Down Expand Up @@ -735,6 +763,32 @@
Preset::new(self, preset_id)
}

/// Provides access to the stemming-related API endpoints.
///
/// # Example
///
/// ```no_run
/// # #[cfg(not(target_family = "wasm"))]
/// # {
/// # use typesense::Client;
/// #
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// # let client = Client::builder()
/// # .nodes(vec!["http://localhost:8108"])
/// # .api_key("xyz")
/// # .build()
/// # .unwrap();
/// let response = client.stemming().dictionaries().retrieve().await.unwrap();
/// # Ok(())
/// # }
/// # }
/// ```
#[inline]
pub fn stemming(&self) -> Stemming<'_> {
Stemming::new(self)
}

/// Provides access to endpoints for managing the collection of stopwords sets.
///
/// # Example
Expand Down
53 changes: 53 additions & 0 deletions typesense/src/client/stemming/dictionaries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! Provides access to the API endpoints for managing the collection of stemming dictionaries.
//!
//! A `Dictionaries` instance is created via the `client.stemming().dictionaries()` method.

use crate::{
client::{Client, Error},
execute_wrapper,
};
use typesense_codegen::{apis::stemming_api, models};

/// Provides methods for interacting with the collection of stemming dictionaries.
///
/// This struct is created by calling `client.stemming().dictionaries()`.
pub struct Dictionaries<'a> {
pub(super) client: &'a Client,
}

impl<'a> Dictionaries<'a> {
/// Creates a new `Dictionaries` instance.
#[inline]
pub(super) fn new(client: &'a Client) -> Self {
Self { client }
}

/// Imports a stemming dictionary from a JSONL file content.
///
/// This creates or updates a dictionary with the given ID.
///
/// # Arguments
/// * `dictionary_id` - The ID to assign to the dictionary.
/// * `dictionary_jsonl` - A string containing the word mappings in JSONL format.
pub async fn import(
&self,
dictionary_id: impl Into<String>,
dictionary_jsonl: String,
) -> Result<String, Error<stemming_api::ImportStemmingDictionaryError>> {
let params = stemming_api::ImportStemmingDictionaryParams {
id: dictionary_id.into(),
body: dictionary_jsonl,
};
execute_wrapper!(self, stemming_api::import_stemming_dictionary, params)
}

/// Retrieves a list of all stemming dictionaries.
pub async fn retrieve(
&self,
) -> Result<
models::ListStemmingDictionaries200Response,
Error<stemming_api::ListStemmingDictionariesError>,
> {
execute_wrapper!(self, stemming_api::list_stemming_dictionaries)
}
}
38 changes: 38 additions & 0 deletions typesense/src/client/stemming/dictionary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! Provides access to the API endpoints for managing a single stemming dictionary.
//!
//! An instance of `Dictionary` is created via the `client.stemming().dictionary()` method.

use crate::{
client::{Client, Error},
execute_wrapper,
};
use typesense_codegen::{apis::stemming_api, models};

/// Provides methods for interacting with a specific stemming dictionary.
///
/// This struct is created by calling `client.stemming().dictionary("dictionary_id")`.
pub struct Dictionary<'a> {
pub(super) client: &'a Client,
pub(super) dictionary_id: &'a str,
}

impl<'a> Dictionary<'a> {
/// Creates a new `Dictionary` instance for a specific dictionary ID.
#[inline]
pub(super) fn new(client: &'a Client, dictionary_id: &'a str) -> Self {
Self {
client,
dictionary_id,
}
}

/// Retrieves the details of this specific stemming dictionary.
pub async fn retrieve(
&self,
) -> Result<models::StemmingDictionary, Error<stemming_api::GetStemmingDictionaryError>> {
let params = stemming_api::GetStemmingDictionaryParams {
dictionary_id: self.dictionary_id.to_owned(),
};
execute_wrapper!(self, stemming_api::get_stemming_dictionary, params)
}
}
40 changes: 40 additions & 0 deletions typesense/src/client/stemming/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Provides access to the API endpoints for managing stemming.
//!
//! An instance of `Stemming` is created via the `client.stemming()` method.

pub mod dictionaries;
pub mod dictionary;

use super::Client;
use dictionaries::Dictionaries;
use dictionary::Dictionary;

/// Provides methods for managing Typesense stemming.
///
/// This struct is created by calling `client.stemming()`.
pub struct Stemming<'a> {
pub(super) client: &'a Client,
}

impl<'a> Stemming<'a> {
/// Creates a new `Stemming` instance.
#[inline]
pub(super) fn new(client: &'a Client) -> Self {
Self { client }
}

/// Provides access to endpoints for managing the collection of dictionaries.
#[inline]
pub fn dictionaries(&self) -> Dictionaries<'a> {
Dictionaries::new(self.client)
}

/// Provides access to endpoints for managing a single dictionary.
///
/// # Arguments
/// * `dictionary_id` - The ID of the dictionary to manage.
#[inline]
pub fn dictionary(&self, dictionary_id: &'a str) -> Dictionary<'a> {
Dictionary::new(self.client, dictionary_id)
}
}
Loading
Loading