assistants-api / app.py
shigeru saito
不要コード削除
4f94063
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
with gr.Blocks() as demo:
gr.Markdown(
f"""
# {title}
{description}
""")
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.ClearButton([msg, chatbot])
msg.submit(respond, [msg, chatbot], [msg, chatbot])
if __name__ == "__main__":
demo.launch()