| import gradio as gr |
| from utils import format_chat_history, get_qwen_response |
|
|
| def chat_with_qwen(message, history): |
| """使用通义千问API进行对话""" |
| |
| messages = format_chat_history(history, message) |
| |
| |
| response = get_qwen_response(messages) |
| |
| if response['success']: |
| return response['content'] |
| else: |
| return f"⚠️ {response['content']}" |
|
|
| |
| demo = gr.ChatInterface( |
| fn=chat_with_qwen, |
| title="通义千问聊天机器人", |
| description="这是一个使用DashScope API调用通义千问大模型的聊天机器人", |
| examples=["你好,请介绍一下自己", "什么是人工智能?", "给我讲个故事"], |
| theme="soft" |
| ) |
|
|
| |
| if __name__ == "__main__": |
| demo.launch(server_name="0.0.0.0", server_port=7860) |