uarp_sdk/generated/api/
open_ai_compat.rs1#![allow(unused_imports, clippy::too_many_arguments)]
6
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9
10use crate::client::{Client, Request, NO_BODY, NO_QUERY};
11use crate::error::Result;
12use crate::generated::models;
13use crate::multipart::{field_text, FilePart};
14use crate::util::encode_path;
15
16#[derive(Debug, Clone)]
18pub struct OpenAiCompatApi {
19 pub(crate) client: Client,
20}
21
22impl Client {
23 pub fn open_ai_compat(&self) -> OpenAiCompatApi {
25 OpenAiCompatApi { client: self.clone() }
26 }
27}
28
29impl OpenAiCompatApi {
30 pub async fn chat_completion(&self, body: &models::ChatCompletionRequest) -> Result<serde_json::Value> {
39 self.client
40 .request_json(Request {
41 method: Method::POST,
42 path: "/v1/chat/completions".to_string(),
43 query: NO_QUERY,
44 body: Some(body),
45 headers: Vec::new(),
46 idempotent: false,
47 })
48 .await
49 }
50
51 pub async fn create_response(&self, body: &models::CreateResponseRequest) -> Result<models::CreateResponseResponse> {
60 self.client
61 .request_json(Request {
62 method: Method::POST,
63 path: "/v1/responses".to_string(),
64 query: NO_QUERY,
65 body: Some(body),
66 headers: Vec::new(),
67 idempotent: false,
68 })
69 .await
70 }
71
72 pub async fn embeddings(&self, body: &models::EmbeddingsRequest) -> Result<models::EmbeddingsResponse> {
81 self.client
82 .request_json(Request {
83 method: Method::POST,
84 path: "/v1/embeddings".to_string(),
85 query: NO_QUERY,
86 body: Some(body),
87 headers: Vec::new(),
88 idempotent: false,
89 })
90 .await
91 }
92
93 pub async fn get_response(&self, response_id: &str) -> Result<serde_json::Value> {
97 self.client
98 .request_json(Request {
99 method: Method::GET,
100 path: format!("/v1/responses/{}", encode_path(response_id)),
101 query: NO_QUERY,
102 body: NO_BODY,
103 headers: Vec::new(),
104 idempotent: false,
105 })
106 .await
107 }
108
109 pub async fn list_models(&self) -> Result<models::ListModelsResponse> {
115 self.client
116 .request_json(Request {
117 method: Method::GET,
118 path: "/v1/models".to_string(),
119 query: NO_QUERY,
120 body: NO_BODY,
121 headers: Vec::new(),
122 idempotent: false,
123 })
124 .await
125 }
126}