cohere_client#
Cohere ModelClient integration.
Classes
|
A component wrapper for the Cohere API. |
- class CohereAPIClient(api_key: str | None = None)[source]#
Bases:
ModelClient
A component wrapper for the Cohere API.
Visit https://docs.cohere.com/ for more api details.
References: - Cohere reranker: https://docs.cohere.com/reference/rerank
Tested Cohere models: 6/16/2024 - rerank-english-v3.0, rerank-multilingual-v3.0, rerank-english-v2.0, rerank-multilingual-v2.0
Note
For all ModelClient integration, such as CohereAPIClient, if you want to subclass CohereAPIClient, you need to import it from the module directly.
from adalflow.components.model_client.cohere_client import CohereAPIClient
instead of using the lazy import with:
from adalflow.components.model_client import CohereAPIClient
- convert_inputs_to_api_kwargs(input: Any | None = None, model_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED) Dict [source]#
- For rerank model, expect model_kwargs to have the following keys:
model: str, query: str, documents: List[str], top_n: int,
- call(api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED)[source]#
Subclass use this to call the API with the sync client. model_type: this decides which API, such as chat.completions or embeddings for OpenAI. api_kwargs: all the arguments that the API call needs, subclass should implement this method.
Additionally in subclass you can implement the error handling and retry logic here. See OpenAIClient for example.