Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,8 @@ class GeminiLLM(LLM):
|
|
| 25 |
model_name: str = "gemini-2.0-flash"
|
| 26 |
temperature: float = 0.1
|
| 27 |
|
| 28 |
-
|
|
|
|
| 29 |
@property
|
| 30 |
def _llm_type(self) -> str:
|
| 31 |
return "google-gemini-llm"
|
|
@@ -38,11 +39,11 @@ class GeminiLLM(LLM):
|
|
| 38 |
}
|
| 39 |
|
| 40 |
full_prompt = (
|
| 41 |
-
"You are
|
| 42 |
-
"
|
| 43 |
f"Question: {prompt}"
|
| 44 |
)
|
| 45 |
-
|
| 46 |
data = {
|
| 47 |
"contents": [
|
| 48 |
{
|
|
@@ -240,6 +241,66 @@ def square_root(a: float) -> float:
|
|
| 240 |
return a ** 0.5
|
| 241 |
return sqrt(a)
|
| 242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
# --- Basic Agent Definition ---
|
| 244 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 245 |
from langchain_core.prompts import PromptTemplate
|
|
|
|
| 25 |
model_name: str = "gemini-2.0-flash"
|
| 26 |
temperature: float = 0.1
|
| 27 |
|
| 28 |
+
|
| 29 |
+
|
| 30 |
@property
|
| 31 |
def _llm_type(self) -> str:
|
| 32 |
return "google-gemini-llm"
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
full_prompt = (
|
| 42 |
+
"You are a helpful agent that answers questions concisely and strictly follows instructions.\n"
|
| 43 |
+
"Respond ONLY with the requested information, no explanations or extra words. If the question specifies a format (number, name, comma separated list), follow it exactly.\n"
|
| 44 |
f"Question: {prompt}"
|
| 45 |
)
|
| 46 |
+
|
| 47 |
data = {
|
| 48 |
"contents": [
|
| 49 |
{
|
|
|
|
| 241 |
return a ** 0.5
|
| 242 |
return sqrt(a)
|
| 243 |
|
| 244 |
+
|
| 245 |
+
@tool
|
| 246 |
+
def extract_numbers(text: str) -> List[float]:
|
| 247 |
+
"""
|
| 248 |
+
Extract all numeric values from a given text.
|
| 249 |
+
Args:
|
| 250 |
+
text (str): Input text that may contain numbers.
|
| 251 |
+
Returns:
|
| 252 |
+
List[float]: A list of numbers found in the text.
|
| 253 |
+
"""
|
| 254 |
+
import re
|
| 255 |
+
return [float(num) for num in re.findall(r'\d+(?:\.\d+)?', text)]
|
| 256 |
+
|
| 257 |
+
@tool
|
| 258 |
+
def extract_keywords(text: str, top_n: int = 5) -> List[str]:
|
| 259 |
+
"""
|
| 260 |
+
Extracts the most frequent keywords from a text (ignores very common words).
|
| 261 |
+
Args:
|
| 262 |
+
text (str): The input text.
|
| 263 |
+
top_n (int): Number of keywords to return.
|
| 264 |
+
Returns:
|
| 265 |
+
List[str]: List of top keywords.
|
| 266 |
+
"""
|
| 267 |
+
import re
|
| 268 |
+
from collections import Counter
|
| 269 |
+
stop_words = {"the", "a", "an", "and", "of", "in", "on", "for", "is", "at", "to", "by"}
|
| 270 |
+
words = re.findall(r'\b[a-zA-Z]+\b', text.lower())
|
| 271 |
+
filtered = [w for w in words if w not in stop_words]
|
| 272 |
+
return [word for word, _ in Counter(filtered).most_common(top_n)]
|
| 273 |
+
@tool
|
| 274 |
+
def extract_names(text: str) -> List[str]:
|
| 275 |
+
"""
|
| 276 |
+
Extracts words that start with a capital letter (possible names or surnames).
|
| 277 |
+
Args:
|
| 278 |
+
text (str): The input text.
|
| 279 |
+
Returns:
|
| 280 |
+
List[str]: List of unique candidate names.
|
| 281 |
+
"""
|
| 282 |
+
import re
|
| 283 |
+
names = re.findall(r'\b[A-Z][a-z]+\b', text)
|
| 284 |
+
return list(dict.fromkeys(names))
|
| 285 |
+
|
| 286 |
+
@tool
|
| 287 |
+
def find_non_commutative_pairs(table: Dict[str, Dict[str, str]]) -> List[tuple]:
|
| 288 |
+
"""
|
| 289 |
+
Finds pairs (a,b) where the operation * is not commutative.
|
| 290 |
+
Args:
|
| 291 |
+
table (dict): A nested dictionary representing the operation table.
|
| 292 |
+
Returns:
|
| 293 |
+
List[tuple]: List of pairs where a*b != b*a.
|
| 294 |
+
"""
|
| 295 |
+
non_commutative = []
|
| 296 |
+
elements = table.keys()
|
| 297 |
+
for a in elements:
|
| 298 |
+
for b in elements:
|
| 299 |
+
if table[a][b] != table[b][a]:
|
| 300 |
+
non_commutative.append((a, b))
|
| 301 |
+
return non_commutative
|
| 302 |
+
|
| 303 |
+
|
| 304 |
# --- Basic Agent Definition ---
|
| 305 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 306 |
from langchain_core.prompts import PromptTemplate
|