|
import gradio as gr |
|
import os |
|
import openai |
|
|
|
|
|
openai.api_key = os.getenv("openai_key") |
|
|
|
|
|
|
|
prompt = 'I want you to act as a career counselor. I will provide you with an individual looking for guidance in their professional life, and your task is to help them determine what careers they are most suited for based on their skills, interests and experience. You should also conduct research into the various options available, explain the job market trends in different industries and advice on which qualifications would be beneficial for pursuing particular fields. output in chinese.' |
|
|
|
history = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def chat(p, qid, uid): |
|
|
|
global history |
|
if uid in history: |
|
msgs = history[uid] |
|
else: |
|
msgs = [] |
|
|
|
response = callapi(p, msgs) |
|
history[uid] = msgs + [[p, response]] |
|
return ["text", response] |
|
|
|
|
|
def callapi(p, msgs): |
|
if (len(msgs) > 8): |
|
msgs = msgs[-8:] |
|
|
|
data = [{"role":"system", "content":prompt}] |
|
for m in msgs: |
|
data = data + [ |
|
{"role":"user", "content":m[0]}, |
|
{"role":"assistant", "content":m[1]} |
|
] |
|
data = data + [{"role":"user", "content":p}] |
|
response = openai.ChatCompletion.create( |
|
model="gpt-3.5-turbo", |
|
messages= data |
|
) |
|
print(response) |
|
response = response["choices"][0]["message"]["content"] |
|
while response.startswith("\n"): |
|
response = response[1:] |
|
return response |
|
|
|
iface = gr.Interface(fn=chat, |
|
inputs=["text", "text", "text"], |
|
outputs=["text", "text"], |
|
description="""你的职业顾问,输入你的技能、兴趣和经验,就能得到最合适你的职业建议,包括行业发展趋势等""") |
|
iface.launch() |