Spaces:
Sleeping
Sleeping
minor changes, and debate initialization with CoRE
Browse files- app.py +15 -3
- multi_agent_debate.py +16 -2
app.py
CHANGED
@@ -225,14 +225,14 @@ def reasoner(query: str, documents: list[str], selected_dreamer: str, selected_r
|
|
225 |
else:
|
226 |
prompt_template = Template(templates["with_evidence"])
|
227 |
prompt = prompt_template.substitute(claim=query, corpus_text=documents)
|
228 |
-
elif selected_dreamer == 'CoRE' or selected_dreamer == 'CoRE-Contrastive':
|
229 |
conditions = [""]
|
230 |
prompt_template = Template(templates["generate_condition"])
|
231 |
prompt = prompt_template.substitute(claim=query)
|
232 |
prompt = get_examples() + prompt + " answer: "
|
233 |
print(prompt)
|
234 |
|
235 |
-
message += f"Using {selected_dreamer} to
|
236 |
display_to_chat(placeholder, message)
|
237 |
placeholder = st.empty()
|
238 |
|
@@ -243,7 +243,7 @@ def reasoner(query: str, documents: list[str], selected_dreamer: str, selected_r
|
|
243 |
|
244 |
condition = conditions[0] if selected_dreamer == 'CoRE' else conditions[1]
|
245 |
|
246 |
-
message = "To reason about the claim, CoRE is
|
247 |
|
248 |
if not documents or len(documents) == 0:
|
249 |
prompt_template = Template(templates["with_condition"])
|
@@ -277,6 +277,17 @@ def reasoner(query: str, documents: list[str], selected_dreamer: str, selected_r
|
|
277 |
prompt = prompt_template.substitute(claim=query, corpus_text=documents)
|
278 |
|
279 |
if selected_reasoner == "Multi Agent Debate":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
multi_agent_debate = MultiAgentDebate(client=llm_client.client)
|
281 |
initial_evidence = "" if (not documents or len(documents)==0) else documents[0]
|
282 |
def mad_printer(msg, explanation):
|
@@ -289,6 +300,7 @@ def reasoner(query: str, documents: list[str], selected_dreamer: str, selected_r
|
|
289 |
|
290 |
decision = multi_agent_debate(claim=query,
|
291 |
doc=initial_evidence,
|
|
|
292 |
writer=mad_printer)
|
293 |
reasoning = "of the debate and discussion."
|
294 |
else:
|
|
|
225 |
else:
|
226 |
prompt_template = Template(templates["with_evidence"])
|
227 |
prompt = prompt_template.substitute(claim=query, corpus_text=documents)
|
228 |
+
elif (selected_dreamer == 'CoRE' or selected_dreamer == 'CoRE-Contrastive') and selected_reasoner != "Multi Agent Debate":
|
229 |
conditions = [""]
|
230 |
prompt_template = Template(templates["generate_condition"])
|
231 |
prompt = prompt_template.substitute(claim=query)
|
232 |
prompt = get_examples() + prompt + " answer: "
|
233 |
print(prompt)
|
234 |
|
235 |
+
message += f"Using {selected_dreamer} to decompose and elaborate the claim..."
|
236 |
display_to_chat(placeholder, message)
|
237 |
placeholder = st.empty()
|
238 |
|
|
|
243 |
|
244 |
condition = conditions[0] if selected_dreamer == 'CoRE' else conditions[1]
|
245 |
|
246 |
+
message = "To reason about the claim, CoRE is considering the potential condition: " + condition + "\n\n\n\n"
|
247 |
|
248 |
if not documents or len(documents) == 0:
|
249 |
prompt_template = Template(templates["with_condition"])
|
|
|
277 |
prompt = prompt_template.substitute(claim=query, corpus_text=documents)
|
278 |
|
279 |
if selected_reasoner == "Multi Agent Debate":
|
280 |
+
initial_agent_beliefs=None
|
281 |
+
if selected_dreamer == 'CoRE' or selected_dreamer == 'CoRE-Contrastive':
|
282 |
+
conditions = [""]
|
283 |
+
prompt_template = Template(templates["generate_condition"])
|
284 |
+
prompt = prompt_template.substitute(claim=query)
|
285 |
+
prompt = get_examples() + prompt + " answer: "
|
286 |
+
llm_response = llm_client.run_inference(prompt)
|
287 |
+
initial_agent_beliefs = llm_response.split('\n\n')
|
288 |
+
print(initial_agent_beliefs)
|
289 |
+
|
290 |
+
|
291 |
multi_agent_debate = MultiAgentDebate(client=llm_client.client)
|
292 |
initial_evidence = "" if (not documents or len(documents)==0) else documents[0]
|
293 |
def mad_printer(msg, explanation):
|
|
|
300 |
|
301 |
decision = multi_agent_debate(claim=query,
|
302 |
doc=initial_evidence,
|
303 |
+
initial_agent_responses=initial_agent_beliefs,
|
304 |
writer=mad_printer)
|
305 |
reasoning = "of the debate and discussion."
|
306 |
else:
|
multi_agent_debate.py
CHANGED
@@ -433,6 +433,7 @@ class MultiAgentDebate:
|
|
433 |
print(x)
|
434 |
|
435 |
def __call__(self, doc, claim, initialization=True, model_name='gpt-4o-mini',
|
|
|
436 |
writer=safe_print):
|
437 |
# number of simultaneous debates for evaluation
|
438 |
num_debates = 1
|
@@ -455,7 +456,19 @@ class MultiAgentDebate:
|
|
455 |
## more utterances
|
456 |
|
457 |
if initialization:
|
458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
else:
|
460 |
agents_responses = ["","","",""]
|
461 |
|
@@ -477,7 +490,8 @@ class MultiAgentDebate:
|
|
477 |
if initialization:
|
478 |
print("ROUND %s: (This is the initialization round where agents are assigned initial stance as their beliefs.)\n"%str(round_counter+1))
|
479 |
for n in range(len(agents_responses)):
|
480 |
-
writer("Agent %s: "%str(n+1) + agents_responses[n] + "\n",
|
|
|
481 |
print("----------------------------------------------------")
|
482 |
round_counter += 1
|
483 |
print("ROUND %s:\n"%str(round_counter+1))
|
|
|
433 |
print(x)
|
434 |
|
435 |
def __call__(self, doc, claim, initialization=True, model_name='gpt-4o-mini',
|
436 |
+
initial_agent_responses=None,
|
437 |
writer=safe_print):
|
438 |
# number of simultaneous debates for evaluation
|
439 |
num_debates = 1
|
|
|
456 |
## more utterances
|
457 |
|
458 |
if initialization:
|
459 |
+
if initial_agent_responses is None:
|
460 |
+
agents_responses = ["The claim is not refuted by evidence.", "The claim is refuted by evidence.", "The claim is not refuted by evidence.", "The claim is refuted by evidence."]
|
461 |
+
else:
|
462 |
+
agents_responses = []
|
463 |
+
for n in range(4):
|
464 |
+
if n < len(initial_agent_responses):
|
465 |
+
agents_responses.append(initial_agent_responses[n])
|
466 |
+
else:
|
467 |
+
if n % 2 == 0:
|
468 |
+
agents_responses.append("The claim is not refuted by evidence.")
|
469 |
+
else:
|
470 |
+
agents_responses.append("The claim is refuted by evidence.")
|
471 |
+
|
472 |
else:
|
473 |
agents_responses = ["","","",""]
|
474 |
|
|
|
490 |
if initialization:
|
491 |
print("ROUND %s: (This is the initialization round where agents are assigned initial stance as their beliefs.)\n"%str(round_counter+1))
|
492 |
for n in range(len(agents_responses)):
|
493 |
+
writer("Agent %s: "%str(n+1) + agents_responses[n] + "\n",
|
494 |
+
"This is my initial belief.")
|
495 |
print("----------------------------------------------------")
|
496 |
round_counter += 1
|
497 |
print("ROUND %s:\n"%str(round_counter+1))
|