blackman_client/apis/feedback_api.rs
1/*
2 * Blackman AI API
3 *
4 * A transparent AI API proxy that optimizes token usage to reduce costs. ## Authentication Blackman AI supports two authentication methods: ### 1. API Key (Recommended for integrations) Use the API key created from your dashboard: ```bash curl -X POST https://app.useblackman.ai/v1/completions \\ -H \"Authorization: Bearer sk_your_api_key_here\" \\ -H \"Content-Type: application/json\" \\ -d '{\"provider\": \"OpenAI\", \"model\": \"gpt-4\", \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}]}' ``` ### 2. JWT Token (For web UI) Obtain a JWT token by logging in: ```bash curl -X POST https://app.useblackman.ai/v1/auth/login \\ -H \"Content-Type: application/json\" \\ -d '{\"email\": \"user@example.com\", \"password\": \"yourpassword\"}' ``` Then use the token: ```bash curl -X POST https://app.useblackman.ai/v1/completions \\ -H \"Authorization: Bearer your_jwt_token\" \\ -H \"Content-Type: application/json\" \\ -d '{...}' ``` ### Provider API Keys (Optional) You can optionally provide your own LLM provider API key via the `X-Provider-Api-Key` header, or store it in your account settings. ## Client SDKs Auto-generated SDKs are available for 10 languages: - **TypeScript**: [View Docs](https://github.com/blackman-ai/typescript-sdk) - **Python**: [View Docs](https://github.com/blackman-ai/python-sdk) - **Go**: [View Docs](https://github.com/blackman-ai/go-sdk) - **Java**: [View Docs](https://github.com/blackman-ai/java-sdk) - **Ruby**: [View Docs](https://github.com/blackman-ai/ruby-sdk) - **PHP**: [View Docs](https://github.com/blackman-ai/php-sdk) - **C#**: [View Docs](https://github.com/blackman-ai/csharp-sdk) - **Rust**: [View Docs](https://github.com/blackman-ai/rust-sdk) - **Swift**: [View Docs](https://github.com/blackman-ai/swift-sdk) - **Kotlin**: [View Docs](https://github.com/blackman-ai/kotlin-sdk) All SDKs are generated from this OpenAPI spec using [openapi-generator](https://openapi-generator.tech). ## Quick Start ```python # Python example with API key import blackman_client from blackman_client import CompletionRequest configuration = blackman_client.Configuration( host=\"http://localhost:8080\", access_token=\"sk_your_api_key_here\" # Your Blackman API key ) with blackman_client.ApiClient(configuration) as api_client: api = blackman_client.CompletionsApi(api_client) response = api.completions( CompletionRequest( provider=\"OpenAI\", model=\"gpt-4o\", messages=[{\"role\": \"user\", \"content\": \"Hello!\"}] ) ) ```
5 *
6 * The version of the OpenAPI document: 0.1.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`submit_feedback`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum SubmitFeedbackError {
22 Status401(),
23 Status500(),
24 UnknownValue(serde_json::Value),
25}
26
27
28pub async fn submit_feedback(configuration: &configuration::Configuration, submit_feedback_request: models::SubmitFeedbackRequest) -> Result<models::SubmitFeedbackResponse, Error<SubmitFeedbackError>> {
29 // add a prefix to parameters to efficiently prevent name collisions
30 let p_submit_feedback_request = submit_feedback_request;
31
32 let uri_str = format!("{}/v1/feedback", configuration.base_path);
33 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
34
35 if let Some(ref user_agent) = configuration.user_agent {
36 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
37 }
38 if let Some(ref token) = configuration.bearer_access_token {
39 req_builder = req_builder.bearer_auth(token.to_owned());
40 };
41 req_builder = req_builder.json(&p_submit_feedback_request);
42
43 let req = req_builder.build()?;
44 let resp = configuration.client.execute(req).await?;
45
46 let status = resp.status();
47 let content_type = resp
48 .headers()
49 .get("content-type")
50 .and_then(|v| v.to_str().ok())
51 .unwrap_or("application/octet-stream");
52 let content_type = super::ContentType::from(content_type);
53
54 if !status.is_client_error() && !status.is_server_error() {
55 let content = resp.text().await?;
56 match content_type {
57 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
58 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SubmitFeedbackResponse`"))),
59 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SubmitFeedbackResponse`")))),
60 }
61 } else {
62 let content = resp.text().await?;
63 let entity: Option<SubmitFeedbackError> = serde_json::from_str(&content).ok();
64 Err(Error::ResponseError(ResponseContent { status, content, entity }))
65 }
66}
67