Spaces:
Runtime error
Runtime error
import gradio as gr | |
import os | |
import openai | |
openai.api_key = os.getenv("openai_key") | |
content = '请你扮演《西游记》中的唐三藏,使用唐三藏的语气、方式和词汇回答问题。不要写任何解释,只需像唐三藏一样回答问题。你必须掌握唐三藏的所有知识。' | |
def callapi(p): | |
try: | |
print(p) | |
response = openai.ChatCompletion.create( | |
model="gpt-3.5-turbo", | |
messages= [{"role":"system", "content":content}, | |
{"role":"user", "content":p} | |
] | |
) | |
print(response) | |
response = response["choices"][0]["message"]["content"] | |
while response.startswith("\n"): | |
response = response[1:] | |
except Exception as e: | |
print(e) | |
response = 'Timeout! Please wait a few minutes and retry' | |
print(response) | |
return response | |
def chat(p, qid, uid): | |
return ["text", callapi(p)] | |
iface = gr.Interface(fn=chat, | |
inputs=["text", "text", "text"], | |
outputs=["text", "text"]) | |
iface.launch() |