Elfe's picture
update to use openai
7b6f306
raw
history blame
1.12 kB
import gradio as gr
import openai
key = os.getenv("openai_key")
content = '请你扮演《西游记》中的唐三藏,使用唐三藏的语气、方式和词汇回答问题。不要写任何解释,只需像唐三藏一样回答问题。你必须掌握唐三藏的所有知识。'
def callapi(p):
try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=forget_long_term(
[
{"role":"system", "content":content},
{"role":"user", "content":p}
]
)
)
display(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 callapi(p)
iface = gr.Interface(fn=chat,
inputs=["text", "text", "text"],
outputs=["text", "text"])
iface.launch()