Skip to content

Commit 2caf0f1

Browse files
authored
Add stemming API & conversation API (#58)
* feat: stemming API * feat: conversations API
1 parent 602d3bb commit 2caf0f1

File tree

15 files changed

+803
-7
lines changed

15 files changed

+803
-7
lines changed

preprocessed_openapi.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,6 +2974,8 @@ paths:
29742974
application/json:
29752975
schema:
29762976
$ref: '#/components/schemas/ApiResponse'
2977+
x-rust-body-is-raw-text: true
2978+
x-supports-plain-text: true
29772979
/nl_search_models:
29782980
get:
29792981
tags:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//! Provides access to the API endpoints for managing conversation models.
2+
//!
3+
//! An `Conversations` instance is created via the main `client.conversations()` method.
4+
5+
use super::Client;
6+
use model::Model;
7+
use models::Models;
8+
9+
mod model;
10+
mod models;
11+
12+
/// Provides methods for managing Typesense conversation models.
13+
///
14+
/// This struct is created by calling `client.conversations()`.
15+
pub struct Conversations<'a> {
16+
pub(super) client: &'a Client,
17+
}
18+
19+
impl<'a> Conversations<'a> {
20+
/// Creates a new `Conversations` instance.
21+
#[inline]
22+
pub(super) fn new(client: &'a Client) -> Self {
23+
Self { client }
24+
}
25+
26+
/// Provides access to endpoints for managing the collection of conversation models.
27+
///
28+
/// Example: `client.conversations().models().list().await`
29+
#[inline]
30+
pub fn models(&self) -> Models<'a> {
31+
Models::new(self.client)
32+
}
33+
34+
/// Provides access to endpoints for managing a single conversation model.
35+
///
36+
/// # Arguments
37+
/// * `model_id` - The ID of the conversation model to manage.
38+
///
39+
/// Example: `client.conversations().model("...").get().await`
40+
#[inline]
41+
pub fn model(&self, model_id: &'a str) -> Model<'a> {
42+
Model::new(self.client, model_id)
43+
}
44+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//! Provides access to the API endpoints for managing conversation models.
2+
//!
3+
//! An instance of `Models` is created via the `client.conversations().models()` method.
4+
5+
use crate::{Client, Error, execute_wrapper, models};
6+
use typesense_codegen::apis::conversations_api;
7+
8+
/// Provides methods for creating and listing conversation models.
9+
///
10+
/// This struct is created by calling `client.conversations().models()`.
11+
pub struct Models<'a> {
12+
pub(super) client: &'a Client,
13+
}
14+
15+
impl<'a> Models<'a> {
16+
/// Creates a new `Models` instance.
17+
#[inline]
18+
pub(super) fn new(client: &'a Client) -> Self {
19+
Self { client }
20+
}
21+
22+
/// Creates a new conversation model.
23+
///
24+
/// # Arguments
25+
/// * `schema` - A `ConversationModelCreateSchema` object describing the model.
26+
pub async fn create(
27+
&self,
28+
schema: models::ConversationModelCreateSchema,
29+
) -> Result<
30+
models::ConversationModelSchema,
31+
Error<conversations_api::CreateConversationModelError>,
32+
> {
33+
let params = conversations_api::CreateConversationModelParams {
34+
conversation_model_create_schema: schema,
35+
};
36+
execute_wrapper!(self, conversations_api::create_conversation_model, params)
37+
}
38+
39+
/// Retrieves a summary of all conversation models.
40+
pub async fn retrieve(
41+
&self,
42+
) -> Result<
43+
Vec<models::ConversationModelSchema>,
44+
Error<conversations_api::RetrieveAllConversationModelsError>,
45+
> {
46+
execute_wrapper!(self, conversations_api::retrieve_all_conversation_models)
47+
}
48+
}

