1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#![warn(missing_docs)]
pub mod completions;
pub mod tokenize;
pub mod translate;
#[macro_use]
extern crate derive_builder;
use std::fmt::Display;
use reqwest::Client;
pub trait IsEngine: Display {
fn is_completion(&self) -> bool {
false
}
fn is_translation(&self) -> bool {
false
}
}
pub struct TextSynthClient {
base_url: String,
client: Client,
}
impl TextSynthClient {
pub fn new_with_endpoint(api_key: &str, endpoint: &str) -> Self {
let mut headers = reqwest::header::HeaderMap::new();
headers.insert(
reqwest::header::AUTHORIZATION,
reqwest::header::HeaderValue::from_str(&format!("Bearer {}", api_key)).unwrap(),
);
let reqwest_client = Client::builder().default_headers(headers);
TextSynthClient {
base_url: endpoint.to_string(),
client: reqwest_client.build().unwrap(),
}
}
pub fn new(api_key: &str) -> Self {
Self::new_with_endpoint(api_key, "https://api.textsynth.com/v1")
}
}