Skip to content

Commit d66cd5d

Browse files
committed
Added real prompt templates for explanation
1 parent 43c439f commit d66cd5d

4 files changed

Lines changed: 61 additions & 7 deletions

File tree

src/explaidllm/cli/clingo_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,5 @@ def main(self, control: clingo.Control, files: Sequence[str]) -> None:
106106

107107
llm = OpenAIModel(ModelTag.GPT_4O_MINI)
108108
logger.info("Prompting Model")
109-
response = llm.prompt_template(ExplainTemplate(program="", mus=mus))
109+
response = llm.prompt_template(template=ExplainTemplate(program="", assumptions=ap.assumptions, mus=mus, unsatisfiable_constraints=ucs.values()))
110110
logger.info(f"Received Response:\n{response}")
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Basic Explanation Prompt Template"""
2-
32
from pathlib import Path
3+
from typing import Iterable, Set, Tuple
44

55
from clingexplaid.mus.core_computer import UnsatisfiableSubset
6+
from clingo import Symbol
67

78
from .base import Template
89

@@ -13,18 +14,23 @@
1314
class ExplainTemplate(Template):
1415
"""Basic Explanation Prompt Template"""
1516

16-
def __init__(self, program: str, mus: UnsatisfiableSubset):
17+
def __init__(self, program: str, assumptions: Set[Tuple[Symbol, bool]], mus: UnsatisfiableSubset, unsatisfiable_constraints: Iterable[str]):
1718
self._program: str = program
19+
self._assumptions: Set[Tuple[Symbol, bool]] = assumptions
1820
self._mus: UnsatisfiableSubset = mus
21+
self._unsatisfiable_constraints = unsatisfiable_constraints
1922

2023
def compose_instructions(self) -> str:
2124
with open(Path(__file__).parent / PROMPT_FILE_INSTRUCTIONS, "r", encoding="utf-8") as prompt_file:
2225
prompt_template = prompt_file.read()
23-
prompt = prompt_template.format()
26+
prompt = prompt_template
2427
return prompt
2528

2629
def compose_input(self) -> str:
2730
with open(Path(__file__).parent / PROMPT_FILE_INPUT, "r", encoding="utf-8") as prompt_file:
2831
prompt_template = prompt_file.read()
29-
prompt = prompt_template.format(program=self._program, mus=self._mus)
32+
p_assumptions = ", ".join([f"({str(a[0])},{a[1]})" for a in self._assumptions])
33+
p_mus = ", ".join([f"({str(a.symbol)},{a.sign})" for a in self._mus.assumptions])
34+
p_ucs = ", ".join([f"'{uc}'" for uc in self._unsatisfiable_constraints])
35+
prompt = prompt_template.format(program=self._program, assumptions=p_assumptions, mus=p_mus, ucs=p_ucs)
3036
return prompt
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
This is a placeholder input. Just say "Hello World!" back
1+
User Input:
2+
{{
3+
"program": "{program}",
4+
"assumptions": [{assumptions}],
5+
"mus": [{mus}],
6+
"unsatisfiable_constraints": [{ucs}],
7+
}}
Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
1-
This is a placeholder instruction
1+
You are an expert debugger of Answer Set Programming. You will receive an ASP program that is unsatisfiable under a set
2+
of assumptions. In addition to the program rules and assumptions, you will receive a Minimal Unsatisfiable Subset (mus)
3+
of these assumptions that leads to the program becoming unsatisfiable. There will also be one or more unsatisfiable
4+
constraints provided, which are the ones from the program that fire to make it unsatisfiable.
5+
6+
Your task is to provide a simple and short natural language explanation to the user that explains what the
7+
unsatisfiability is and why it occurs. Follow the structure of the examples below.
8+
9+
EXAMPLE 1 START
10+
11+
Input:
12+
{
13+
"program": "
14+
number(1..4).
15+
16+
sudoku(X,Y,V) :- initial(X,Y,V).
17+
{sudoku(X,Y,N): number(N)}=1 :- number(X) ,number(Y).
18+
cage(X1,Y1,X2,Y2) :- sudoku(X1,Y1,_), sudoku(X2,Y2,_),
19+
((X1-1)/2)==((X2-1)/2),
20+
((Y1-1)/2)==((Y2-1)/2).
21+
22+
:- sudoku(X,Y1,N), sudoku(X,Y2,N), Y1 != Y2.
23+
:- sudoku(X1,Y,N), sudoku(X2,Y,N), X1 != X2.
24+
:- cage(X1,Y1,X2,Y2), sudoku(X1,Y1,N), sudoku(X2,Y2,N), X1!=X2, Y1!=Y2.
25+
26+
#show sudoku/3.
27+
",
28+
"assumptions": [("sudoku(1,1,1)", True), ("sudoku(3,2,2)", True), ("sudoku(2,3,4)", True), ("sudoku(4,3,4)", True)],
29+
"mus": [("sudoku(2,3,4)", True), ("sudoku(4,3,4)", True)],
30+
"unsatisfiable_constraints": [
31+
":- sudoku(X1,Y,N), sudoku(X2,Y,N), X1 != X2."
32+
]
33+
}
34+
Output:
35+
{
36+
"explanation": "
37+
The program is unsatisfiable because sudoku(2,3,4) and sudoku(4,3,4) trigger the constraint
38+
':- sudoku(X1,Y,N), sudoku(X2,Y,N), X1 != X2.' which prohibits having the same value N two times with the same Y
39+
value.
40+
"
41+
}
42+
43+
EXAMPLE 1 END

0 commit comments

Comments
 (0)