typesense/src/client/mod.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ mod alias;
110110
mod aliases;
111111
mod collection;
112112
mod collections;
113+
mod conversations;
113114
mod key;
114115
mod keys;
115116
mod multi_search;
116117
mod operations;
117118
mod preset;
118119
mod presets;
120+
mod stemming;
119121
mod stopword;
120122
mod stopwords;
121123

@@ -124,11 +126,13 @@ use alias::Alias;
124126
use aliases::Aliases;
125127
use collection::Collection;
126128
use collections::Collections;
129+
use conversations::Conversations;
127130
use key::Key;
128131
use keys::Keys;
129132
use operations::Operations;
130133
use preset::Preset;
131134
use presets::Presets;
135+
use stemming::Stemming;
132136
use stopword::Stopword;
133137
use stopwords::Stopwords;
134138

@@ -564,6 +568,30 @@ impl Client {
564568
Collection::new(self, collection_name)
565569
}
566570

571+
/// Returns a `Conversations` instance for managing conversation models.
572+
/// # Example
573+
/// ```no_run
574+
/// # #[cfg(not(target_family = "wasm"))]
575+
/// # {
576+
/// # use typesense::Client;
577+
/// #
578+
/// # #[tokio::main]
579+
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
580+
/// # let client = Client::builder()
581+
/// # .nodes(vec!["http://localhost:8108"])
582+
/// # .api_key("xyz")
583+
/// # .build()
584+
/// # .unwrap();
585+
/// let conversation = client.conversations().models().retrieve().await.unwrap();
586+
/// # Ok(())
587+
/// # }
588+
/// # }
589+
/// ```
590+
#[inline]
591+
pub fn conversations(&self) -> Conversations<'_> {
592+
Conversations::new(self)
593+
}
594+
567595
/// Provides access to endpoints for managing the collection of API keys.
568596
///
569597
/// # Example
@@ -735,6 +763,32 @@ impl Client {
735763
Preset::new(self, preset_id)
736764
}
737765

