egasparovic-asante commited on
Commit
acd3601
·
1 Parent(s): 9a8c112

feat(app.py): add treasure map game

Browse files
Files changed (1) hide show
  1. app.py +49 -8
app.py CHANGED
@@ -4,19 +4,58 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -38,7 +77,9 @@ final_answer = FinalAnswerTool()
38
  model = HfApiModel(
39
  max_tokens=2096,
40
  temperature=0.5,
41
- model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
 
 
42
  custom_role_conversions=None,
43
  )
44
 
@@ -51,7 +92,7 @@ with open("prompts.yaml", 'r') as stream:
51
 
52
  agent = CodeAgent(
53
  model=model,
54
- tools=[final_answer], ## add your tools here (don't remove final answer)
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import random
8
 
9
  from Gradio_UI import GradioUI
10
 
11
+ class Position:
12
+ def __init__(self, x: int, y: int):
13
+ self.x = x
14
+ self.y = y
15
+
16
+ class TreasureMapGame:
17
+ def __init__(self):
18
+ self.treasure_position = None
19
+ self.position = None
20
+
21
+ self.initialize_game()
22
+
23
+ def initialize_game(self):
24
+ self.treasure_position = Position(random.randint(-10, 10), random.randint(-10, 10))
25
+ self.position = Position(0, 0)
26
+
27
+ def check_distance(self) -> str:
28
+ distance = abs(self.treasure_position.x - self.position.x) + abs(self.treasure_position.y - self.position.y)
29
+ if distance == 0:
30
+ message = "You found the treasure!"
31
+ self.initialize_game()
32
+ else:
33
+ message = f"You are {distance} steps away from the treasure."
34
+ return message
35
+
36
+ def move(self, direction: str, steps: int):
37
+ if direction == "left":
38
+ self.position.x -= steps
39
+ if direction == "right":
40
+ self.position.x += steps
41
+ if direction == "down":
42
+ self.position.y -= steps
43
+ if direction == "up":
44
+ self.position.y += steps
45
+
46
+ game = TreasureMapGame()
47
+
48
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
49
  @tool
50
+ def move(direction:str, steps:int) -> str: #it's import to specify the return type
51
+ """A tool that moves your position to find the hidden treasure in the Treasure Map Game. Returns a message indicating the distance to the treasure.
 
52
  Args:
53
+ direction: One of 'left', 'right', 'up' or 'down'
54
+ steps: Amount of steps to move in the specified direction
55
  """
56
+ game.move(direction, steps)
57
+ status = game.check_distance()
58
+ return status
59
 
60
  @tool
61
  def get_current_time_in_timezone(timezone: str) -> str:
 
77
  model = HfApiModel(
78
  max_tokens=2096,
79
  temperature=0.5,
80
+ # model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
81
+ # model_id='mistralai/Mistral-7B-Instruct-v0.3',
82
+ model_id='deepseek-ai/DeepSeek-R1-Distill-Qwen-32B',
83
  custom_role_conversions=None,
84
  )
85
 
 
92
 
93
  agent = CodeAgent(
94
  model=model,
95
+ tools=[final_answer, move, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
96
  max_steps=6,
97
  verbosity_level=1,
98
  grammar=None,