pub struct Cohere { /* private fields */ }
Expand description
Cohere Rust SDK to build natural language understanding and generation into your product with a few lines of code.
Implementations§
Source§impl Cohere
impl Cohere
pub fn new<U: Into<String>, K: Into<String>>(api_url: U, api_key: K) -> Self
Sourcepub async fn check_api_key(&self) -> Result<(), CohereApiError>
pub async fn check_api_key(&self) -> Result<(), CohereApiError>
Verify that the Cohere API key being used is valid
Sourcepub async fn generate<'input>(
&self,
request: &GenerateRequest<'input>,
) -> Result<Vec<Generation>, CohereApiError>
pub async fn generate<'input>( &self, request: &GenerateRequest<'input>, ) -> Result<Vec<Generation>, CohereApiError>
Generates realistic text conditioned on a given input.
Sourcepub async fn chat<'input>(
&self,
request: &ChatRequest<'input>,
) -> Result<Receiver<Result<ChatStreamResponse, CohereStreamError>>, CohereApiError>
pub async fn chat<'input>( &self, request: &ChatRequest<'input>, ) -> Result<Receiver<Result<ChatStreamResponse, CohereStreamError>>, CohereApiError>
Chat with Cohere’s LLM
Sourcepub async fn embed<'input>(
&self,
request: &EmbedRequest<'input>,
) -> Result<Vec<Vec<f64>>, CohereApiError>
pub async fn embed<'input>( &self, request: &EmbedRequest<'input>, ) -> Result<Vec<Vec<f64>>, CohereApiError>
Returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents. Embeddings can be used to create text classifiers as well as empower semantic search.
Sourcepub async fn classify<'input>(
&self,
request: &ClassifyRequest<'input>,
) -> Result<Vec<Classification>, CohereApiError>
pub async fn classify<'input>( &self, request: &ClassifyRequest<'input>, ) -> Result<Vec<Classification>, CohereApiError>
Makes a prediction about which label fits the specified text inputs best. To make a prediction, classify uses the provided examples of text + label pairs as a reference.
Sourcepub async fn tokenize<'input>(
&self,
request: &TokenizeRequest<'input>,
) -> Result<TokenizeResponse, CohereApiError>
pub async fn tokenize<'input>( &self, request: &TokenizeRequest<'input>, ) -> Result<TokenizeResponse, CohereApiError>
Splits input text into smaller units called tokens using byte-pair encoding (BPE).
Sourcepub async fn detokenize<'input>(
&self,
request: &DetokenizeRequest<'input>,
) -> Result<String, CohereApiError>
pub async fn detokenize<'input>( &self, request: &DetokenizeRequest<'input>, ) -> Result<String, CohereApiError>
Takes tokens using byte-pair encoding and returns their text representation.
Sourcepub async fn rerank<'input>(
&self,
request: &ReRankRequest<'input>,
) -> Result<Vec<ReRankResult>, CohereApiError>
pub async fn rerank<'input>( &self, request: &ReRankRequest<'input>, ) -> Result<Vec<ReRankResult>, CohereApiError>
Takes a query plus an list of texts and return an ordered array with each text assigned a relevance score.