typesense_rs/apis/
conversations_api.rs

1// Typesense API
2//
3// An open source search engine for building delightful search experiences.
4//
5// The version of the OpenAPI document: 27.0
6//
7// Generated by: https://openapi-generator.tech
8
9use std::sync::Arc;
10
11use async_trait::async_trait;
12use reqwest;
13use serde::{Deserialize, Serialize};
14
15use super::{configuration, Error};
16use crate::apis::ResponseContent;
17use crate::models;
18
19#[async_trait]
20pub trait ConversationsApi: Send + Sync {
21	async fn create_conversation_model(
22		&self,
23		params: CreateConversationModelParams,
24	) -> Result<models::ConversationModelSchema, Error<CreateConversationModelError>>;
25	async fn delete_conversation_model(
26		&self,
27		params: DeleteConversationModelParams,
28	) -> Result<models::ConversationModelSchema, Error<DeleteConversationModelError>>;
29	async fn retrieve_all_conversation_models(
30		&self,
31	) -> Result<Vec<models::ConversationModelSchema>, Error<RetrieveAllConversationModelsError>>;
32	async fn retrieve_conversation_model(
33		&self,
34		params: RetrieveConversationModelParams,
35	) -> Result<models::ConversationModelSchema, Error<RetrieveConversationModelError>>;
36	async fn update_conversation_model(
37		&self,
38		params: UpdateConversationModelParams,
39	) -> Result<models::ConversationModelSchema, Error<UpdateConversationModelError>>;
40}
41
42pub struct ConversationsApiClient {
43	configuration: Arc<configuration::Configuration>,
44}
45
46impl ConversationsApiClient {
47	pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
48		Self { configuration }
49	}
50}
51
52/// struct for passing parameters to the method [`create_conversation_model`]
53#[derive(Clone, Debug)]
54#[cfg_attr(feature = "bon", derive(::bon::Builder))]
55pub struct CreateConversationModelParams {
56	pub conversation_model_create_schema: models::ConversationModelCreateSchema,
57}
58
59/// struct for passing parameters to the method [`delete_conversation_model`]
60#[derive(Clone, Debug)]
61#[cfg_attr(feature = "bon", derive(::bon::Builder))]
62pub struct DeleteConversationModelParams {
63	/// The id of the conversation model to delete
64	pub model_id: String,
65}
66
67/// struct for passing parameters to the method [`retrieve_conversation_model`]
68#[derive(Clone, Debug)]
69#[cfg_attr(feature = "bon", derive(::bon::Builder))]
70pub struct RetrieveConversationModelParams {
71	/// The id of the conversation model to retrieve
72	pub model_id: String,
73}
74
75/// struct for passing parameters to the method [`update_conversation_model`]
76#[derive(Clone, Debug)]
77#[cfg_attr(feature = "bon", derive(::bon::Builder))]
78pub struct UpdateConversationModelParams {
79	/// The id of the conversation model to update
80	pub model_id: String,
81	pub conversation_model_update_schema: models::ConversationModelUpdateSchema,
82}
83
84#[async_trait]
85impl ConversationsApi for ConversationsApiClient {
86	/// Create a Conversation Model
87	async fn create_conversation_model(
88		&self,
89		params: CreateConversationModelParams,
90	) -> Result<models::ConversationModelSchema, Error<CreateConversationModelError>> {
91		let CreateConversationModelParams {
92			conversation_model_create_schema,
93		} = params;
94
95		let local_var_configuration = &self.configuration;
96
97		let local_var_client = &local_var_configuration.client;
98
99		let local_var_uri_str = format!("{}/conversations/models", local_var_configuration.base_path);
100		let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
101
102		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
103			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
104		}
105		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
106			let local_var_key = local_var_apikey.key.clone();
107			let local_var_value = match local_var_apikey.prefix {
108				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
109				None => local_var_key,
110			};
111			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
112		};
113		local_var_req_builder = local_var_req_builder.json(&conversation_model_create_schema);
114
115		let local_var_req = local_var_req_builder.build()?;
116		let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118		let local_var_status = local_var_resp.status();
119		let local_var_content = local_var_resp.text().await?;
120
121		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122			serde_json::from_str(&local_var_content).map_err(Error::from)
123		} else {
124			let local_var_entity: Option<CreateConversationModelError> = serde_json::from_str(&local_var_content).ok();
125			let local_var_error = ResponseContent {
126				status: local_var_status,
127				content: local_var_content,
128				entity: local_var_entity,
129			};
130			Err(Error::ResponseError(local_var_error))
131		}
132	}
133
134	/// Delete a conversation model
135	async fn delete_conversation_model(
136		&self,
137		params: DeleteConversationModelParams,
138	) -> Result<models::ConversationModelSchema, Error<DeleteConversationModelError>> {
139		let DeleteConversationModelParams { model_id } = params;
140
141		let local_var_configuration = &self.configuration;
142
143		let local_var_client = &local_var_configuration.client;
144
145		let local_var_uri_str = format!(
146			"{}/conversations/models/{modelId}",
147			local_var_configuration.base_path,
148			modelId = crate::apis::urlencode(model_id)
149		);
150		let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
151
152		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
153			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
154		}
155		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
156			let local_var_key = local_var_apikey.key.clone();
157			let local_var_value = match local_var_apikey.prefix {
158				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
159				None => local_var_key,
160			};
161			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
162		};
163
164		let local_var_req = local_var_req_builder.build()?;
165		let local_var_resp = local_var_client.execute(local_var_req).await?;
166
167		let local_var_status = local_var_resp.status();
168		let local_var_content = local_var_resp.text().await?;
169
170		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
171			serde_json::from_str(&local_var_content).map_err(Error::from)
172		} else {
173			let local_var_entity: Option<DeleteConversationModelError> = serde_json::from_str(&local_var_content).ok();
174			let local_var_error = ResponseContent {
175				status: local_var_status,
176				content: local_var_content,
177				entity: local_var_entity,
178			};
179			Err(Error::ResponseError(local_var_error))
180		}
181	}
182
183	/// Retrieve all conversation models
184	async fn retrieve_all_conversation_models(
185		&self,
186	) -> Result<Vec<models::ConversationModelSchema>, Error<RetrieveAllConversationModelsError>> {
187		let local_var_configuration = &self.configuration;
188
189		let local_var_client = &local_var_configuration.client;
190
191		let local_var_uri_str = format!("{}/conversations/models", local_var_configuration.base_path);
192		let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
193
194		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
195			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
196		}
197		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
198			let local_var_key = local_var_apikey.key.clone();
199			let local_var_value = match local_var_apikey.prefix {
200				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
201				None => local_var_key,
202			};
203			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
204		};
205
206		let local_var_req = local_var_req_builder.build()?;
207		let local_var_resp = local_var_client.execute(local_var_req).await?;
208
209		let local_var_status = local_var_resp.status();
210		let local_var_content = local_var_resp.text().await?;
211
212		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
213			serde_json::from_str(&local_var_content).map_err(Error::from)
214		} else {
215			let local_var_entity: Option<RetrieveAllConversationModelsError> = serde_json::from_str(&local_var_content).ok();
216			let local_var_error = ResponseContent {
217				status: local_var_status,
218				content: local_var_content,
219				entity: local_var_entity,
220			};
221			Err(Error::ResponseError(local_var_error))
222		}
223	}
224
225	/// Retrieve a conversation model
226	async fn retrieve_conversation_model(
227		&self,
228		params: RetrieveConversationModelParams,
229	) -> Result<models::ConversationModelSchema, Error<RetrieveConversationModelError>> {
230		let RetrieveConversationModelParams { model_id } = params;
231
232		let local_var_configuration = &self.configuration;
233
234		let local_var_client = &local_var_configuration.client;
235
236		let local_var_uri_str = format!(
237			"{}/conversations/models/{modelId}",
238			local_var_configuration.base_path,
239			modelId = crate::apis::urlencode(model_id)
240		);
241		let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
242
243		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
244			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
245		}
246		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
247			let local_var_key = local_var_apikey.key.clone();
248			let local_var_value = match local_var_apikey.prefix {
249				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
250				None => local_var_key,
251			};
252			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
253		};
254
255		let local_var_req = local_var_req_builder.build()?;
256		let local_var_resp = local_var_client.execute(local_var_req).await?;
257
258		let local_var_status = local_var_resp.status();
259		let local_var_content = local_var_resp.text().await?;
260
261		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
262			serde_json::from_str(&local_var_content).map_err(Error::from)
263		} else {
264			let local_var_entity: Option<RetrieveConversationModelError> = serde_json::from_str(&local_var_content).ok();
265			let local_var_error = ResponseContent {
266				status: local_var_status,
267				content: local_var_content,
268				entity: local_var_entity,
269			};
270			Err(Error::ResponseError(local_var_error))
271		}
272	}
273
274	/// Update a conversation model
275	async fn update_conversation_model(
276		&self,
277		params: UpdateConversationModelParams,
278	) -> Result<models::ConversationModelSchema, Error<UpdateConversationModelError>> {
279		let UpdateConversationModelParams {
280			model_id,
281			conversation_model_update_schema,
282		} = params;
283
284		let local_var_configuration = &self.configuration;
285
286		let local_var_client = &local_var_configuration.client;
287
288		let local_var_uri_str = format!(
289			"{}/conversations/models/{modelId}",
290			local_var_configuration.base_path,
291			modelId = crate::apis::urlencode(model_id)
292		);
293		let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
294
295		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
296			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
297		}
298		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
299			let local_var_key = local_var_apikey.key.clone();
300			let local_var_value = match local_var_apikey.prefix {
301				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
302				None => local_var_key,
303			};
304			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
305		};
306		local_var_req_builder = local_var_req_builder.json(&conversation_model_update_schema);
307
308		let local_var_req = local_var_req_builder.build()?;
309		let local_var_resp = local_var_client.execute(local_var_req).await?;
310
311		let local_var_status = local_var_resp.status();
312		let local_var_content = local_var_resp.text().await?;
313
314		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
315			serde_json::from_str(&local_var_content).map_err(Error::from)
316		} else {
317			let local_var_entity: Option<UpdateConversationModelError> = serde_json::from_str(&local_var_content).ok();
318			let local_var_error = ResponseContent {
319				status: local_var_status,
320				content: local_var_content,
321				entity: local_var_entity,
322			};
323			Err(Error::ResponseError(local_var_error))
324		}
325	}
326}
327
328/// struct for typed errors of method [`create_conversation_model`]
329#[derive(Debug, Clone, Serialize, Deserialize)]
330#[serde(untagged)]
331pub enum CreateConversationModelError {
332	Status400(models::ApiResponse),
333	UnknownValue(serde_json::Value),
334}
335
336/// struct for typed errors of method [`delete_conversation_model`]
337#[derive(Debug, Clone, Serialize, Deserialize)]
338#[serde(untagged)]
339pub enum DeleteConversationModelError {
340	UnknownValue(serde_json::Value),
341}
342
343/// struct for typed errors of method [`retrieve_all_conversation_models`]
344#[derive(Debug, Clone, Serialize, Deserialize)]
345#[serde(untagged)]
346pub enum RetrieveAllConversationModelsError {
347	UnknownValue(serde_json::Value),
348}
349
350/// struct for typed errors of method [`retrieve_conversation_model`]
351#[derive(Debug, Clone, Serialize, Deserialize)]
352#[serde(untagged)]
353pub enum RetrieveConversationModelError {
354	UnknownValue(serde_json::Value),
355}
356
357/// struct for typed errors of method [`update_conversation_model`]
358#[derive(Debug, Clone, Serialize, Deserialize)]
359#[serde(untagged)]
360pub enum UpdateConversationModelError {
361	UnknownValue(serde_json::Value),
362}