-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4o_statements_obj2.py
More file actions
54 lines (41 loc) · 1.76 KB
/
gpt4o_statements_obj2.py
File metadata and controls
54 lines (41 loc) · 1.76 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pandas as pd
from openai import OpenAI
from tqdm import tqdm
client = OpenAI(api_key="")
df = pd.read_csv("3countries_reddit.csv")
df = df[df.source != 'human']
def build_prompt(question, country):
return f"""
You are a culturally aware assistant from {country}.
Given the question: {question}, generate a short conversational-style statement that someone might say, which could naturally lead another person to ask this question in the cultural context of {country}.
Do not answer the question — only provide the preceding statement.
Examples:
Country: Germany
Question: "Is it acceptable to arrive 10 minutes late to a dinner party?"
Statement: "I’m thinking of showing up a bit after the dinner party starts."
Country: India
Question: "Is it acceptable to eat with the left hand during a meal?"
Statement: "I sometimes use my left hand when eating."
Country: Egypt
Question: "Is it polite to greet everyone individually at a gathering?"
Statement: "Whenever I walk into a room, I like to greet each person one by one."
Now generate the statement (in English) for:
Country: {country}
Question: {question}
Statement:
"""
statements = []
for idx, row in tqdm(df.iterrows(), total=len(df), desc="Generating initial statements"):
country, question = row["country"], row["question"]
prompt = build_prompt(question, country)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": prompt}],
temperature=0.6,
max_tokens=300
)
stmt = response.choices[0].message.content.strip()
statements.append(stmt)
df["initial_statements"] = statements
df.to_csv("gpt4o_statements_reddit.csv", index=False)
print("\nSaved output to gpt4o_statements_reddit.csv")