File size: 906 Bytes
845a7f6
b7f2fb4
24c2565
90c87e6
23b72b3
04038a0
845a7f6
 
5afed16
76ce653
56844fd
845a7f6
b7f2fb4
76ce653
24c2565
 
859b35f
24c2565
6345748
24c2565
 
 
 
90c87e6
47d0c73
b7f2fb4
24c2565
845a7f6
90c87e6
b7f2fb4
47d0c73
24c2565
7a8f90a
a274d3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gradio as gr
from gradio_client import Client
from typing import List, Optional, Tuple, Dict
# 创建Client实例,指定API的URL
client = Client("Qwen/Qwen2-72B-Instruct")

# 默认系统提示
default_system = "You are a helpful assistant."
api_name = "/model_chat_1"

# 清空聊天历史的函数
def clear_session():
    return [], default_system

History = List[Tuple[str, str]]

# 模型对话函数
def model_chat(query: Optional[str], chat_history: Optional[History], system: str) -> Tuple[str, str, History]:
    # 调用API接口
    if not chat_history:
        chat_history = []
    if not query:
        query = ''
    result = client.predict(
        query=query,
        history=chat_history,
        system=default_system,
        api_name=api_name
    )
    # 更新聊天历史
    new_round = [query, result]
    chat_history.append(new_round)
    return result, chat_history