Update app.py
Browse files
app.py
CHANGED
|
@@ -35,9 +35,25 @@ def respond(
|
|
| 35 |
Gradio ChatInterfaceの標準形式に対応
|
| 36 |
"""
|
| 37 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# システムメッセージと会話履歴を含むプロンプトを構築
|
| 39 |
conversation = ""
|
| 40 |
-
if system_message.strip():
|
| 41 |
conversation += f"システム: {system_message}\n"
|
| 42 |
|
| 43 |
# 会話履歴を追加
|
|
@@ -86,7 +102,7 @@ def respond(
|
|
| 86 |
|
| 87 |
|
| 88 |
except Exception as e:
|
| 89 |
-
|
| 90 |
|
| 91 |
"""
|
| 92 |
Gradio ChatInterfaceを使用したシンプルなチャットボット
|
|
|
|
| 35 |
Gradio ChatInterfaceの標準形式に対応
|
| 36 |
"""
|
| 37 |
try:
|
| 38 |
+
# パラメータを適切な型に変換(API呼び出し時の文字列対策)
|
| 39 |
+
try:
|
| 40 |
+
max_tokens = int(max_tokens) if max_tokens is not None else 512
|
| 41 |
+
except (ValueError, TypeError):
|
| 42 |
+
max_tokens = 512
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
temperature = float(temperature) if temperature is not None else 0.7
|
| 46 |
+
except (ValueError, TypeError):
|
| 47 |
+
temperature = 0.7
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
top_p = float(top_p) if top_p is not None else 0.95
|
| 51 |
+
except (ValueError, TypeError):
|
| 52 |
+
top_p = 0.95
|
| 53 |
+
|
| 54 |
# システムメッセージと会話履歴を含むプロンプトを構築
|
| 55 |
conversation = ""
|
| 56 |
+
if system_message and system_message.strip():
|
| 57 |
conversation += f"システム: {system_message}\n"
|
| 58 |
|
| 59 |
# 会話履歴を追加
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
except Exception as e:
|
| 105 |
+
return f"エラーが発生しました: {str(e)}"
|
| 106 |
|
| 107 |
"""
|
| 108 |
Gradio ChatInterfaceを使用したシンプルなチャットボット
|