Skip to main content

rig_core/providers/together/
client.rs

1use crate::client::{self, BearerAuth, DebugExt, Provider};
2
3// ================================================================
4// Together AI Client
5// ================================================================
6const TOGETHER_AI_BASE_URL: &str = "https://api.together.xyz";
7
8#[derive(Debug, Default, Clone, Copy)]
9pub struct TogetherExt;
10#[derive(Debug, Default, Clone, Copy)]
11pub struct TogetherExtBuilder;
12
13type TogetherApiKey = BearerAuth;
14
15pub type Client<H = reqwest::Client> = client::Client<TogetherExt, H>;
16pub type ClientBuilder<H = crate::markers::Missing> =
17    client::ClientBuilder<TogetherExtBuilder, TogetherApiKey, H>;
18
19impl Provider for TogetherExt {
20    type Builder = TogetherExtBuilder;
21
22    const VERIFY_PATH: &'static str = "/models";
23}
24
25impl DebugExt for TogetherExt {}
26
27impl crate::providers::openai::completion::OpenAICompatibleProvider for TogetherExt {
28    const PROVIDER_NAME: &'static str = "together";
29
30    type StreamingUsage = crate::providers::openai::Usage;
31
32    // Together's structured-output support is model-dependent; keep the
33    // pre-migration behavior of dropping `output_schema` with a warning.
34    const SUPPORTS_RESPONSE_FORMAT: bool = false;
35
36    type Response = crate::providers::openai::CompletionResponse;
37
38    // The client base URL is the bare host; embeddings build their own v1 path.
39    fn completion_path(&self, _model: &str) -> String {
40        "/v1/chat/completions".to_string()
41    }
42}
43
44client::impl_capabilities!(
45    TogetherExt,
46    completion = super::CompletionModel<H>,
47    embeddings = super::EmbeddingModel<H>,
48);
49
50client::impl_default_provider_builder!(
51    TogetherExtBuilder => TogetherExt,
52    api_key = TogetherApiKey,
53    base_url = TOGETHER_AI_BASE_URL,
54);
55
56client::impl_provider_client!(Client, input = String, api_key_env = "TOGETHER_API_KEY");
57
58#[cfg(test)]
59mod tests {
60    #[test]
61    fn test_client_initialization() {
62        let _client =
63            crate::providers::together::Client::new("dummy-key").expect("Client::new() failed");
64        let _client_from_builder = crate::providers::together::Client::builder()
65            .api_key("dummy-key")
66            .build()
67            .expect("Client::builder() failed");
68    }
69}