CoolFace
Apppublic

LymanML/ML_HF_OpenAPI

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py35 linesDownload Raw Back to root
1import gradio as gr2from gradio_client import Client3from typing import List, Optional, Tuple, Dict4# 创建Client实例,指定API的URL5client = Client("Qwen/Qwen2-72B-Instruct")6 7# 默认系统提示8default_system = "You are a helpful assistant."9api_name = "/model_chat_1"10 11# 清空聊天历史的函数12def clear_session():13    return [], default_system14 15History = List[Tuple[str, str]]16 17# 模型对话函数18def model_chat(query: Optional[str], chat_history: Optional[History], system: str) -> Tuple[str, str, History]:19    # 调用API接口20    if not chat_history:21        chat_history = []22    if not query:23        query = ''24    result = client.predict(25        query=query,26        history=chat_history,27        system=default_system,28        api_name=api_name29    )30    # 更新聊天历史31    new_round = [query, result]32    chat_history.append(new_round)33    return result, chat_history34 35