Spaces:
Sleeping
Sleeping
Daniel Amendoeira
commited on
Update tools.py
Browse files
tools.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from langchain.tools import
|
2 |
import datetime
|
3 |
import requests
|
4 |
import openai
|
@@ -7,13 +7,19 @@ import tempfile
|
|
7 |
from urllib.parse import urlparse
|
8 |
from openai import OpenAI
|
9 |
|
10 |
-
|
|
|
|
|
11 |
return datetime.datetime.now().strftime("%Y-%m-%d")
|
12 |
|
13 |
-
|
|
|
|
|
14 |
return datetime.datetime.now().strftime("%A")
|
15 |
|
16 |
-
|
|
|
|
|
17 |
try:
|
18 |
future_date = datetime.datetime.strptime(date_str, "%Y-%m-%d").date()
|
19 |
today = datetime.date.today()
|
@@ -23,24 +29,9 @@ def days_until(date_str):
|
|
23 |
except Exception as e:
|
24 |
return f"Error parsing date: {str(e)}"
|
25 |
|
26 |
-
datetime_tools = [
|
27 |
-
Tool(
|
28 |
-
name="current_date",
|
29 |
-
func=current_date,
|
30 |
-
description="Returns the current date in YYYY-MM-DD format."
|
31 |
-
),
|
32 |
-
Tool(
|
33 |
-
name="current_day_of_week",
|
34 |
-
func=day_of_week,
|
35 |
-
description="Returns the current day of the week (e.g., Monday, Tuesday)."
|
36 |
-
),
|
37 |
-
Tool(
|
38 |
-
name="days_until",
|
39 |
-
func=days_until,
|
40 |
-
description="Returns the number of days from today until a given date (input format: YYYY-MM-DD)."
|
41 |
-
)
|
42 |
-
]
|
43 |
|
|
|
44 |
def transcribe_audio(audio_input: str) -> str:
|
45 |
"""
|
46 |
Transcribes an audio file from a local file or a URL
|
@@ -78,10 +69,4 @@ def transcribe_audio(audio_input: str) -> str:
|
|
78 |
return transcription.text
|
79 |
|
80 |
except Exception as e:
|
81 |
-
return f"Transcription failed: {e}"
|
82 |
-
|
83 |
-
transcribe_audio_tool = Tool(
|
84 |
-
name="transcribe_audio",
|
85 |
-
func=transcribe_audio,
|
86 |
-
description="Transcribes an audio file from a local file or a URL"
|
87 |
-
)
|
|
|
1 |
+
from langchain.tools import tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import openai
|
|
|
7 |
from urllib.parse import urlparse
|
8 |
from openai import OpenAI
|
9 |
|
10 |
+
@tool
|
11 |
+
def current_date(_) -> str :
|
12 |
+
""" Returns the current date in YYYY-MM-DD format """
|
13 |
return datetime.datetime.now().strftime("%Y-%m-%d")
|
14 |
|
15 |
+
@tool
|
16 |
+
def day_of_week(_) -> str :
|
17 |
+
""" Returns the current day of the week (e.g., Monday, Tuesday) """
|
18 |
return datetime.datetime.now().strftime("%A")
|
19 |
|
20 |
+
@tool
|
21 |
+
def days_until(date_str: str) -> str :
|
22 |
+
""" Returns the number of days from today until a given date (input format: YYYY-MM-DD) """
|
23 |
try:
|
24 |
future_date = datetime.datetime.strptime(date_str, "%Y-%m-%d").date()
|
25 |
today = datetime.date.today()
|
|
|
29 |
except Exception as e:
|
30 |
return f"Error parsing date: {str(e)}"
|
31 |
|
32 |
+
datetime_tools = [current_date, day_of_week, days_until]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
@tool
|
35 |
def transcribe_audio(audio_input: str) -> str:
|
36 |
"""
|
37 |
Transcribes an audio file from a local file or a URL
|
|
|
69 |
return transcription.text
|
70 |
|
71 |
except Exception as e:
|
72 |
+
return f"Transcription failed: {e}"
|
|
|
|
|
|
|
|
|
|
|
|