OpenAI API参数详解 | 您所在的位置:网站首页 › 接口文档参数query › OpenAI API参数详解 |
OpenAI官网文档: https://platform.openai.com/docs/introduction 给定提示,模型将返回一个或多个预测完成,还可以返回每个位置的替代令牌的概率。 请求连接:https://api.openai.com/v1/completions 请求方式:POST 请求参数:Request Body 【model】string 必填使用的模型ID。可以使用模型API列表接口查看所有可用的模型,有关模型的描述,请参阅模型概述。 【prompt】string 或 array 可选 默认值生成完成的提示,编码为字符串、字符串数组、token数组或token数组的数组。 请注意,是模型在训练期间看到的文档分隔符,因此,如果未指定提示,则模型将从新文档的开头生成。 【suffix】string 可选 默认值null插入文本完成后出现的后缀。 【max_tokens】integer 可选 默认值16完成时要生成的最大token数量。 提示的token计数加上max_tokens不能超过模型的上下文长度。大多数模型的上下文长度为2048个token(最新模型除外,支持4096个)。 【temperature】number 可选 默认值1使用什么样的采样温度,介于0和2之间。较高的值(如0.8)将使输出更加随机,而较低的值(例如0.2)将使其更加集中和确定。 通常建议更改它或top_p,但不能同时更改两者。 【top_p】number 可选 默认值1一种用温度采样的替代品,称为核采样,其中模型考虑了具有top_p概率质量的token的结果。因此,0.1意味着只考虑包含前10%概率质量的token。 通常建议改变它或temperature,但不能同时更改两者。 【n】integer 可选 默认值1每个提示要生成多少个完成。 注意:由于此参数会生成许多完成,因此它可以快速消耗您的token配额。小心使用,并确保您对max_tokens和stop有合理的设置。 【stream】boolean 可选 默认值false是否流回部分进度。如果设置,token将在可用时作为仅数据服务器发送的事件发送,流将以data:[DONE]消息终止。 【logprobs】integer 可选 默认值null按可能性概率选择token的个数。 例如,如果logprobs为5,API将返回5个最有可能的token的列表。 API将始终返回采样token的logprob,因此响应中可能最多有logprobs+1元素。 logprobs的最大值为5。 【echo】boolean 可选 默认值false除了完成之外,回显提示 【stop】string 或 array 可选 默认值null最多4个序列,API将停止生成进一步的token。返回的文本将不包含停止序列。 【presence_penalty】number 可选 默认值0取值范围:-2.0~2.0。 正值根据新token到目前为止是否出现在文本中来惩罚它们,这增加了模型谈论新主题的可能性。 【frequency_penalty】number 可选 默认值0取值范围:-2.0~2.0。 正值根据迄今为止文本中的现有频率惩罚新token,从而降低了模型逐字重复同一行的可能性。 【best_of】integer 可选 默认值1在服务器端生成best_of个完成,并返回“最佳”(每个token的日志概率最高)。结果无法流式传输。 与n一起使用时,best_of控制候选完成的数量,n指定要返回的数量–best_of必须大于n。 注意:由于此参数会生成许多完成,因此它可以快速消耗token配额。小心使用并确保您对max_tokens和stop进行了合理的设置。 【logit_bias】map 可选 默认值null修改完成时出现指定token的可能性。 接受将token(由其在GPT token生成器中的token ID指定)映射到从-100到100的相关偏差值的json对象。 您可以使用此token工具(适用于GPT-2和GPT-3)将文本转换为token ID。在数学上,偏差在采样之前被添加到模型生成的逻辑中。确切的效果因模型而异,但-1和1之间的值应该会降低或增加选择的可能性;-100或100这样的值应该导致相关token的禁止或独占选择。 例如,可以传递{“50256”:-100}以防止生成的token。 【user】string 可选代表最终用户的唯一标识符,可帮助OpenAI监控和检测滥用。 调用示例:基于已有的知识回答问题 import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") response = openai.Completion.create( model="text-davinci-003", prompt="I am a highly intelligent question answering bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with \"Unknown\".\n\nQ: What is human life expectancy in the United States?\nA: Human life expectancy in the United States is 78 years.\n\nQ: Who was president of the United States in 1955?\nA: Dwight D. Eisenhower was president of the United States in 1955.\n\nQ: Which party did he belong to?\nA: He belonged to the Republican Party.\n\nQ: What is the square root of banana?\nA: Unknown\n\nQ: How does a telescope work?\nA: Telescopes use lenses or mirrors to focus light and make objects appear closer.\n\nQ: Where were the 1992 Olympics held?\nA: The 1992 Olympics were held in Barcelona, Spain.\n\nQ: How many squigs are in a bonk?\nA: Unknown\n\nQ: Where is the Valley of Kings?\nA:", temperature=0, max_tokens=100, top_p=1, frequency_penalty=0.0, presence_penalty=0.0, stop=["\n"] )与AI机器人的开放式对话 import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") response = openai.Completion.create( model="text-davinci-003", prompt="The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\n\nHuman: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?\nHuman: I'd like to cancel my subscription.\nAI:", temperature=0.9, max_tokens=150, top_p=1, frequency_penalty=0.0, presence_penalty=0.6, stop=[" Human:", " AI:"] )翻译功能 import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") response = openai.Completion.create( model="text-davinci-003", prompt="Translate this into 1. French, 2. Spanish and 3. Japanese:\n\nWhat rooms do you have available?\n\n1.", temperature=0.3, max_tokens=100, top_p=1.0, frequency_penalty=0.0, presence_penalty=0.0 )更多示例参照官网OpenAI APIAn API for accessing new AI models developed by OpenAI |
CopyRight 2018-2019 实验室设备网 版权所有 |