elikoga_textsynth/
lib.rs

1#![warn(missing_docs)]
2//! TextSynth API Crate
3
4pub 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
15/// Engine trait,
16pub trait IsEngine: Display {
17    /// Returns wether it is a completion engine or not.
18    fn is_completion(&self) -> bool {
19        false
20    }
21    /// Returns wether it is a translation engine or not.
22    fn is_translation(&self) -> bool {
23        false
24    }
25}
26
27/// TextSynth API Client
28pub struct TextSynthClient {
29    /// endpoint of TextSynth API
30    base_url: String,
31    /// Client for making requests to the TextSynth API
32    client: Client,
33}
34
35impl TextSynthClient {
36    /// Create a new TextSynth API Client with a custom endpoint
37    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    /// Create a new TextSynth API Client
51    pub fn new(api_key: &str) -> Self {
52        Self::new_with_endpoint(api_key, "https://api.textsynth.com/v1")
53    }
54}