langfuse_rs/apis/
comments_api.rs

1/*
2 * langfuse
3 *
4 * ## Authentication  Authenticate with the API using [Basic Auth](https://en.wikipedia.org/wiki/Basic_access_authentication), get API keys in the project settings:  - username: Langfuse Public Key - password: Langfuse Secret Key  ## Exports  - OpenAPI spec: https://cloud.langfuse.com/generated/api/openapi.yml - Postman collection: https://cloud.langfuse.com/generated/postman/collection.json
5 *
6 * The version of the OpenAPI document:
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16/// struct for typed errors of method [`comments_create`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CommentsCreateError {
20	Status400(serde_json::Value),
21	Status401(serde_json::Value),
22	Status403(serde_json::Value),
23	Status404(serde_json::Value),
24	Status405(serde_json::Value),
25	UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`comments_get`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum CommentsGetError {
32	Status400(serde_json::Value),
33	Status401(serde_json::Value),
34	Status403(serde_json::Value),
35	Status404(serde_json::Value),
36	Status405(serde_json::Value),
37	UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`comments_get_by_id`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum CommentsGetByIdError {
44	Status400(serde_json::Value),
45	Status401(serde_json::Value),
46	Status403(serde_json::Value),
47	Status404(serde_json::Value),
48	Status405(serde_json::Value),
49	UnknownValue(serde_json::Value),
50}
51
52/// Create a comment. Comments may be attached to different object types (trace, observation, session, prompt).
53pub async fn comments_create(
54	configuration: &configuration::Configuration,
55	create_comment_request: models::CreateCommentRequest,
56) -> Result<models::CreateCommentResponse, Error<CommentsCreateError>> {
57	// add a prefix to parameters to efficiently prevent name collisions
58	let p_create_comment_request = create_comment_request;
59
60	let uri_str = format!("{}/api/public/comments", configuration.base_path);
61	let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
62
63	if let Some(ref user_agent) = configuration.user_agent {
64		req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
65	}
66	if let Some(ref auth_conf) = configuration.basic_auth {
67		req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
68	};
69	req_builder = req_builder.json(&p_create_comment_request);
70
71	let req = req_builder.build()?;
72	let resp = configuration.client.execute(req).await?;
73
74	let status = resp.status();
75
76	if !status.is_client_error() && !status.is_server_error() {
77		let content = resp.text().await?;
78		serde_json::from_str(&content).map_err(Error::from)
79	} else {
80		let content = resp.text().await?;
81		let entity: Option<CommentsCreateError> = serde_json::from_str(&content).ok();
82		Err(Error::ResponseError(ResponseContent { status, content, entity }))
83	}
84}
85
86/// Get all comments
87pub async fn comments_get(
88	configuration: &configuration::Configuration,
89	page: Option<i32>,
90	limit: Option<i32>,
91	object_type: Option<&str>,
92	object_id: Option<&str>,
93	author_user_id: Option<&str>,
94) -> Result<models::GetCommentsResponse, Error<CommentsGetError>> {
95	// add a prefix to parameters to efficiently prevent name collisions
96	let p_page = page;
97	let p_limit = limit;
98	let p_object_type = object_type;
99	let p_object_id = object_id;
100	let p_author_user_id = author_user_id;
101
102	let uri_str = format!("{}/api/public/comments", configuration.base_path);
103	let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
104
105	if let Some(ref param_value) = p_page {
106		req_builder = req_builder.query(&[("page", &param_value.to_string())]);
107	}
108	if let Some(ref param_value) = p_limit {
109		req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
110	}
111	if let Some(ref param_value) = p_object_type {
112		req_builder = req_builder.query(&[("objectType", &param_value.to_string())]);
113	}
114	if let Some(ref param_value) = p_object_id {
115		req_builder = req_builder.query(&[("objectId", &param_value.to_string())]);
116	}
117	if let Some(ref param_value) = p_author_user_id {
118		req_builder = req_builder.query(&[("authorUserId", &param_value.to_string())]);
119	}
120	if let Some(ref user_agent) = configuration.user_agent {
121		req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
122	}
123	if let Some(ref auth_conf) = configuration.basic_auth {
124		req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
125	};
126
127	let req = req_builder.build()?;
128	let resp = configuration.client.execute(req).await?;
129
130	let status = resp.status();
131
132	if !status.is_client_error() && !status.is_server_error() {
133		let content = resp.text().await?;
134		serde_json::from_str(&content).map_err(Error::from)
135	} else {
136		let content = resp.text().await?;
137		let entity: Option<CommentsGetError> = serde_json::from_str(&content).ok();
138		Err(Error::ResponseError(ResponseContent { status, content, entity }))
139	}
140}
141
142/// Get a comment by id
143pub async fn comments_get_by_id(
144	configuration: &configuration::Configuration,
145	comment_id: &str,
146) -> Result<models::Comment, Error<CommentsGetByIdError>> {
147	// add a prefix to parameters to efficiently prevent name collisions
148	let p_comment_id = comment_id;
149
150	let uri_str = format!(
151		"{}/api/public/comments/{commentId}",
152		configuration.base_path,
153		commentId = crate::apis::urlencode(p_comment_id)
154	);
155	let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
156
157	if let Some(ref user_agent) = configuration.user_agent {
158		req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
159	}
160	if let Some(ref auth_conf) = configuration.basic_auth {
161		req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
162	};
163
164	let req = req_builder.build()?;
165	let resp = configuration.client.execute(req).await?;
166
167	let status = resp.status();
168
169	if !status.is_client_error() && !status.is_server_error() {
170		let content = resp.text().await?;
171		serde_json::from_str(&content).map_err(Error::from)
172	} else {
173		let content = resp.text().await?;
174		let entity: Option<CommentsGetByIdError> = serde_json::from_str(&content).ok();
175		Err(Error::ResponseError(ResponseContent { status, content, entity }))
176	}
177}