-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponses.py
More file actions
68 lines (55 loc) · 1.96 KB
/
responses.py
File metadata and controls
68 lines (55 loc) · 1.96 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
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import anthropic
import base64
def load_prompt():
with open("prompt.txt", "r") as file:
return file.read()
main_prompt = load_prompt()
def image_group_content(problem, side):
group_content = []
group_content.append({"type": "text", "text": f"The following 6 images form the '{side}' group."})
for i in range(1, 7):
with open(f"problems/{problem}/{side}_image_{i}.png", 'rb') as image_file:
image_base64 = base64.b64encode(image_file.read()).decode("utf-8")
group_content.append(
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": image_base64,
},
}
)
return group_content
def problem_content(problem):
content = [{"type": "text", "text": "What follows is a Bongard problem."}]
content.extend(image_group_content(problem, "left"))
content.extend(image_group_content(problem, "right"))
content.append({"type": "text", "text": main_prompt})
return content
def get_response(problem, model):
client = anthropic.Anthropic()
content = problem_content(problem)
message = client.messages.create(
model=model,
max_tokens=1024,
messages=[
{
"role": "user",
"content": content
}
],
)
return message
if __name__ == "__main__":
model = "claude-3-opus-20240229"
# model = "claude-3-haiku-20240307"
for problem in range(68, 101):
print(f"Processing problem number: {problem}")
message = get_response(problem, model)
response_content = message.content[0].text
problem_folder = f"problems/{problem}/{model}"
os.makedirs(problem_folder, exist_ok=True)
with open(f"{problem_folder}/response.txt", 'w') as file:
file.write(response_content)