Skip to main content

Documentation Index

Fetch the complete documentation index at: https://nvd-54.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

您当前所在的页面介绍的是 Cohere models as text completion models. Many popular Cohere models are chat completion models.You may be looking for 此页面.
Cohere is a Canadian startup that provides natural language processing models that help companies improve human-machine interactions.
Head to the API reference 查看所有属性和方法的详细文档。

概述

集成详情

本地可序列化JS 支持下载量版本
Coherelangchain-communitybetaPyPI - DownloadsPyPI - Version

设置

The 集成位于 langchain-community package. We also need to install the cohere package itself. We can install these with:

凭证

We’ll need to get a Cohere API key and set the COHERE_API_KEY 环境变量:
import getpass
import os

if "COHERE_API_KEY" not in os.environ:
    os.environ["COHERE_API_KEY"] = getpass.getpass()

安装

pip install -U langchain-community langchain-cohere
It’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()

调用

Cohere supports all LLM functionality:
from langchain_cohere import Cohere
from langchain.messages import HumanMessage
model = Cohere(max_tokens=256, temperature=0.75)
message = "Knock knock"
model.invoke(message)
" Who's there?"
await model.ainvoke(message)
" Who's there?"
for chunk in model.stream(message):
    print(chunk, end="", flush=True)
 Who's there?
model.batch([message])
[" Who's there?"]

API 参考

有关所有 Cohere llm 功能和配置的详细文档,请前往 API reference