ChatGPT插件例子 自然语言到 OpenAI API
创建代码以使用自然语言指令调用 OpenAI API。
提示:
“”“
Util公开以下内容:
util.openai()->验证并返回openai模块,该模块具有以下功能:
openai.完成.create(
prompt=“<my prompt>”,#开始完成的提示
max_tokens=123,#要生成的最大令牌数
温度=1.0#随机性的度量
echo=True,#是否在生成的完成之外返回提示
)
“”“
导入util
“”“
从提示“Once on a AI”开始创建一个OpenAI完成,不超过5个代币。不包括提示。
“”“
回答
openai = util.openai()
completion = openai.Completion.create(prompt="Once upon an AI", max_tokens=5, echo=False)
"""
API 请求
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.Completion.create(
model="text-davinci-003",
prompt="\"\"\"\nUtil exposes the following:\nutil.openai() -> authenticates & returns the openai module, which has the following functions:\nopenai.Completion.create(\n prompt=\"\", # The prompt to start completing from\n max_tokens=123, # The max number of tokens to generate\n temperature=1.0 # A measure of randomness\n echo=True, # Whether to return the prompt in addition to the generated completion\n)\n\"\"\"\nimport util\n\"\"\"\nCreate an OpenAI completion starting from the prompt \"Once upon an AI\", no more than 5 tokens. Does not include the prompt.\n\"\"\"\n",
temperature=0,
max_tokens=64,
top_p=1.0,
frequency_penalty=0.0,
presence_penalty=0.0,
stop=["\"\"\""]
)