本页还没有译文
本页 16 段还没译成한국어,下面显示的是英文原文。Cohere integration
还没翻译译自英文(docs.langchain.com)本页 16 段都还没译
Warning
You are currently on a page documenting the use of Cohere models as text completion models. Many popular Cohere models are chat completion models.
You may be looking for this page instead.
Cohere is a Canadian startup that provides natural language processing models that help companies improve human-machine interactions.
Head to the API reference for detailed documentation of all attributes and methods.
Setup
The integration lives in the langchain-community package. We also need to install the cohere package itself. We can install these with:
Warning
The langchain-community package is no longer maintained. Examples that import from langchain_community may be outdated or broken. Use with caution.
Credentials
We'll need to get a Cohere API key and set the COHERE_API_KEY environment variable:
import getpass
import os
if "COHERE_API_KEY" not in os.environ:
os.environ["COHERE_API_KEY"] = getpass.getpass()Installation
pip install -U langchain-community langchain-cohereIt's also helpful (but not needed) to set up LangSmith for best-in-class observability
os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()Invocation
Cohere supports all LLM functionality:
from langchain_cohere import Cohere
from langchain.messages import HumanMessagemodel = Cohere(max_tokens=256, temperature=0.75)message = "Knock knock"
model.invoke(message)" Who's there?"await model.ainvoke(message)" Who's there?"stream = model.stream_events(message, version="v3")
for token in stream.text:
print(token, end="", flush=True) Who's there?model.batch([message])[" Who's there?"]API reference
For detailed documentation of all Cohere llm features and configurations head to the API reference