-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathsdk.py
More file actions
138 lines (112 loc) · 4.13 KB
/
sdk.py
File metadata and controls
138 lines (112 loc) · 4.13 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import requests
class GameSDK:
api_url: str = "https://game-api.virtuals.io/api"
api_key: str
eval_api_url: str = "https://api.evaengine.ai/api"
def __init__(self, api_key: str):
self.api_key = api_key
def functions(self):
"""
Get all default functions
"""
response = requests.get(
f"{self.api_url}/functions", headers={"x-api-key": self.api_key})
if (response.status_code != 200):
raise Exception(response.json())
functions = {}
for x in response.json()["data"]:
functions[x["fn_name"]] = x["fn_description"]
return functions
def simulate(self, session_id: str, goal: str, description: str, world_info: str, functions: list, custom_functions: list):
"""
Simulate the agent configuration
"""
response = requests.post(
f"{self.api_url}/simulate",
json={
"data": {
"sessionId": session_id,
"goal": goal,
"description": description,
"worldInfo": world_info,
"functions": functions,
"customFunctions": [x.toJson() for x in custom_functions]
}
},
headers={"x-api-key": self.api_key}
)
if (response.status_code != 200):
raise Exception(response.json())
return response.json()["data"]
def react(self, session_id: str, platform: str, goal: str,
description: str, world_info: str, functions: list, custom_functions: list,
event: str = None, task: str = None, tweet_id: str = None):
"""
Simulate the agent configuration
"""
url = f"{self.api_url}/react/{platform}"
payload = {
"sessionId": session_id,
"goal": goal,
"description": description,
"worldInfo": world_info,
"functions": functions,
"customFunctions": [x.toJson() for x in custom_functions]
}
if (event):
payload["event"] = event
if (task):
payload["task"] = task
if (tweet_id):
payload["tweetId"] = tweet_id
print(payload)
response = requests.post(
url,
json={
"data": payload
},
headers={"x-api-key": self.api_key}
)
if (response.status_code != 200):
raise Exception(response.json())
return response.json()["data"]
def eval_react(self, input_tweet: str, output_tweet: str):
"""
Evaluate the agent reply
Checkout your eval dashboard here: https://evaengine.ai/virtuals (import your api key to view)
"""
response = requests.post(
f"{self.eval_api_url}/eval/evaluate-tweet",
headers={"x-api-key": self.api_key},
json={
"input_tweet": input_tweet,
"output_tweet": output_tweet
}
)
if (response.status_code != 200):
raise Exception(response.json())
return response.json()
def deploy(self, goal: str, description: str, world_info: str, functions: list, custom_functions: list, main_heartbeat: int, reaction_heartbeat: int):
"""
Simulate the agent configuration
"""
response = requests.post(
f"{self.api_url}/deploy",
json={
"data": {
"goal": goal,
"description": description,
"worldInfo": world_info,
"functions": functions,
"customFunctions": custom_functions,
"gameState" : {
"mainHeartbeat" : main_heartbeat,
"reactionHeartbeat" : reaction_heartbeat,
}
}
},
headers={"x-api-key": self.api_key}
)
if (response.status_code != 200):
raise Exception(response.json())
return response.json()["data"]