-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_predicates.py
More file actions
36 lines (23 loc) · 1.1 KB
/
extract_predicates.py
File metadata and controls
36 lines (23 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from openai_lib.api import Gpt4oInterface
from pydantic import BaseModel
import shelve
class PredicatesExtractor(BaseModel):
predicates: list[str]
api = Gpt4oInterface()
instructions = """
You are working with the prolog programing language and you need to create a script to solve logical puzzles.
A logical puzzle will be inputed and you must extract the predicates that need to be declared in the prolog script, including conditional predicates.
The predicates must not be generic, they must represent the actual ammout of entities and contitions in the puzzle.
Each individual predicate is a single string of text. Output all predicates extracted from that logical puzzle.
Prolog predicates must end with a period.
"""
extractor_resolver = api.of_format(PredicatesExtractor, instructions)
def main():
with shelve.open("extracted") as db:
prompt = db["prompt"]
extracted = extractor_resolver(prompt)
with open("prolog/reasoning.pl", "w") as f:
for predicate in extracted.predicates:
f.write(predicate + "\n")
for p in extracted.predicates:
print(p)