Cohere
Cohere 是一家提供自然语言处理模型的加拿大初创公司 该模型帮助公司改善人机交互。
安装和设置
- 安装 Python SDK :
pip install langchain-cohere
获取一个 Cohere api 密钥 并将其设置为环境变量 (COHERE_API_KEY
)
Cohere LangChain 集成
API | 描述 | 端点文档 | 导入 | 示例用法 |
---|---|---|---|---|
聊天 | 构建聊天机器人 | 聊天 | from langchain_cohere import ChatCohere | cohere.ipynb |
大型语言模型 | 生成文本 | 生成 | from langchain_cohere.llms import Cohere | cohere.ipynb |
RAG 检索器 | 连接到外部数据源 | 聊天 + RAG | from langchain.retrievers import CohereRagRetriever | cohere.ipynb |
文本嵌入 | 将字符串嵌入到向量 | 嵌入 | from langchain_cohere import CohereEmbeddings | cohere.ipynb |
重新排序检索器 | 根据相关性对字符串进行排序 | 重新排序 | from langchain.retrievers.document_compressors import CohereRerank | cohere.ipynb |
快速复制示例
聊天
from langchain_cohere import ChatCohere
from langchain_core.messages import HumanMessage
chat = ChatCohere()
messages = [HumanMessage(content="knock knock")]
print(chat.invoke(messages))
使用 Cohere 聊天模型
大型语言模型
from langchain_cohere.llms import Cohere
llm = Cohere()
print(llm.invoke("Come up with a pet name"))
使用 Cohere (遗留) LLM 模型