-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_gpt.py
More file actions
39 lines (37 loc) · 2.25 KB
/
query_gpt.py
File metadata and controls
39 lines (37 loc) · 2.25 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
36
37
38
39
import pandas as pd
from openai import OpenAI
client = OpenAI()
df = pd.read_csv('./Merged_LLU.csv', sep=';')
for i in range(df.shape[0]):
response = client.responses.create(
model="o1",
input=[
{"role": "system",
"content": "You are an expert in Answer Set Programming (ASP). Do not output comments or anything other "
"than facts and rules. In your response, you must use the following atoms: "
"'statement(ID, S, P, O)', where 'ID' is the ID of the sentence, 'S' is the main subject, "
"'P' is the main predicate, and 'O' is the object of the sentence; "
"'weapon(ID, W)', where 'ID' is the ID of the sentence, and 'W' is the weapon involved "
"in the predicate P; "
"'incompatible_object(P, O)', where 'O' is an object and 'P' is a predicate of the same "
"sentence that cannot be done using the object O; "
"'incompatible_predicates(P1, P2)', where 'P1' and 'P2' are two different predicates which "
"are not synonyms of each other. "
"Example of sentences: "
"Sentence1: 'Yesterday, Will said that he saw Mary killing Peter.' "
"Sentence2: 'But in front of the judge, Will swore that he saw Mary beating Peter. "
"Example of output: statement(s1, mary, kill, peter). statement(s2, mary, beat, peter). "
"incompatible_predicates(kill, beat)."
},
{"role": "user", "content": [
{"type": "input_text",
"text": "Return ASP facts that model the event involved in the following sentences and their possible "
"incompatibilities. If necessary, when you find two words that are similar or synonyms, "
"keep only one of the two words. "
f"Sentence1: '{df['sentence1'].iloc[i]}' "
f"Sentence2: '{df['sentence2'].iloc[i]}' "}
]}
]
)
with open(f'./output/output_o1_{i}.asp', 'w', encoding="utf-8") as f:
f.write(response.output_text)