Files
lollms_hub/app/tools/stackoverflow_search.py
Saifeddine ALOUI 2a5e6b4cd6 feat(api/core): Implement admin settings and enhance proxy vectorization caching
This commit updates several core components related to administration, proxy handling, bot management, and application startup sequence.

**Changes include:**
*   **`app/api/v1/routes/admin.py`**: Added handling for Redis password updates in the admin settings endpoint.
*   **`app/api/v1/routes/proxy.py`**: Updated the shared vectorizer function to cache model description embeddings for performance.
*   **`app/core/bot_manager.py`**: Refined the logic for generating unique request IDs for bots.
*   **`app/main.py`**: Adjusted the application lifespan hook to ensure necessary directories are created during startup.
2026-04-19 19:17:25 +02:00

58 lines
1.9 KiB
Python

TOOL_LIBRARY_NAME = 'StackOverflow Search'
TOOL_LIBRARY_DESC = 'Search StackOverflow for programming answers and solutions.'
TOOL_LIBRARY_ICON = '🥞'
TOOL_TITLES = {
"tool_search_stackoverflow": "🥞 StackOverflow Search"
}
def init_tool_library() -> None:
import pipmaster as pm
pm.ensure_packages({'requests': '>=2.0.0'})
def tool_search_stackoverflow(args: dict, lollms=None):
'''
Search StackOverflow for answers to programming questions.
Args:
args: dict with keys:
- query (str): The programming question or error message to search for.
- max_results (int, optional): The maximum number of results to return (default: 3).
'''
import requests
try:
query = args.get('query')
limit = args.get('max_results', 3)
if not query:
return "Error: No search query provided."
url = "https://api.stackexchange.com/2.3/search/advanced"
params = {
"order": "desc",
"sort": "relevance",
"q": query,
"site": "stackoverflow",
"filter": "withbody", # Include question body to give the AI context
"pagesize": limit
}
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
data = response.json()
items = data.get("items",[])
if not items:
return "No results found on StackOverflow for this query."
results =[]
for item in items:
title = item.get("title", "")
link = item.get("link", "")
body = item.get("body_markdown", item.get("body", ""))[:500] # Truncate body
results.append(f"Q: {title}\nURL: {link}\nPreview: {body}...")
return "\n\n---\n\n".join(results)
except Exception as e:
return f"Execution Error: {str(e)}"