aidn commited on
Commit
fdf4ef2
·
verified ·
1 Parent(s): 1034608

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -2,8 +2,7 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
- # Die Ratsmitglieder - Ich habe die UI-Namen etwas neutraler gemacht,
6
- # der System-Prompt ist jetzt für alle gleich (siehe unten in der Funktion)
7
  COUNCIL_MEMBERS = {
8
  "Mitglied 1 (Llama)": ("meta-llama/Llama-3.3-70B-Instruct", "Fokus auf Philosophie, Logik und das große Ganze."),
9
  "Mitglied 2 (DeepSeek)": ("deepseek-ai/DeepSeek-V3", "Fokus auf harte Fakten, Mathematik, Physik und Naturwissenschaften."),
@@ -26,6 +25,7 @@ def ask_model(model_id, system_prompt, user_input):
26
  model=model_id,
27
  messages=messages,
28
  max_tokens=500,
 
29
  stream=True
30
  ):
31
  if hasattr(chunk, "choices") and chunk.choices and len(chunk.choices) > 0:
@@ -39,7 +39,6 @@ def run_council(user_prompt, rounds):
39
  history = [{"role": "user", "content": user_prompt}]
40
  yield history
41
 
42
- # Hier speichern wir fortlaufend den gesamten Chatverlauf
43
  discussion_history = ""
44
 
45
  for r in range(int(rounds)):
@@ -47,38 +46,36 @@ def run_council(user_prompt, rounds):
47
  history.append({"role": "assistant", "content": round_header})
48
  yield history
49
 
50
- for name, model_id in COUNCIL_MEMBERS.items():
51
- # Der neue, neutrale System-Prompt für alle
 
 
52
  system_msg = (
53
- "Du bist Mitglied eines Expertenrates. Antworte in 2-3 Sätzen. "
54
- "WICHTIG: Sei analytisch und kritisch. Wiederhole NICHT einfach, was schon gesagt wurde. "
55
- "Wenn du zustimmst, füge zwingend eine völlig neue Perspektive oder einen neuen Fakt hinzu. "
56
  "Wenn jemand ein schwaches Argument liefert oder Details übergeht, weise höflich aber bestimmt darauf hin."
57
  )
58
 
59
- # Die Anweisung an das Modell ändert sich, je nachdem ob es der erste Sprecher ist oder nicht
60
  if discussion_history == "":
61
  current_prompt = f"Die Frage an den Rat lautet: '{user_prompt}'. Bitte eröffne die Diskussion mit deiner ersten Einschätzung."
62
  else:
63
  current_prompt = (
64
  f"Die ursprüngliche Frage lautet: '{user_prompt}'.\n\n"
65
  f"Bisheriges Protokoll der Sitzung:\n{discussion_history}\n\n"
66
- f"Du bist nun an der Reihe. Bitte reagiere auf die bisherigen Aussagen deiner Vorredner und füge deine eigene Perspektive hinzu."
67
  )
68
 
69
  answer = ask_model(model_id, system_msg, current_prompt)
70
  formatted_answer = f"**{name}**: {answer}"
71
 
72
- # WICHTIG: Wir updaten die History SOFORT. Das nächste Modell in der Schleife
73
- # liest diesen Text also direkt im nächsten Durchlauf als "Bisheriges Protokoll".
74
  discussion_history += f"{formatted_answer}\n\n"
75
 
76
  history.append({"role": "assistant", "content": formatted_answer})
77
  yield history
78
 
79
- # Finale Zusammenfassung durch den Moderator
80
  mod_prompt = f"Das ursprüngliche Thema war: '{user_prompt}'.\n\nHier ist das komplette Protokoll des Rates:\n{discussion_history}\n\nFasse den gefundenen Konsens oder die Kernpunkte in 3 Sätzen zusammen."
81
- final_res = ask_model(MODERATOR_MODEL, "Du bist der Moderator des Rates.", mod_prompt)
82
 
83
  history.append({"role": "assistant", "content": "### 🏆 FINALE ENTSCHEIDUNG"})
84
  history.append({"role": "assistant", "content": final_res})
@@ -89,7 +86,7 @@ with gr.Blocks() as demo:
89
  gr.Markdown("# 🏛️ PromptPlenum42")
90
 
91
  with gr.Row():
