rig_core/client/
cohere.rs1use crate::client::macros::http_client;
5use crate::driver::Model;
6
7use crate::providers::cohere::wire::{Chat, CohereConfig, Embeddings, ImageEmbeddings};
8
9http_client!(
10 Cohere,
13 CohereConfig
14);
15
16impl Cohere {
17 #[cfg(feature = "reqwest")]
20 #[cfg_attr(docsrs, doc(cfg(feature = "reqwest")))]
21 pub fn new(api_key: impl Into<crate::wire::Secret>) -> Self {
22 CohereConfig::new(api_key).client()
23 }
24
25 #[cfg(feature = "reqwest")]
27 #[cfg_attr(docsrs, doc(cfg(feature = "reqwest")))]
28 pub fn from_env() -> Result<Self, crate::client::env::EnvError> {
29 Ok(CohereConfig::from_env()?.client())
30 }
31
32 pub fn completion(&self, model: impl Into<String>) -> Model<Chat> {
34 self.model(self.config.completion(model))
35 }
36
37 pub fn embedding(&self, model: impl Into<String>, ndims: Option<usize>) -> Model<Embeddings> {
40 self.model(self.config.embedding(model, ndims))
41 }
42
43 pub fn image_embedding(&self) -> Model<ImageEmbeddings> {
46 self.model(self.config.image_embedding())
47 }
48}