766+
/// Provides access to the stemming-related API endpoints.
767+
///
768+
/// # Example
769+
///
770+
/// ```no_run
771+
/// # #[cfg(not(target_family = "wasm"))]
772+
/// # {
773+
/// # use typesense::Client;
774+
/// #
775+
/// # #[tokio::main]
776+
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
777+
/// # let client = Client::builder()
778+
/// # .nodes(vec!["http://localhost:8108"])
779+
/// # .api_key("xyz")
780+
/// # .build()
781+
/// # .unwrap();
782+
/// let response = client.stemming().dictionaries().retrieve().await.unwrap();
783+
/// # Ok(())
784+
/// # }
785+
/// # }
786+
/// ```
787+
#[inline]
788+
pub fn stemming(&self) -> Stemming<'_> {
789+
Stemming::new(self)
790+
}
791+
738792
/// Provides access to endpoints for managing the collection of stopwords sets.
739793
///
740794
/// # Example
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//! Provides access to the API endpoints for managing the collection of stemming dictionaries.
2+
//!
3+
//! A `Dictionaries` instance is created via the `client.stemming().dictionaries()` method.
4+
5+
use crate::{
6+
client::{Client, Error},
7+
execute_wrapper,
8+
};
9+
use typesense_codegen::{apis::stemming_api, models};
10+
11+
/// Provides methods for interacting with the collection of stemming dictionaries.
12+
///
13+
/// This struct is created by calling `client.stemming().dictionaries()`.
14+
pub struct Dictionaries<'a> {
15+
pub(super) client: &'a Client,
16+
}
17+
18+
impl<'a> Dictionaries<'a> {
19+
/// Creates a new `Dictionaries` instance.
20+
#[inline]
21+
pub(super) fn new(client: &'a Client) -> Self {
22+
Self { client }
23+
}
24+
25+
/// Imports a stemming dictionary from a JSONL file content.
26+
///
27+
/// This creates or updates a dictionary with the given ID.
28+
///
29+
/// # Arguments
30+
/// * `dictionary_id` - The ID to assign to the dictionary.
31+
/// * `dictionary_jsonl` - A string containing the word mappings in JSONL format.
32+
pub async fn import(
33+
&self,
34+
dictionary_id: impl Into<String>,
35+
dictionary_jsonl: String,
36+
) -> Result<String, Error<stemming_api::ImportStemmingDictionaryError>> {
37+
let params = stemming_api::ImportStemmingDictionaryParams {
38+
id: dictionary_id.into(),
39+
body: dictionary_jsonl,
40+
};
41+
execute_wrapper!(self, stemming_api::import_stemming_dictionary, params)
42+
}
43+
44+
/// Retrieves a list of all stemming dictionaries.
45+
pub async fn retrieve(
46+
&self,
47+
) -> Result<
48+
models::ListStemmingDictionaries200Response,
49+
Error<stemming_api::ListStemmingDictionariesError>,
50+
> {
51+
execute_wrapper!(self, stemming_api::list_stemming_dictionaries)
52+
}
53+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! Provides access to the API endpoints for managing a single stemming dictionary.
2+
//!
3+
//! An instance of `Dictionary` is created via the `client.stemming().dictionary()` method.
4+
5+
use crate::{
6+
client::{Client, Error},
7+
execute_wrapper,
8+
};
9+
use typesense_codegen::{apis::stemming_api, models};
10+
11+
/// Provides methods for interacting with a specific stemming dictionary.
12+
///
13+
/// This struct is created by calling `client.stemming().dictionary("dictionary_id")`.
14+
pub struct Dictionary<'a> {
15+
pub(super) client: &'a Client,
16+
pub(super) dictionary_id: &'a str,
17+
}
18+
19+
impl<'a> Dictionary<'a> {
20+
/// Creates a new `Dictionary` instance for a specific dictionary ID.
21+
#[inline]
22+
pub(super) fn new(client: &'a Client, dictionary_id: &'a str) -> Self {
23+
Self {
24+
client,
25+
dictionary_id,
26+
}
27+
}
28+
29+
/// Retrieves the details of this specific stemming dictionary.
30+
pub async fn retrieve(
31+
&self,
32+
) -> Result<models::StemmingDictionary, Error<stemming_api::GetStemmingDictionaryError>> {
33+
let params = stemming_api::GetStemmingDictionaryParams {
34+
dictionary_id: self.dictionary_id.to_owned(),
35+
};
36+
execute_wrapper!(self, stemming_api::get_stemming_dictionary, params)
37+
}
38+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//! Provides access to the API endpoints for managing stemming.
2+
//!
3+
//! An instance of `Stemming` is created via the `client.stemming()` method.
4+
5+
pub mod dictionaries;
6+
pub mod dictionary;
7+
8+
use super::Client;
9+
use dictionaries::Dictionaries;
10+
use dictionary::Dictionary;
11+
12+
/// Provides methods for managing Typesense stemming.
13+
///
14+
/// This struct is created by calling `client.stemming()`.
15+
pub struct Stemming<'a> {
16+
pub(super) client: &'a Client,
17+
}
18+
19+
impl<'a> Stemming<'a> {
20+
/// Creates a new `Stemming` instance.
21+
#[inline]
22+
pub(super) fn new(client: &'a Client) -> Self {
23+
Self { client }
24+
}
25+
26+
/// Provides access to endpoints for managing the collection of dictionaries.
27+
#[inline]
28+
pub fn dictionaries(&self) -> Dictionaries<'a> {
29+
Dictionaries::new(self.client)
30+
}
31+
32+
/// Provides access to endpoints for managing a single dictionary.
33+
///
34+
/// # Arguments
35+
/// * `dictionary_id` - The ID of the dictionary to manage.
36+
#[inline]
37+
pub fn dictionary(&self, dictionary_id: &'a str) -> Dictionary<'a> {
38+
Dictionary::new(self.client, dictionary_id)
39+
}
40+
}

0 commit comments

Comments
 (0)