gpt4 book ai didi

python - 尝试在 OpenAI 中使用 Python 插入输入函数

转载 作者:行者123 更新时间:2023-12-02 05:47:30 25 4
gpt4 key购买 nike

import os
import openai
openai.api_key = 'API_Key'
Question = "\\n\\nQ: input("Enter Question")?\\nA:",
response = openai.Completion.create(
model="text-davinci-003",
prompt= Question,
temperature=0,
max_tokens=100,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0,
stop=\["\\n"\]
)
print( str(response\['choices'\]\[0\]\['text'\]))`
ERROR
File "C:\\Users\\yus\\PycharmProjects\\pythonProject\\TEST.py", line 6
Question = "\\n\\nQ: "Input_Question" \\nA:"
^
SyntaxError: invalid syntax
Process finished with exit code 1

期望输入函数要求输入问题,然后使用 OpenAI 打印答案。

最佳答案

这是怎么做的

 def main():
form = cgi.FieldStorage()
IN = form.getvalue("query")
QT = f"Q: {IN} ? A:"
response = openai.Completion.create(
model="text-davinci-003",
prompt=QT,
temperature=0,
max_tokens=64,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
stop=["\n\n"]
)
print(str(response['choices'][0]['text']))

if __name__ == "__main__":
main()

关于python - 尝试在 OpenAI 中使用 Python 插入输入函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75003737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com