# -*- coding: utf-8 -*- import gradio as gr from utils import prompt from utils import engine from utils.datasetSaver import login import time MODEL_NAME = 'gpt-3.5-turbo' # MODEL_NAME = 'gpt-4-turbo-preview' # MODEL_NAME = 'glm-4' # 自定义system # 设置端口号,默认7560,遇冲突可自定义 SERVER_PORT = 7562 story_path = r"/home/yangkelang/program/novalConvertProject/data/stories/十八岁出门远行.txt" prompt_text = prompt.prompt_generator(story_path) # 调用gpt的bot LLM = engine.ChatGPT(model=MODEL_NAME,init_system={"role": "system", "content": prompt_text}) # LLM = engine.zhiPuGlm(model=MODEL_NAME, init_system={"role": "system", "content": prompt_text}) initial_response = LLM.get_response() def predict(input, chatbot): """ 调用openai接口,获取答案 """ chatbot.append((input, "")) # 找chatgpt要答案 response = LLM.get_response(input) characters = '' for character in response: characters +=character chatbot[-1] = (input,characters) time.sleep(0.05) yield chatbot # return chatbot def reset_user_input(): return gr.update(value='') def reset_user_input_new_game(): return gr.update(value='newgame') def reset_state(): LLM.clean_history() return [] def save_history(): LLM.save_history() return [] def new_game(): return gr.update(value=[[None,initial_response]]) def main(): with gr.Blocks() as demo: gr.HTML("""