Yasu777 commited on
Commit
5da4d70
·
verified ·
1 Parent(s): 9182d03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -10
app.py CHANGED
@@ -188,6 +188,9 @@ def generate_response(user_input):
188
  physics_consideration = " DeepSeekの物理学的知見を考慮して" if is_physics else ""
189
  deepseek_section = f"DeepSeekの物理学的知見:\n{deepseek_knowledge}" if is_physics else ""
190
 
 
 
 
191
  qwen_prompt = f"""
192
  以下のユーザー入力に対してコーディングアシスタントとして回答してください。
193
  Mistral Sabaの分析結果と{physics_consideration}、
@@ -203,7 +206,10 @@ def generate_response(user_input):
203
 
204
  qwen_response = client.chat.completions.create(
205
  model=MODELS["qwen_coder"],
206
- messages=[{"role": "user", "content": qwen_prompt}],
 
 
 
207
  temperature=0.5,
208
  max_tokens=4000
209
  )
@@ -211,7 +217,12 @@ def generate_response(user_input):
211
  final_response = qwen_response.choices[0].message.content
212
 
213
  elif st.session_state.current_mode == "実装モード":
214
- # Step 2a: Qwen Coderによる設計書作成
 
 
 
 
 
215
  design_prompt = f"""
216
  以下のユーザー入力に基づいて、実装するコードの設計書を作成してください。
217
  設計書には以下の項目を含めてください:
@@ -226,12 +237,15 @@ def generate_response(user_input):
226
  Mistral Sabaの分析:
227
  {mistral_analysis}
228
 
229
- {'DeepSeekの物理学的知見:\n' + deepseek_knowledge if is_physics else ''}
230
  """
231
 
232
  design_response = client.chat.completions.create(
233
  model=MODELS["qwen_coder"],
234
- messages=[{"role": "user", "content": design_prompt}],
 
 
 
235
  temperature=0.4,
236
  max_tokens=3000
237
  )
@@ -242,7 +256,9 @@ def generate_response(user_input):
242
  "content": design_doc
243
  })
244
 
245
- # Step 2b: 設計書に基づいて実装コードを生成
 
 
246
  implementation_prompt = f"""
247
  以下の設計書に基づいて、完全な実装コードを提供してください。
248
  コードは実行可能で、エラー処理が適切に行われているものにしてください。
@@ -257,7 +273,10 @@ def generate_response(user_input):
257
 
258
  implementation_response = client.chat.completions.create(
259
  model=MODELS["qwen_coder"],
260
- messages=[{"role": "user", "content": implementation_prompt}],
 
 
 
261
  temperature=0.5,
262
  max_tokens=4000
263
  )
@@ -265,6 +284,12 @@ def generate_response(user_input):
265
  final_response = implementation_response.choices[0].message.content
266
 
267
  elif st.session_state.current_mode == "エラー修正モード":
 
 
 
 
 
 
268
  error_prompt = f"""
269
  以下のユーザー入力はコードのエラーに関するものです。
270
  エラーの原因を特定し、修正案を提供してください。
@@ -281,12 +306,15 @@ def generate_response(user_input):
281
  Mistral Sabaの分析:
282
  {mistral_analysis}
283
 
284
- {'DeepSeekの物理学的知見:\n' + deepseek_knowledge if is_physics else ''}
285
  """
286
 
287
  error_response = client.chat.completions.create(
288
  model=MODELS["qwen_coder"],
289
- messages=[{"role": "user", "content": error_prompt}],
 
 
 
290
  temperature=0.4,
291
  max_tokens=4000
292
  )
@@ -317,6 +345,9 @@ if prompt := st.chat_input("質問を入力してください"):
317
  # 直接Qwen Coderで応答
318
  client = Groq(api_key=api_key)
319
 
 
 
 
320
  # 過去の会話履歴を短くまとめたコンテキスト
321
  context = ""
322
  if len(st.session_state.messages) > 2:
@@ -326,7 +357,6 @@ if prompt := st.chat_input("質問を入力してください"):
326
  context += f"{role}: {msg['content'][:200]}...\n\n"
327
 
328
  qwen_prompt = f"""
329
- あなたはQwen-2.5-Coderモデルをベースにした、コーディングに特化した高性能AIアシスタントです。
330
  以下の会話の流れを踏まえて、最新のユーザー入力に回答してください。
331
 
332
  {context}
@@ -336,7 +366,10 @@ if prompt := st.chat_input("質問を入力してください"):
336
 
337
  qwen_response = client.chat.completions.create(
338
  model=MODELS["qwen_coder"],
339
- messages=[{"role": "user", "content": qwen_prompt}],
 
 
 
340
  temperature=0.5,
341
  max_tokens=4000
342
  )
 
188
  physics_consideration = " DeepSeekの物理学的知見を考慮して" if is_physics else ""
189
  deepseek_section = f"DeepSeekの物理学的知見:\n{deepseek_knowledge}" if is_physics else ""
190
 
191
+ # 通常モード用のシステムプロンプトをロード
192
+ system_prompt = load_system_prompt(MODELS["qwen_coder"], "通常モード")
193
+
194
  qwen_prompt = f"""
