簡體   English   中英

OpenGPT 中的“索引” API output

[英]`index` in OpenGPT API output

以下是代碼

import os
import openai


openai.api_key = "..."


response = openai.Completion.create(
  model="text-davinci-003",     
  prompt="I am happy!",
  temperature=0, #creativity
  max_tokens=10,
  top_p=1,
  frequency_penalty=0.0,
  presence_penalty=0.0,
  suffix='I am even more happy!'
)

print(response)

以下是output

{
  "choices": [
    {
      "finish_reason": "length",
      "index": 0,
      "logprobs": null,
      "text": "\n\nI am happy because I am surrounded by"
    }
  ],
  "created": 1674640360,
  "id": "cmpl-6cWkK124234ho8C2134afasdasdnwDKLUMP",
  "model": "text-davinci-003",
  "object": "text_completion",
  "usage": {
    "completion_tokens": 10,
    "prompt_tokens": 10,
    "total_tokens": 20
  }
}

上面output后面的index代表什么?

索引是指回復prompt的索引。

由於prompt可以是字符串或數組, 文檔將其稱為:

提示字符串或數組

生成完成的提示,編碼為字符串字符串數組、標記數組或標記數組 arrays。


例如,考慮使用 2 個prompt調用/completions端點:

{
    "model": "text-davinci-003",
    "prompt": [ 
      "How should I",                            // [ 0 ]
      "Should I"                                 // [ 1 ] 
    ],
    "max_tokens": 7,
    "temperature": 0
}

OpenAI 將回答這兩個提示, index將參考prompt中回復的原始索引:

{
    "choices": [
        {
            "text": " go about doing this?\n\n",
            "index": 0,                              // Answers prompt[0]
            "logprobs": null,
            "finish_reason": "length"
        },
        {
            "text": " use a VPN on my iPhone?",
            "index": 1,                              // Answers prompt[1]
            "logprobs": null,
            "finish_reason": "length"
        }
    ]
}

在您的示例中,只有 1 個prompt ,因此 API 只會在choices數組中發送 1 object,因此index將始終為0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM