Upload app.py
Browse files
app.py
CHANGED
|
@@ -223,26 +223,48 @@ def update_affection(message, affection):
|
|
| 223 |
return affection
|
| 224 |
return affection
|
| 225 |
|
|
|
|
|
|
|
| 226 |
def respond(message, chat_history, affection, history, scene_params):
|
| 227 |
new_affection = update_affection(message, affection)
|
| 228 |
stage_name = get_relationship_stage(new_affection)
|
| 229 |
current_theme = scene_params.get("theme", "default")
|
| 230 |
new_scene_name = detect_scene_change(history, message)
|
| 231 |
final_scene_params = scene_params
|
|
|
|
| 232 |
if new_scene_name and new_scene_name != current_theme:
|
| 233 |
print(f"シーンチェンジを実行: {current_theme} -> {new_scene_name}")
|
|
|
|
|
|
|
| 234 |
new_params_base = generate_scene_instruction_with_groq(new_affection, stage_name, new_scene_name, message)
|
| 235 |
if new_params_base:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
final_scene_params = {**DEFAULT_SCENE_PARAMS, **new_params_base}
|
| 237 |
-
#
|
| 238 |
simple_instruction = f"{new_scene_name}に来た感想を述べる"
|
| 239 |
print(f"シンプルな指示を使用: {simple_instruction}")
|
|
|
|
|
|
|
| 240 |
bot_message = generate_dialogue_with_gemini(history, message, new_affection, stage_name, final_scene_params, instruction=simple_instruction)
|
| 241 |
else:
|
| 242 |
final_scene_params["theme"] = new_scene_name
|
| 243 |
bot_message = generate_dialogue_with_gemini(history, message, new_affection, stage_name, final_scene_params)
|
| 244 |
else:
|
|
|
|
| 245 |
bot_message = generate_dialogue_with_gemini(history, message, new_affection, stage_name, final_scene_params)
|
|
|
|
| 246 |
new_history = history + [(message, bot_message)]
|
| 247 |
chat_history.append((message, bot_message))
|
| 248 |
theme_name = final_scene_params.get("theme", "default")
|
|
|
|
| 223 |
return affection
|
| 224 |
return affection
|
| 225 |
|
| 226 |
+
|
| 227 |
+
|
| 228 |
def respond(message, chat_history, affection, history, scene_params):
|
| 229 |
new_affection = update_affection(message, affection)
|
| 230 |
stage_name = get_relationship_stage(new_affection)
|
| 231 |
current_theme = scene_params.get("theme", "default")
|
| 232 |
new_scene_name = detect_scene_change(history, message)
|
| 233 |
final_scene_params = scene_params
|
| 234 |
+
|
| 235 |
if new_scene_name and new_scene_name != current_theme:
|
| 236 |
print(f"シーンチェンジを実行: {current_theme} -> {new_scene_name}")
|
| 237 |
+
|
| 238 |
+
# シーンパラメータを更新
|
| 239 |
new_params_base = generate_scene_instruction_with_groq(new_affection, stage_name, new_scene_name, message)
|
| 240 |
if new_params_base:
|
| 241 |
+
# Groqからの応答を精査し、問題のある可能性のあるフィールドを修正
|
| 242 |
+
if isinstance(new_params_base.get("personality_mod"), dict):
|
| 243 |
+
# 複雑な構造になっている場合は単純化
|
| 244 |
+
new_params_base["personality_mod"] = f"{new_scene_name}での様子を観察している"
|
| 245 |
+
|
| 246 |
+
if isinstance(new_params_base.get("tone"), dict):
|
| 247 |
+
# 複雑な構造になっている場合は単純化
|
| 248 |
+
new_params_base["tone"] = "冷静だが、少し興味を持っている様子"
|
| 249 |
+
|
| 250 |
+
# 英語の指示を日本語に変換
|
| 251 |
+
if "initial_dialogue_instruction" in new_params_base and new_params_base["initial_dialogue_instruction"].strip().lower().startswith("so"):
|
| 252 |
+
new_params_base["initial_dialogue_instruction"] = f"{new_scene_name}の感想を述べる"
|
| 253 |
+
|
| 254 |
final_scene_params = {**DEFAULT_SCENE_PARAMS, **new_params_base}
|
| 255 |
+
# シンプルな指示を使用
|
| 256 |
simple_instruction = f"{new_scene_name}に来た感想を述べる"
|
| 257 |
print(f"シンプルな指示を使用: {simple_instruction}")
|
| 258 |
+
|
| 259 |
+
# Geminiを使用して応答を生成
|
| 260 |
bot_message = generate_dialogue_with_gemini(history, message, new_affection, stage_name, final_scene_params, instruction=simple_instruction)
|
| 261 |
else:
|
| 262 |
final_scene_params["theme"] = new_scene_name
|
| 263 |
bot_message = generate_dialogue_with_gemini(history, message, new_affection, stage_name, final_scene_params)
|
| 264 |
else:
|
| 265 |
+
# 通常会話はGeminiを使用
|
| 266 |
bot_message = generate_dialogue_with_gemini(history, message, new_affection, stage_name, final_scene_params)
|
| 267 |
+
|
| 268 |
new_history = history + [(message, bot_message)]
|
| 269 |
chat_history.append((message, bot_message))
|
| 270 |
theme_name = final_scene_params.get("theme", "default")
|