92
- input_text = gr.Textbox(label="Deine Frage", placeholder="Ist das Holodeck sicher?")
93
  rounds_slider = gr.Slider(minimum=1, maximum=3, value=1, step=1, label="Diskussionszyklen")
94
 
95
  start_btn = gr.Button("Protokoll starten", variant="primary")
 
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
+ # Die Ratsmitglieder - Jetzt mit Tupeln für Modell und thematischen Fokus
 
6
  COUNCIL_MEMBERS = {
7
  "Mitglied 1 (Llama)": ("meta-llama/Llama-3.3-70B-Instruct", "Fokus auf Philosophie, Logik und das große Ganze."),
8
  "Mitglied 2 (DeepSeek)": ("deepseek-ai/DeepSeek-V3", "Fokus auf harte Fakten, Mathematik, Physik und Naturwissenschaften."),
 
25
  model=model_id,
26
  messages=messages,
27
  max_tokens=500,
28
+ temperature=0.7, # Etwas mehr Kreativität für die Diskussion
29
  stream=True
30
  ):
31
  if hasattr(chunk, "choices") and chunk.choices and len(chunk.choices) > 0:
 
39
  history = [{"role": "user", "content": user_prompt}]
40
  yield history
41
 
 
42
  discussion_history = ""
43
 
44
  for r in range(int(rounds)):
 
46
  history.append({"role": "assistant", "content": round_header})
47
  yield history
48
 
49
+ # HIER IST DER FIX: Wir entpacken das Tuple direkt in model_id und role_focus
50
+ for name, (model_id, role_focus) in COUNCIL_MEMBERS.items():
51
+
52
+ # Der dynamische System-Prompt
53
  system_msg = (
54
+ f"Du bist Mitglied eines Expertenrates. Dein spezifischer Fokus in dieser Diskussion: {role_focus} "
55
+ "Antworte in 2-3 Sätzen. WICHTIG: Sei analytisch und kritisch. Wiederhole NICHT einfach, was schon gesagt wurde. "
56
+ "Wenn du zustimmst, füge zwingend eine völlig neue Perspektive oder einen neuen Fakt aus deinem Fokus-Bereich hinzu. "
57
  "Wenn jemand ein schwaches Argument liefert oder Details übergeht, weise höflich aber bestimmt darauf hin."
58
  )
59
 
 
60
  if discussion_history == "":
61
  current_prompt = f"Die Frage an den Rat lautet: '{user_prompt}'. Bitte eröffne die Diskussion mit deiner ersten Einschätzung."
62
  else:
63
  current_prompt = (
64
  f"Die ursprüngliche Frage lautet: '{user_prompt}'.\n\n"
65
  f"Bisheriges Protokoll der Sitzung:\n{discussion_history}\n\n"
66
+ f"Du bist nun an der Reihe. Bitte reagiere auf die bisherigen Aussagen deiner Vorredner und bringe deine Perspektive ein."
67
  )
68
 
69
  answer = ask_model(model_id, system_msg, current_prompt)
70
  formatted_answer = f"**{name}**: {answer}"
71
 
 
 
72
  discussion_history += f"{formatted_answer}\n\n"
73
 
74
  history.append({"role": "assistant", "content": formatted_answer})
75
  yield history
76
 
 
77
  mod_prompt = f"Das ursprüngliche Thema war: '{user_prompt}'.\n\nHier ist das komplette Protokoll des Rates:\n{discussion_history}\n\nFasse den gefundenen Konsens oder die Kernpunkte in 3 Sätzen zusammen."
78
+ final_res = ask_model(MODERATOR_MODEL, "Du bist der Moderator des Rates. Antworte neutral und sachlich.", mod_prompt)
79
 
80
  history.append({"role": "assistant", "content": "### 🏆 FINALE ENTSCHEIDUNG"})
81
  history.append({"role": "assistant", "content": final_res})
 
86
  gr.Markdown("# 🏛️ PromptPlenum42")
87
 
88
  with gr.Row():
89
+ input_text = gr.Textbox(label="Deine Frage", placeholder="Sollten wir KI regulieren?")
90
  rounds_slider = gr.Slider(minimum=1, maximum=3, value=1, step=1, label="Diskussionszyklen")
91
 
92
  start_btn = gr.Button("Protokoll starten", variant="primary")