RamiNuraliyev commited on
Commit
b6a5402
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -6
app.py CHANGED
@@ -9,14 +9,46 @@ 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:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def calculate_min_price(price1:float, price2:float)-> str: #it's import to specify the return type
13
+ """A tool that calculates the min price of two numerical values
 
14
  Args:
15
+ price1: price of one product
16
+ price2: price of second product
17
  """
18
+ min_price = str(min(price1,price2))
19
+ return f"The minimum price is {min_price}"
20
+
21
+ def extract_price_from_snippet(snippet):
22
+ """
23
+ A simple function to extract prices from a text snippet using regex.
24
+ You can enhance this function for more complex price extraction.
25
+ """
26
+ # A basic regular expression to detect common price formats like $29.99, 29.99 USD, etc.
27
+ price_pattern = r'\$\d+(?:,\d{3})*(?:\.\d{2})?|\d+(?:,\d{3})*(?:\.\d{2})?\s*(USD|EUR|GBP|INR|AUD|CAD)?'
28
+ matches = re.findall(price_pattern, snippet)
29
+ return matches
30
+
31
+ @tool
32
+ def search_product_price(product_name:str)->str:
33
+ """
34
+ A tool that searches for product prices
35
+ Args:
36
+ product_name: product name that we want to search prices for
37
+ """
38
+
39
+ query = f"{product_name} price"
40
+ results = search_tool.search(query)
41
+
42
+ # Extract and print the prices from the search snippets
43
+ found_prices = []
44
+ for result in results:
45
+ snippet = result.get('snippet', '')
46
+ prices = extract_price_from_snippet(snippet)
47
+ if prices:
48
+ found_prices.extend(prices)
49
+
50
+ return "The found prices are:"+ str(found_prices)
51
+
52
 
53
  @tool
54
  def get_current_time_in_timezone(timezone: str) -> str: