Cohere
    Cohere
    • 关于 Cohere
    • 团队和角色
    • 版本控制
    • 错误
    • 协同生成(Co.Generate)
      POST
    • 协同嵌入(Co.Embed)
      POST
    • 协同聊天(Co.Chat (Beta))
      POST
    • 协同分类(Co.Classify)
      POST
    • 协同分词(Co.Tokenize)
      POST
    • 协同合并分词(Co.Detokenize)
      POST
    • 协同语言检测(Co.Detect_language)
      POST
    • 协同摘要(Co.Summarize)
      POST
    • 协同重新排序(Co.Rerank)
      POST

      协同分类(Co.Classify)

      开发环境
      https://api.cohere.ai/v1
      开发环境
      https://api.cohere.ai/v1
      POST
      https://api.cohere.ai/v1/classify
      这个接口可以对给定的文本输入预测最匹配的标签。Classify 通过提供的文本+标签对的示例作为参考,来进行预测。
      注意:在分类示例上训练的自定义模型在进行预测时不需要明确地传递 examples 参数。
      请求示例请求示例
      Shell
      JavaScript
      Java
      Swift
      curl --location --request POST 'https://api.cohere.ai/v1/classify' \
      --header 'Content-Type: application/json' \
      --data-raw '{
        "truncate": "END",
        "inputs": [
          "Confirm your email address",
          "hey i need u to send some $"
        ],
        "examples": [
          {
            "text": "Dermatologists don'\''t like her!",
            "label": "Spam"
          },
          {
            "text": "Hello, open to this?",
            "label": "Spam"
          },
          {
            "text": "I need help please wire me $1000 right now",
            "label": "Spam"
          },
          {
            "text": "Nice to know you ;)",
            "label": "Spam"
          },
          {
            "text": "Please help me?",
            "label": "Spam"
          },
          {
            "text": "Your parcel will be delivered today",
            "label": "Not spam"
          },
          {
            "text": "Review changes to our Terms and Conditions",
            "label": "Not spam"
          },
          {
            "text": "Weekly sync notes",
            "label": "Not spam"
          },
          {
            "text": "Re: Follow up from today’s meeting",
            "label": "Not spam"
          },
          {
            "text": "Pre-read for tomorrow",
            "label": "Not spam"
          }
        ]
      }'
      响应示例响应示例
      {
        "id": "string",
        "classifications": [
          {
            "id": "string",
            "input": "string",
            "prediction": "string",
            "predictions": [
              "string"
            ],
            "confidence": 0,
            "confidences": [
              0
            ],
            "labels": {
              "Not spam": {
                "confidence": 0
              },
              "Spam": {
                "confidence": 0
              }
            },
            "classification_type": "string"
          }
        ],
        "meta": {
          "api_version": {
            "version": "string"
          }
        }
      }

      请求参数

      Body 参数application/json
      truncate
      string 
      可选
      其中之一NONE|START|END指定 API 如何处理长于最大令牌长度的输入。 传递START将丢弃输入的开头。END将丢弃输入的末尾。在这两种情况下,输入都会被丢弃,直到剩余输入恰好是模型的最大输入标记长度。 如果NONE选择,当输入超过最大输入令牌长度时,将返回错误。 默认:END
      inputs
      array[string]
      必需
      表示要分类的查询列表,每个条目不能为空。最多为 96 个输入。
      examples
      array [object {2}] 
      必需
      为模型提供上下文的一组示例。每个示例都是一个文本字符串及其关联的标签/类。每个独特的标签需要至少 2 个与之关联的示例;示例的最大数量为 2500,每个示例的最大长度为 512 个标记。这些值的结构应为{text: "...",label: "..."}。 注意:在分类示例上训练的自定义模型不需要examples显式传入参数。
      text
      string 
      必需
      label
      string 
      必需
      model
      string 
      可选
      模型的标识符。当前可用的型号有embed-multilingual-v2.0、embed-english-light-v2.0和embed-english-v2.0(默认)。较小的“轻型”模型速度更快,而较大的模型性能更好。定制模型也可以提供完整的 ID。
      preset
      string 
      可选
      自定义游乐场预设的 ID。您可以在Playground中创建预设。如果您使用预设,则所有其他参数都将变为可选,并且任何包含的参数都将覆盖预设的参数。
      示例

      返回响应

      🟢200成功
      application/json
      Body
      id
      string 
      必需
      classifications
      array [object {8}] 
      必需
      id
      string 
      必需
      input
      string 
      必需
      prediction
      string 
      必需
      predictions
      array[string]
      必需
      confidence
      number 
      必需
      confidences
      array[number]
      必需
      labels
      object 
      必需
      classification_type
      string 
      必需
      meta
      object 
      必需
      api_version
      object 
      必需
      上一页
      协同聊天(Co.Chat (Beta))
      下一页
      协同分词(Co.Tokenize)
      Built with