Spaces:
Sleeping
Sleeping
Update app.py
Browse files20 unmodified lines21222324252627282930313233343536373839404142434445464748495051525320 unmodified lines# 定义聊天机器人的响应函数def chatbot_response(messages):completion = client.chat.completions.create(model="llama3-8b-8192",messages=[{"role": "system","content": "You are a corporate secretary who is skilled at drafting business emails. The prompt will feed you addressee, main message, and final greetings."}] + messages,temperature=1,max_tokens=1024,top_p=1,stream=True,stop=None,)response = ""for chunk in completion:response += chunk.choices[0].delta.content or ""return response# 使用 gradio 创建聊天机器人界面def respond(message, history):history.append({"role": "user", "content": message})bot_response = chatbot_response(history)history.append({"role": "assistant", "content": bot_response})return "", history# 初始化 Gradio 应用with gr.Blocks() as demo:20 unmodified lines212223242526272829303132333435363738394041424344454647484950515253545556575859606120 unmodified lines# 定义聊天机器人的响应函数def chatbot_response(messages):try:completion = client.chat.completions.create(model="llama3-8b-8192",messages=[{"role": "system","content": "You are a corporate secretary who is skilled at drafting business emails. The prompt will feed you addressee, main message, and final greetings."}] + messages,temperature=1,max_tokens=1024,top_p=1,stream=True,stop=None,)response = ""for chunk in completion:response += chunk.choices[0].delta.content or ""return responseexcept Exception as e:print(f"Error in chatbot_response: {e}")return "Error: Unable to get response from the API."# 使用 gradio 创建聊天机器人界面def respond(message, history):try:history.append({"role": "user", "content": message})bot_response = chatbot_response(history)history.append({"role": "assistant", "content": bot_response})return "", historyexcept Exception as e:print(f"Error in respond function: {e}")return "", history# 初始化 Gradio 应用with gr.Blocks() as demo:
app.py+32-24