panda992 commited on
Commit
6dbc67d
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -9
app.py CHANGED
@@ -9,14 +9,34 @@ 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_custom_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:
@@ -55,13 +75,13 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
62
  planning_interval=None,
63
- name=None,
64
- description=None,
65
  prompt_templates=prompt_templates
66
  )
67
 
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def ask_stock_price() -> str:
13
+ """Asks the user for a stock name and fetches its price."""
14
+ company = input("Enter the company name or stock symbol: ").strip()
15
+ return get_stock_price(company)
16
+
17
+ @tool
18
+ def get_stock_price(company: str) -> str:
19
+ """Fetches the current stock price of an Indian company using DuckDuckGo search.
20
  Args:
21
+ company: The name or symbol of the company (e.g., 'Reliance', 'TCS')
 
22
  """
23
+ search_tool = DuckDuckGoSearchTool()
24
+
25
+ # Construct the search query
26
+ query = f"{company} stock price today india "
27
+
28
+ # Perform the search
29
+ search_results = search_tool(query)
30
+
31
+ # Extract stock price using regex (pattern for ₹ price)
32
+ match = re.search(r"₹\s?([\d,]+\.?\d*)", search_results)
33
+
34
+ if match:
35
+ price = match.group(0)
36
+ return f"The current stock price of {company} is {price}."
37
+ else:
38
+ return f"Could not find the stock price for {company}. Please check manually."
39
+
40
 
41
  @tool
42
  def get_current_time_in_timezone(timezone: str) -> str:
 
75
 
76
  agent = CodeAgent(
77
  model=model,
78
+ tools=[final_answer,get_stock_price], ## add your tools here (don't remove final answer)
79
  max_steps=6,
80
  verbosity_level=1,
81
  grammar=None,
82
  planning_interval=None,
83
+ name="Stock Price Agent india",
84
+ description="",
85
  prompt_templates=prompt_templates
86
  )
87