| 2 | |
| 3 | |
| 4 | class GameSDK: |
| 5 | api_url: str = "https://game-api.virtuals.io/api" |
| 6 | api_key: str |
| 7 | |
| 8 | def __init__(self, api_key: str): |
| 9 | self.api_key = api_key |
| 10 | |
| 11 | def functions(self): |
| 12 | """ |
| 13 | Get all default functions |
| 14 | """ |
| 15 | response = requests.get( |
| 16 | f"{self.api_url}/functions", headers={"x-api-key": self.api_key}) |
| 17 | |
| 18 | if (response.status_code != 200): |
| 19 | raise Exception(response.json()) |
| 20 | |
| 21 | functions = {} |
| 22 | |
| 23 | for x in response.json()["data"]: |
| 24 | functions[x["fn_name"]] = x["fn_description"] |
| 25 | |
| 26 | return functions |
| 27 | |
| 28 | def simulate(self, session_id: str, goal: str, description: str, world_info: str, functions: list, custom_functions: list): |
| 29 | """ |
| 30 | Simulate the agent configuration |
| 31 | """ |
| 32 | response = requests.post( |
| 33 | f"{self.api_url}/simulate", |
| 34 | json={ |
| 35 | "data": { |
| 36 | "sessionId": session_id, |
| 37 | "goal": goal, |
| 38 | "description": description, |
| 39 | "worldInfo": world_info, |
| 40 | "functions": functions, |
| 41 | "customFunctions": [x.toJson() for x in custom_functions] |
| 42 | } |
| 43 | }, |
| 44 | headers={"x-api-key": self.api_key} |
| 45 | ) |
| 46 | |
| 47 | if (response.status_code != 200): |
| 48 | raise Exception(response.json()) |
| 49 | |
| 50 | return response.json()["data"] |
| 51 | |
| 52 | def react(self, session_id: str, platform: str, goal: str, |
| 53 | description: str, world_info: str, functions: list, custom_functions: list, |
| 54 | event: str = None, task: str = None, tweet_id: str = None): |
| 55 | """ |
| 56 | Simulate the agent configuration |
| 57 | """ |
| 58 | url = f"{self.api_url}/react/{platform}" |
| 59 | |
| 60 | payload = { |
| 61 | "sessionId": session_id, |
nothing calls this directly
no outgoing calls
no test coverage detected