import gradio as gr import random from llm.openai import Llm # # mock for testing # from llm.mock import Llm llm = Llm() def assistant_response(prompt): answer = llm.chatcompletion(prompt) return answer def respond(message, chat_history): answer = llm.chatcompletion(message) print(answer) chat_history.append((message, answer)) return "", chat_history title = "OpenAPI Assistant API: " + llm.assistant.name if llm.assistant.description is None: model = llm.assistant.model description = f"このデモはOpenAPI Assistant APIのデモです。テキストボックスにテキストを入力すると、{model}モデルが応答します。" else: description = llm.assistant.description # 実行例のリスト (現在使用してない) import csv examples = [] with open('flagged/log.csv', 'r', encoding='utf-8') as file: reader = csv.DictReader(file) examples = [row['prompt'] for row in reader] with gr.Blocks() as demo: gr.Markdown( f""" # {title} {description} """) chatbot = gr.Chatbot() msg = gr.Textbox() clear = gr.ClearButton([msg, chatbot]) examples=examples msg.submit(respond, [msg, chatbot], [msg, chatbot]) if __name__ == "__main__": demo.launch()