Cohere
Cohere is a Canadian startup that provides natural language processing models that help companies improve human-machine interactions.
Installation and Setup
- Install the Python SDK :
pip install langchain-cohere
Get a Cohere api key and set it as an environment variable (COHERE_API_KEY
)
Cohere langchain integrations
API | description | Endpoint docs | Import | Example usage |
---|---|---|---|---|
Chat | Build chat bots | chat | from langchain_cohere import ChatCohere | cohere.ipynb |
LLM | Generate text | generate | from langchain_cohere.llms import Cohere | cohere.ipynb |
RAG Retriever | Connect to external data sources | chat + rag | from langchain.retrievers import CohereRagRetriever | cohere.ipynb |
Text Embedding | Embed strings to vectors | embed | from langchain_cohere import CohereEmbeddings | cohere.ipynb |
Rerank Retriever | Rank strings based on relevance | rerank | from langchain.retrievers.document_compressors import CohereRerank | cohere.ipynb |
Quick copy examples
Chat
from langchain_cohere import ChatCohere
from langchain_core.messages import HumanMessage
chat = ChatCohere()
messages = [HumanMessage(content="knock knock")]
print(chat.invoke(messages))
API Reference:HumanMessage
Usage of the Cohere chat model
LLM
from langchain_cohere.llms import Cohere
llm = Cohere()
print(llm.invoke("Come up with a pet name"))
Usage of the Cohere (legacy) LLM model