# !/usr/bin/env python # -*-coding:utf-8 -*- """ # File : claude2_xiaolv_api_file_chat.py # Time :2023/8/14 10:20 # Author :小吕同学 """ import gradio as gr import google.generativeai as genai def request_to_v2(message, api_keys, context=[]): context = [message] ## 加入API_keys genai.configure(api_key=api_keys) model = genai.GenerativeModel(model_name="gemini-pro") promt_s = [ message ] respose = model.generate_content(promt_s) responses = respose.text # responses = "嘿嘿" context += [responses] responses = [(u, b) for u, b in zip(context[::2], context[1::2])] return responses, context with gr.Blocks() as dialog_app: gr.HTML("""
5.如果想多轮对话的话,可以参考以下这个地址:Claude2-API-xiaolv-第1版-多轮对话
""" """6.如果只想回复一次的话,可以参考以下这个地址:Claude2-API-xiaolv-第2版-单轮对话
""" """如果喜欢请给个 💖
""" ) with gr.Row(): with gr.Column(scale=0.4): api_keys = gr.Textbox(lines=2, label="输入GOOGLE_API_KEY") with gr.Column(scale=0.6): chatbot = gr.Chatbot([]) state = gr.State([]) with gr.Row(): inputs = gr.Textbox( label="输入问题", placeholder="请输入你的文本,确保已经正确填入GOOGLE_API_KEY" ) inputs.submit(request_to_v2, [inputs, api_keys, state], [chatbot, state]) send = gr.Button("发送请求.....") send.click(request_to_v2, [inputs, api_keys, state], [chatbot, state], api_name="xiaolv_google_ai", show_progress=True) gr.Markdown(""" 清除历史记录是,请输入:```/resrt```""") # 为网站设置密码防止滥用 # dialog_app.launch(auth=("admin", "2240560729"),show_error=True,show_api=True,share=True) # dialog_app.launch(auth=("admin", "2240560729"),show_error=True) dialog_app.launch(show_error=True) # dialog_app.launch(show_error=True,show_api=True,share=True)