Commit
·
ba12808
1
Parent(s):
31a5120
new fix for tools
Browse files
app.py
CHANGED
@@ -55,8 +55,14 @@ def download_file(file_name: str) -> None:
|
|
55 |
@tool
|
56 |
def open_file_as_text(file_name: str, filetype: Optional[str] = "txt") -> str:
|
57 |
"""
|
58 |
-
Opens and reads a file
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
"""
|
61 |
download_file(file_name)
|
62 |
try:
|
@@ -88,16 +94,17 @@ def open_file_as_text(file_name: str, filetype: Optional[str] = "txt") -> str:
|
|
88 |
except Exception as e:
|
89 |
return f"Error opening file '{file_name}': {str(e)}"
|
90 |
|
|
|
91 |
@tool
|
92 |
def web_search(query: str) -> str:
|
93 |
"""
|
94 |
Performs a web search using DuckDuckGo and returns the top results.
|
95 |
|
96 |
Args:
|
97 |
-
query: Search query string.
|
98 |
|
99 |
Returns:
|
100 |
-
Top search results formatted as title, snippet, and URL.
|
101 |
"""
|
102 |
try:
|
103 |
with DDGS() as ddgs:
|
@@ -108,16 +115,17 @@ def web_search(query: str) -> str:
|
|
108 |
except Exception as e:
|
109 |
return f"Error during search: {str(e)}"
|
110 |
|
|
|
111 |
@tool
|
112 |
def read_wikipedia_page(url: str) -> str:
|
113 |
"""
|
114 |
Reads and extracts clean text content from a Wikipedia page.
|
115 |
|
116 |
Args:
|
117 |
-
url: Full URL to the Wikipedia page.
|
118 |
|
119 |
Returns:
|
120 |
-
Sectioned and readable content from the page, including paragraphs, lists, and tables.
|
121 |
"""
|
122 |
headers = {"User-Agent": "Mozilla/5.0"}
|
123 |
resp = requests.get(url, headers=headers, timeout=10)
|
@@ -134,17 +142,18 @@ def read_wikipedia_page(url: str) -> str:
|
|
134 |
parts.append(parse_wikipedia_table(elem))
|
135 |
return "\n".join(parts)
|
136 |
|
|
|
137 |
@tool
|
138 |
def smart_paginate_around_query(full_text: str, query: str) -> list:
|
139 |
"""
|
140 |
Splits full text into focused windows surrounding the query keyword.
|
141 |
|
142 |
Args:
|
143 |
-
full_text: The large text content to paginate.
|
144 |
-
query: Keyword or phrase to center each window on.
|
145 |
|
146 |
Returns:
|
147 |
-
List of substrings centered around the query within the original text.
|
148 |
"""
|
149 |
before_chars = 1000
|
150 |
after_chars = 3000
|
@@ -162,29 +171,31 @@ def smart_paginate_around_query(full_text: str, query: str) -> list:
|
|
162 |
start = e
|
163 |
return pages
|
164 |
|
|
|
165 |
@tool
|
166 |
def reverse_sentence(text: str) -> str:
|
167 |
"""
|
168 |
Reverses the input text string.
|
169 |
|
170 |
Args:
|
171 |
-
text: A string to reverse.
|
172 |
|
173 |
Returns:
|
174 |
-
Reversed string.
|
175 |
"""
|
176 |
return text[::-1]
|
177 |
|
|
|
178 |
@tool
|
179 |
def run_python_code(file_name: str) -> str:
|
180 |
"""
|
181 |
Executes a Python script and returns the output.
|
182 |
|
183 |
Args:
|
184 |
-
file_name: Name of the Python file to execute.
|
185 |
|
186 |
Returns:
|
187 |
-
Printed standard output or error message from the script.
|
188 |
"""
|
189 |
download_file(file_name)
|
190 |
try:
|
|
|
55 |
@tool
|
56 |
def open_file_as_text(file_name: str, filetype: Optional[str] = "txt") -> str:
|
57 |
"""
|
58 |
+
Opens and reads a file based on its type.
|
59 |
+
|
60 |
+
Args:
|
61 |
+
file_name (str): The name of the file to open (should be available after download).
|
62 |
+
filetype (Optional[str]): The type of file - one of 'txt', 'json', 'csv', 'xlsx', or 'mp3'. Defaults to 'txt'.
|
63 |
+
|
64 |
+
Returns:
|
65 |
+
str: File content as text, or transcription if an audio file.
|
66 |
"""
|
67 |
download_file(file_name)
|
68 |
try:
|
|
|
94 |
except Exception as e:
|
95 |
return f"Error opening file '{file_name}': {str(e)}"
|
96 |
|
97 |
+
|
98 |
@tool
|
99 |
def web_search(query: str) -> str:
|
100 |
"""
|
101 |
Performs a web search using DuckDuckGo and returns the top results.
|
102 |
|
103 |
Args:
|
104 |
+
query (str): Search query string.
|
105 |
|
106 |
Returns:
|
107 |
+
str: Top search results formatted as title, snippet, and URL.
|
108 |
"""
|
109 |
try:
|
110 |
with DDGS() as ddgs:
|
|
|
115 |
except Exception as e:
|
116 |
return f"Error during search: {str(e)}"
|
117 |
|
118 |
+
|
119 |
@tool
|
120 |
def read_wikipedia_page(url: str) -> str:
|
121 |
"""
|
122 |
Reads and extracts clean text content from a Wikipedia page.
|
123 |
|
124 |
Args:
|
125 |
+
url (str): Full URL to the Wikipedia page.
|
126 |
|
127 |
Returns:
|
128 |
+
str: Sectioned and readable content from the page, including paragraphs, lists, and tables.
|
129 |
"""
|
130 |
headers = {"User-Agent": "Mozilla/5.0"}
|
131 |
resp = requests.get(url, headers=headers, timeout=10)
|
|
|
142 |
parts.append(parse_wikipedia_table(elem))
|
143 |
return "\n".join(parts)
|
144 |
|
145 |
+
|
146 |
@tool
|
147 |
def smart_paginate_around_query(full_text: str, query: str) -> list:
|
148 |
"""
|
149 |
Splits full text into focused windows surrounding the query keyword.
|
150 |
|
151 |
Args:
|
152 |
+
full_text (str): The large text content to paginate.
|
153 |
+
query (str): Keyword or phrase to center each window on.
|
154 |
|
155 |
Returns:
|
156 |
+
list: List of substrings centered around the query within the original text.
|
157 |
"""
|
158 |
before_chars = 1000
|
159 |
after_chars = 3000
|
|
|
171 |
start = e
|
172 |
return pages
|
173 |
|
174 |
+
|
175 |
@tool
|
176 |
def reverse_sentence(text: str) -> str:
|
177 |
"""
|
178 |
Reverses the input text string.
|
179 |
|
180 |
Args:
|
181 |
+
text (str): A string to reverse.
|
182 |
|
183 |
Returns:
|
184 |
+
str: Reversed string.
|
185 |
"""
|
186 |
return text[::-1]
|
187 |
|
188 |
+
|
189 |
@tool
|
190 |
def run_python_code(file_name: str) -> str:
|
191 |
"""
|
192 |
Executes a Python script and returns the output.
|
193 |
|
194 |
Args:
|
195 |
+
file_name (str): Name of the Python file to execute.
|
196 |
|
197 |
Returns:
|
198 |
+
str: Printed standard output or error message from the script.
|
199 |
"""
|
200 |
download_file(file_name)
|
201 |
try:
|