6de2455917
- Added GLOBAL_MARKETS_TITLE to all translation files - Updated footer with 12 markets (4 active + 8 upcoming) - Translated market section to: zh-cn, zh-tw, ja, ko, th, vi, id, ms, hi - Built and deployed to production - CloudFront invalidation: I3RTMXVFDJXWLG3SYX208OP1CC
77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Web Searcher för Landvex Produktionsagent
|
|
Använder web_search och web_fetch tools
|
|
"""
|
|
|
|
import json
|
|
from typing import List, Dict, Optional
|
|
|
|
|
|
def sok_och_hamta(amne: str, doman: str, max_resultat: int = 5) -> List[Dict]:
|
|
"""
|
|
Sök efter information om ett infrastrukturobjekt och hämta innehåll.
|
|
|
|
Args:
|
|
amne: Objektets namn
|
|
doman: Domänkod
|
|
max_resultat: Max antal resultat att hämta
|
|
|
|
Returns:
|
|
Lista med resultat-dicts
|
|
"""
|
|
resultat = []
|
|
|
|
# Bygg sökfråga
|
|
sok_fraga = f"{amne} infrastructure technical specifications standards"
|
|
if doman == "VAT":
|
|
sok_fraga = f"{amne} water infrastructure valve technical"
|
|
elif doman == "TRP":
|
|
sok_fraga = f"{amne} road traffic infrastructure"
|
|
elif doman == "ELN":
|
|
sok_fraga = f"{amne} electrical power grid infrastructure"
|
|
|
|
try:
|
|
# Använd web_search tool
|
|
from tools import web_search
|
|
sok_resultat = web_search(query=sok_fraga, count=max_resultat)
|
|
|
|
if sok_resultat:
|
|
for item in sok_resultat:
|
|
resultat.append({
|
|
"titel": item.get("title", ""),
|
|
"url": item.get("url", ""),
|
|
"snippet": item.get("snippet", ""),
|
|
"content": item.get("content", item.get("snippet", ""))
|
|
})
|
|
except ImportError:
|
|
print("Varning: web_search inte tillgänglig")
|
|
except Exception as e:
|
|
print(f"Sökfel: {e}")
|
|
|
|
return resultat
|
|
|
|
|
|
def hamta_sida_content(url: str) -> Optional[str]:
|
|
"""Hämta fullständigt innehåll från en URL."""
|
|
try:
|
|
from tools import web_fetch
|
|
result = web_fetch(url=url)
|
|
if result:
|
|
# Begränsa till 2000 tecken
|
|
return result[:2000]
|
|
except ImportError:
|
|
pass
|
|
except Exception as e:
|
|
print(f"Hämtningsfel för {url}: {e}")
|
|
|
|
return None
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Test
|
|
resultat = sok_och_hamta("Avstängningsventil", "VAT")
|
|
print(f"Hittade {len(resultat)} resultat")
|
|
for r in resultat:
|
|
print(f"- {r['titel']}: {r['url']}")
|