Trying to Insert an input function using Python in OpenAI
题意:尝试在 OpenAI 中使用 Python 插入一个输入函数
问题背景:
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
Expecting an input function to ask to enter a question and then print the answer using OpenAI.
期望输入一个函数,提示用户输入一个问题,然后使用 OpenAI 打印回答。
问题解决:
this is how is done 这是完成方法
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()

