Update app.py
Browse files
app.py
CHANGED
|
@@ -14,11 +14,11 @@ headers = {
|
|
| 14 |
"Content-Type": "application/json"
|
| 15 |
}
|
| 16 |
|
| 17 |
-
def get_response(prompt, temperature, top_p, max_tokens):
|
| 18 |
# ペイロードを作成
|
| 19 |
payload = {
|
| 20 |
"model": "jd5fsx11n7go",
|
| 21 |
-
"prompt": prompt,
|
| 22 |
"max_tokens": max_tokens,
|
| 23 |
"temperature": temperature,
|
| 24 |
"top_p": top_p
|
|
@@ -33,34 +33,30 @@ def get_response(prompt, temperature, top_p, max_tokens):
|
|
| 33 |
else:
|
| 34 |
return f"エラーが発生しました: {response.status_code} {response.text}"
|
| 35 |
|
| 36 |
-
def
|
| 37 |
-
# ユーザーからの入力を
|
| 38 |
-
|
| 39 |
|
| 40 |
# レスポンスを取得
|
| 41 |
-
response = get_response(
|
| 42 |
|
| 43 |
-
# レスポンスを
|
| 44 |
-
|
| 45 |
|
| 46 |
-
return
|
| 47 |
|
| 48 |
-
# Gradio
|
| 49 |
-
|
| 50 |
-
fn=
|
| 51 |
-
|
| 52 |
-
gr.Textbox(
|
| 53 |
-
gr.Slider(minimum=
|
| 54 |
-
gr.Slider(minimum=0.
|
| 55 |
-
gr.Slider(minimum=1, maximum=
|
| 56 |
-
gr.State()
|
| 57 |
],
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
gr.outputs.Chatbot()
|
| 61 |
-
],
|
| 62 |
-
live=True
|
| 63 |
)
|
| 64 |
|
| 65 |
# インターフェースの起動
|
| 66 |
-
|
|
|
|
| 14 |
"Content-Type": "application/json"
|
| 15 |
}
|
| 16 |
|
| 17 |
+
def get_response(prompt, system_message, temperature, top_p, max_tokens):
|
| 18 |
# ペイロードを作成
|
| 19 |
payload = {
|
| 20 |
"model": "jd5fsx11n7go",
|
| 21 |
+
"prompt": f"{system_message}\n{prompt}",
|
| 22 |
"max_tokens": max_tokens,
|
| 23 |
"temperature": temperature,
|
| 24 |
"top_p": top_p
|
|
|
|
| 33 |
else:
|
| 34 |
return f"エラーが発生しました: {response.status_code} {response.text}"
|
| 35 |
|
| 36 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 37 |
+
# ユーザーからの入力を history に追加
|
| 38 |
+
history.append(("あなた", message))
|
| 39 |
|
| 40 |
# レスポンスを取得
|
| 41 |
+
response = get_response(message, system_message, temperature, top_p, max_tokens)
|
| 42 |
|
| 43 |
+
# レスポンスを history に追加
|
| 44 |
+
history.append(("チャットボット", response))
|
| 45 |
|
| 46 |
+
return history, history
|
| 47 |
|
| 48 |
+
# Gradio ChatInterfaceの作成
|
| 49 |
+
demo = gr.ChatInterface(
|
| 50 |
+
fn=respond,
|
| 51 |
+
additional_inputs=[
|
| 52 |
+
gr.Textbox(value="あなたはフレンドリーなチャットボットです。", label="システムメッセージ"),
|
| 53 |
+
gr.Slider(minimum=1, maximum=2048, value=768, step=1, label="新規トークン最大"),
|
| 54 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="温度"),
|
| 55 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (核 sampling)"),
|
|
|
|
| 56 |
],
|
| 57 |
+
title="Friendli AI チャットボット",
|
| 58 |
+
description="Friendli AIを使用したチャットボットです。パラメータを調整して会話を行ってください。",
|
|
|
|
|
|
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
# インターフェースの起動
|
| 62 |
+
demo.launch()
|