195
  以下のユーザー入力に対してコーディングアシスタントとして回答してください。
196
  Mistral Sabaの分析結果と{physics_consideration}、
 
206
 
207
  qwen_response = client.chat.completions.create(
208
  model=MODELS["qwen_coder"],
209
+ messages=[
210
+ {"role": "system", "content": system_prompt},
211
+ {"role": "user", "content": qwen_prompt}
212
+ ],
213
  temperature=0.5,
214
  max_tokens=4000
215
  )
 
217
  final_response = qwen_response.choices[0].message.content
218
 
219
  elif st.session_state.current_mode == "実装モード":
220
+ # 物理関連の条件分岐を変数で処理
221
+ deepseek_section = f"DeepSeekの物理学的知見:\n{deepseek_knowledge}" if is_physics else ""
222
+
223
+ # Step 2a: Qwen Coderによる設計書作成(通常モードのシステムプロンプトを利用)
224
+ design_system_prompt = load_system_prompt(MODELS["qwen_coder"], "通常モード")
225
+
226
  design_prompt = f"""
227
  以下のユーザー入力に基づいて、実装するコードの設計書を作成してください。
228
  設計書には以下の項目を含めてください:
 
237
  Mistral Sabaの分析:
238
  {mistral_analysis}
239
 
240
+ {deepseek_section}
241
  """
242
 
243
  design_response = client.chat.completions.create(
244
  model=MODELS["qwen_coder"],
245
+ messages=[
246
+ {"role": "system", "content": design_system_prompt},
247
+ {"role": "user", "content": design_prompt}
248
+ ],
249
  temperature=0.4,
250
  max_tokens=3000
251
  )
 
256
  "content": design_doc
257
  })
258
 
259
+ # Step 2b: 設計書に基づいて実装コードを生成(実装モード用のシステムプロンプトを利用)
260
+ implementation_system_prompt = load_system_prompt(MODELS["qwen_coder"], "実装モード")
261
+
262
  implementation_prompt = f"""
263
  以下の設計書に基づいて、完全な実装コードを提供してください。
264
  コードは実行可能で、エラー処理が適切に行われているものにしてください。
 
273
 
274
  implementation_response = client.chat.completions.create(
275
  model=MODELS["qwen_coder"],
276
+ messages=[
277
+ {"role": "system", "content": implementation_system_prompt},
278
+ {"role": "user", "content": implementation_prompt}
279
+ ],
280
  temperature=0.5,
281
  max_tokens=4000
282
  )
 
284
  final_response = implementation_response.choices[0].message.content
285
 
286
  elif st.session_state.current_mode == "エラー修正モード":
287
+ # 物理関連の条件分岐を変数で処理
288
+ deepseek_section = f"DeepSeekの物理学的知見:\n{deepseek_knowledge}" if is_physics else ""
289
+
290
+ # エラー修正モード用のシステムプロンプトをロード
291
+ error_system_prompt = load_system_prompt(MODELS["qwen_coder"], "エラー修正モード")
292
+
293
  error_prompt = f"""
294
  以下のユーザー入力はコードのエラーに関するものです。
295
  エラーの原因を特定し、修正案を提供してください。
 
306
  Mistral Sabaの分析:
307
  {mistral_analysis}
308
 
309
+ {deepseek_section}
310
  """
311
 
312
  error_response = client.chat.completions.create(
313
  model=MODELS["qwen_coder"],
314
+ messages=[
315
+ {"role": "system", "content": error_system_prompt},
316
+ {"role": "user", "content": error_prompt}
317
+ ],
318
  temperature=0.4,
319
  max_tokens=4000
320
  )
 
345
  # 直接Qwen Coderで応答
346
  client = Groq(api_key=api_key)
347
 
348
+ # 現在のモードに合わせたシステムプロンプトをロード
349
+ current_system_prompt = load_system_prompt(MODELS["qwen_coder"], st.session_state.current_mode)
350
+
351
  # 過去の会話履歴を短くまとめたコンテキスト
352
  context = ""
353
  if len(st.session_state.messages) > 2:
 
357
  context += f"{role}: {msg['content'][:200]}...\n\n"
358
 
359
  qwen_prompt = f"""
 
360
  以下の会話の流れを踏まえて、最新のユーザー入力に回答してください。
361
 
362
  {context}
 
366
 
367
  qwen_response = client.chat.completions.create(
368
  model=MODELS["qwen_coder"],
369
+ messages=[
370
+ {"role": "system", "content": current_system_prompt},
371
+ {"role": "user", "content": qwen_prompt}
372
+ ],
373
  temperature=0.5,
374
  max_tokens=4000
375
  )