Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,10 @@ def respond(
|
|
11 |
temperature,
|
12 |
top_p,
|
13 |
):
|
|
|
|
|
|
|
|
|
14 |
messages = [{"role": "system", "content": system_message}]
|
15 |
|
16 |
# ユーザーとAIの履歴を追加
|
@@ -22,25 +26,29 @@ def respond(
|
|
22 |
|
23 |
messages.append({"role": "user", "content": message})
|
24 |
|
|
|
25 |
response = ""
|
26 |
-
|
27 |
-
# AIの応答を取得する
|
28 |
-
for message in client.chat_completion(
|
29 |
messages,
|
30 |
max_tokens=max_tokens,
|
31 |
-
stream=True,
|
32 |
temperature=temperature,
|
33 |
top_p=top_p,
|
34 |
-
)
|
|
|
|
|
35 |
token = message.choices[0].delta.content
|
36 |
response += token
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# グラディオインターフェースの設定
|
40 |
demo = gr.ChatInterface(
|
41 |
respond,
|
42 |
additional_inputs=[
|
43 |
-
gr.Textbox(value="
|
44 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
45 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
46 |
gr.Slider(
|
|
|
11 |
temperature,
|
12 |
top_p,
|
13 |
):
|
14 |
+
# ユーザーの入力が空でない場合のみ処理
|
15 |
+
if not message.strip():
|
16 |
+
return "メッセージを入力してください。"
|
17 |
+
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
# ユーザーとAIの履歴を追加
|
|
|
26 |
|
27 |
messages.append({"role": "user", "content": message})
|
28 |
|
29 |
+
# AIの応答を取得
|
30 |
response = ""
|
31 |
+
completion = client.chat_completion(
|
|
|
|
|
32 |
messages,
|
33 |
max_tokens=max_tokens,
|
|
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
+
)
|
37 |
+
|
38 |
+
for message in completion:
|
39 |
token = message.choices[0].delta.content
|
40 |
response += token
|
41 |
+
|
42 |
+
# AIの応答を履歴に追加
|
43 |
+
history.append((message, response))
|
44 |
+
|
45 |
+
return response
|
46 |
|
47 |
# グラディオインターフェースの設定
|
48 |
demo = gr.ChatInterface(
|
49 |
respond,
|
50 |
additional_inputs=[
|
51 |
+
gr.Textbox(value="あなたは親切なチャットボットです。できるだけユーザーが安心して理解できるように会話してください", label="System message"),
|
52 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
53 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
54 |
gr.Slider(
|