# ここから下はPythonのコードなので、編集時にはインデント関係に注意すること
import gradio as gr
from js import self
session = []
# LLM機能のサポート確認
try:
session = await self.ai.languageModel.create()
except:
if not session:
raise Exception("あなたのブラウザでは利用できません。1")
pass
self.ai.languageModel.capabilities();
self.ai_text_session = session
# プロンプトを送信すると呼び出される
# ストリーミングで動作する
async def prompt(message, history):
session = self.ai_text_session
if not session:
raise Exception("あなたのブラウザでは利用できません。2")
stream = session.promptStreaming(message)
async for chunk in stream:
yield chunk
demo = gr.ChatInterface(fn=prompt)
demo.launch()