LlamaIndex LLMs Cohere

raw JSON →
0.8.0 verified Sat May 09 auth: no python

Integration between LlamaIndex and Cohere's language models, enabling the use of Cohere's command and embed models within LlamaIndex workflows. Current version 0.8.0, supporting Python >=3.10. Release cadence is aligned with llama-index core updates, approximately bi-weekly.

pip install llama-index-llms-cohere
error ImportError: cannot import name 'Cohere' from 'llama_index.llms.cohere'
cause Incorrect import statement trying to import from legacy path.
fix
Use 'from llama_index.llms.cohere import Cohere' (capital C, nested import).
error cohere.core.api_error.ApiError: Status code 401: unauthorized
cause Missing or invalid API key.
fix
Set the environment variable COHERE_API_KEY to your valid Cohere API key.
deprecated The 'cohere' model parameter as string may be deprecated in favor of specific model classes. Always check the latest supported model names.
fix Use explicit model names like 'command-r', 'command-r-plus', or 'command-light'.
gotcha Cohere API key must be set via environment variable COHERE_API_KEY or passed directly. Missing key raises a non-obvious authentication error.
fix Set COHERE_API_KEY in environment or pass api_key parameter.
breaking Breaking import path change from legacy llama_index.llms.cohere to llama_index.llms.cohere.Cohere. Previous imports may fail.
fix Use from llama_index.llms.cohere import Cohere (capitalized class name).

Instantiate Cohere LLM and generate a completion.

import os
from llama_index.llms.cohere import Cohere

api_key = os.environ.get('COHERE_API_KEY', '')
llm = Cohere(model='command-r', api_key=api_key)
response = llm.complete('Hello, how are you?')
print(response.text)