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