Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- core_dialogue.py +9 -0
- main_app.py +14 -1
core_dialogue.py
CHANGED
|
@@ -91,7 +91,10 @@ class DialogueGenerator:
|
|
| 91 |
|
| 92 |
def call_llm(self, system_prompt: str, user_prompt: str, is_json_output: bool = False) -> str:
|
| 93 |
"""Together.ai APIを呼び出す"""
|
|
|
|
|
|
|
| 94 |
if not self.client:
|
|
|
|
| 95 |
# デモモード用の固定応答(隠された真実付き)
|
| 96 |
if is_json_output:
|
| 97 |
return '{"scene": "none"}'
|
|
@@ -108,6 +111,7 @@ class DialogueGenerator:
|
|
| 108 |
# Together.ai APIを呼び出し
|
| 109 |
# JSON出力の場合は短く、通常の対話は適度な長さに制限
|
| 110 |
max_tokens = 150 if is_json_output else 500
|
|
|
|
| 111 |
|
| 112 |
response = self.client.chat.completions.create(
|
| 113 |
model=self.model,
|
|
@@ -119,13 +123,18 @@ class DialogueGenerator:
|
|
| 119 |
max_tokens=max_tokens,
|
| 120 |
)
|
| 121 |
|
|
|
|
|
|
|
| 122 |
content = response.choices[0].message.content if response.choices else ""
|
|
|
|
|
|
|
| 123 |
if not content:
|
| 124 |
logger.warning("Together.ai API応答が空です")
|
| 125 |
if is_json_output:
|
| 126 |
return '{"scene": "none"}'
|
| 127 |
return "[HIDDEN:(何て言えばいいか分からない...)]…言葉が出てこない。"
|
| 128 |
|
|
|
|
| 129 |
return content
|
| 130 |
|
| 131 |
except Exception as e:
|
|
|
|
| 91 |
|
| 92 |
def call_llm(self, system_prompt: str, user_prompt: str, is_json_output: bool = False) -> str:
|
| 93 |
"""Together.ai APIを呼び出す"""
|
| 94 |
+
logger.info(f"🔗 call_llm開始 - is_json_output: {is_json_output}")
|
| 95 |
+
|
| 96 |
if not self.client:
|
| 97 |
+
logger.warning("⚠️ APIクライアントが利用できません - デモモード応答を返します")
|
| 98 |
# デモモード用の固定応答(隠された真実付き)
|
| 99 |
if is_json_output:
|
| 100 |
return '{"scene": "none"}'
|
|
|
|
| 111 |
# Together.ai APIを呼び出し
|
| 112 |
# JSON出力の場合は短く、通常の対話は適度な長さに制限
|
| 113 |
max_tokens = 150 if is_json_output else 500
|
| 114 |
+
logger.info(f"🔗 Together.ai API呼び出し開始 - model: {self.model}, max_tokens: {max_tokens}")
|
| 115 |
|
| 116 |
response = self.client.chat.completions.create(
|
| 117 |
model=self.model,
|
|
|
|
| 123 |
max_tokens=max_tokens,
|
| 124 |
)
|
| 125 |
|
| 126 |
+
logger.info("🔗 Together.ai API呼び出し完了")
|
| 127 |
+
|
| 128 |
content = response.choices[0].message.content if response.choices else ""
|
| 129 |
+
logger.info(f"🔗 API応答内容: '{content[:100]}...' (長さ: {len(content)}文字)")
|
| 130 |
+
|
| 131 |
if not content:
|
| 132 |
logger.warning("Together.ai API応答が空です")
|
| 133 |
if is_json_output:
|
| 134 |
return '{"scene": "none"}'
|
| 135 |
return "[HIDDEN:(何て言えばいいか分からない...)]…言葉が出てこない。"
|
| 136 |
|
| 137 |
+
logger.info("🔗 call_llm正常完了")
|
| 138 |
return content
|
| 139 |
|
| 140 |
except Exception as e:
|
main_app.py
CHANGED
|
@@ -2230,10 +2230,23 @@ Streamlit情報:
|
|
| 2230 |
logger.info("🧠 メモリサマリーは空です(初対面状態)")
|
| 2231 |
|
| 2232 |
# 対話生成(隠された真実機能統合済み)
|
| 2233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2234 |
history, message, affection, stage_name, st.session_state.chat['scene_params'], instruction, memory_summary, st.session_state.chat['ura_mode']
|
| 2235 |
)
|
| 2236 |
|
|
|
|
|
|
|
| 2237 |
# デバッグ: AI応答の形式をチェック
|
| 2238 |
if response:
|
| 2239 |
logger.info(f"🤖 AI応答: '{response[:100]}...'")
|
|
|
|
| 2230 |
logger.info("🧠 メモリサマリーは空です(初対面状態)")
|
| 2231 |
|
| 2232 |
# 対話生成(隠された真実機能統合済み)
|
| 2233 |
+
logger.info("🤖 AI対話生成開始")
|
| 2234 |
+
logger.info(f"🤖 パラメータ - 好感度: {affection}, ステージ: {stage_name}, テーマ: {st.session_state.chat['scene_params'].get('theme', 'default')}")
|
| 2235 |
+
logger.info(f"🤖 URAモード: {st.session_state.chat['ura_mode']}")
|
| 2236 |
+
|
| 2237 |
+
# APIクライアントの状態確認
|
| 2238 |
+
dialogue_generator = managers['dialogue_generator']
|
| 2239 |
+
if dialogue_generator.client:
|
| 2240 |
+
logger.info("🔗 Together.ai APIクライアント利用可能")
|
| 2241 |
+
else:
|
| 2242 |
+
logger.warning("⚠️ Together.ai APIクライアント利用不可 - デモモードで動作")
|
| 2243 |
+
|
| 2244 |
+
response = dialogue_generator.generate_dialogue(
|
| 2245 |
history, message, affection, stage_name, st.session_state.chat['scene_params'], instruction, memory_summary, st.session_state.chat['ura_mode']
|
| 2246 |
)
|
| 2247 |
|
| 2248 |
+
logger.info("🤖 AI対話生成完了")
|
| 2249 |
+
|
| 2250 |
# デバッグ: AI応答の形式をチェック
|
| 2251 |
if response:
|
| 2252 |
logger.info(f"🤖 AI応答: '{response[:100]}...'")
|