-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcerebras_few_shot.py
76 lines (58 loc) · 1.77 KB
/
cerebras_few_shot.py
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
68
69
70
71
72
73
74
75
76
import json
import os
from dotenv import load_dotenv
from cerebras.cloud.sdk import Cerebras
from betamark import arc_agi
load_dotenv()
EVAL_CHALELNGES_FILEPATH = "data/arc-agi_evaluation_challenges.json"
eval_challenges_json = json.load(open(EVAL_CHALELNGES_FILEPATH, "r"))
def few_shot_cerebras_predict(input_dict):
PROMPT = """
What is the output to this sequence?
Only answer as a double list
"""
for i in range(len(input_dict["train"])):
input = input_dict["train"][i]["input"]
PROMPT += f'\n"input": {input}'
output = input_dict["train"][i]["output"]
PROMPT += f'\n"output": {output}'
PROMPT += f'\n"input": {input_dict["test"][0]["input"]}'
# print(PROMPT)
client = Cerebras(
# This is the default and can be omitted
api_key=os.environ.get("CEREBRAS_API_KEY"),
)
try:
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": PROMPT,
}
],
model="llama3.1-70b",
)
except:
return [[0]]
# print("######")
# print(chat_completion.choices[0].message.content)
# raise KeyError
list_repr_string = chat_completion.choices[0].message.content
list_repr_string = (
list_repr_string.replace("```json", "")
.replace("```python", "")
.replace("```", "")
)
try:
list_repr = eval(list_repr_string)
# print(list_repr)
# print(type(list_repr))
return list_repr
except:
pass
# print("error!")
return [[0]]
return [[0]]
if __name__ == "__main__":
results = arc_agi.run_eval(user_func=few_shot_cerebras_predict)
print(results)