walrus_model/remote/openai/
mod.rs1use compact_str::CompactString;
7use reqwest::{Client, header::HeaderMap};
8
9mod provider;
10mod request;
11
12pub mod endpoint {
14 pub const OPENAI: &str = "https://api.openai.com/v1/chat/completions";
16 pub const DEEPSEEK: &str = "https://api.deepseek.com/chat/completions";
18 pub const GROK: &str = "https://api.x.ai/v1/chat/completions";
20 pub const QWEN: &str = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions";
22 pub const KIMI: &str = "https://api.moonshot.cn/v1/chat/completions";
24 pub const OLLAMA: &str = "http://localhost:11434/v1/chat/completions";
26}
27
28#[derive(Clone)]
30pub struct OpenAI {
31 pub client: Client,
33 headers: HeaderMap,
35 endpoint: String,
37 model: CompactString,
39}
40
41impl OpenAI {
42 pub fn custom(client: Client, key: &str, endpoint: &str, model: &str) -> anyhow::Result<Self> {
44 use reqwest::header;
45 let mut headers = HeaderMap::new();
46 headers.insert(header::CONTENT_TYPE, "application/json".parse()?);
47 headers.insert(header::ACCEPT, "application/json".parse()?);
48 headers.insert(header::AUTHORIZATION, format!("Bearer {key}").parse()?);
49 Ok(Self {
50 client,
51 headers,
52 endpoint: endpoint.to_owned(),
53 model: CompactString::from(model),
54 })
55 }
56
57 pub fn no_auth(client: Client, endpoint: &str, model: &str) -> Self {
59 use reqwest::header::{self, HeaderValue};
60 let mut headers = HeaderMap::new();
61 headers.insert(
62 header::CONTENT_TYPE,
63 HeaderValue::from_static("application/json"),
64 );
65 headers.insert(header::ACCEPT, HeaderValue::from_static("application/json"));
66 Self {
67 client,
68 headers,
69 endpoint: endpoint.to_owned(),
70 model: CompactString::from(model),
71 }
72 }
73}