SuperAPI AI 工具集

cohere-python-sdk

编程与开发

查看项目

更新于 10-16 08:10

技能介绍

用途:面向使用 Python 构建 Cohere Command 系列模型应用的开发者,提供原生 Python SDK 的调用参考。

主要能力:支持同步 ClientV2 与异步 AsyncClientV2;chat 接口支持系统消息、多轮对话、temperature、max_tokens、p、k、seed、stop_sequences 等参数;command-a-reasoning-2025 模型可通过 thinking 参数开启或关闭推理并设置 budget_tokens;chat_stream 支持流式事件(message-start、content-delta、message-end、tool-plan-delta、tool-call-start);工具调用支持定义 function、执行 tool_calls 并回传 tool 结果,tool_choice 可选 AUTO、REQUIRED、NONE,strict_tools=True 可减少工具名称与参数幻觉;结构化输出支持 response_format 的 json_object 与 json_schema;RAG 可传入 documents 并读取 citations;支持 safety_mode(CONTEXTUAL、STRICT、OFF);可捕获 cohere.core.ApiError 处理错误。

使用方式:导入 cohere,使用 co.ClientV2()(自动读取 CO_API_KEY 环境变量)或显式传入 api_key、base_url;异步使用 cohere.AsyncClientV2()。调用 co.chat(...) 或 co.chat_stream(...),按需传入 model、messages、tools、documents、response_format、safety_mode 等参数。

适用场景:Python 聊天应用、流式交互、函数调用与多步智能体、结构化数据抽取、基于文档的问答与引用。

限制:本资料为第三方非官方参考;具体模型可用性、定价、配额及服务条款需以 Cohere 官方文档为准,资料中未提供这些信息。