跳到内容

CohereLLM

使用异步客户端进行并发文本生成的 Cohere API 实现。

属性

  • model: 要用于生成的 Cohere API 中的模型名称。

  • base_url: 用于 Cohere API 请求的基础 URL。默认为 "https://api.cohere.ai/v1"

  • api_key: 用于验证对 Cohere API 请求的 API 密钥。默认为 COHERE_API_KEY 环境变量的值。

  • timeout: 等待 API 响应的最长时间(秒)。默认为 120

  • client_name: 用于 API 请求的客户端名称。默认为 "distilabel"

  • structured_output: 一个字典,包含使用 instructor 的结构化输出配置。您可以查看 distilabel.steps.tasks.structured_outputs.instructor 中的 InstructorStructuredOutputType 的字典结构。

  • _ChatMessage: 来自 cohere 包的 ChatMessage 类。

  • _aclient: 来自 cohere 包的 AsyncClient 客户端。

运行时参数

  • base_url: 用于 Cohere API 请求的基础 URL。默认为 "https://api.cohere.ai/v1"

  • api_key: 用于验证对 Cohere API 请求的 API 密钥。默认为 COHERE_API_KEY 环境变量的值。

  • timeout: 等待 API 响应的最长时间(秒)。默认为 120

  • client_name: 用于 API 请求的客户端名称。默认为 "distilabel"

示例

生成文本

from distilabel.models.llms import CohereLLM

llm = CohereLLM(model="CohereForAI/c4ai-command-r-plus")

llm.load()

# Call the model
output = llm.generate_outputs(inputs=[[{"role": "user", "content": "Hello world!"}]])

Generate structured data: