smarter: factual-model routing (beh-10), fetch_url main-content extraction + 8k cap (url-08), get_weather via met.no (spec-016)
This commit is contained in:
@@ -17,6 +17,7 @@ from .leonardo_draw import LeonardoAIDrawMixIn
|
||||
from .news import GET_NEWS_TOOL, query_news
|
||||
from .quota import QuotaLedger
|
||||
from .url_reader import FETCH_URL_TOOL, URLReader
|
||||
from .weather import GET_WEATHER_TOOL, Weather
|
||||
from .websearch import DEFAULT_RESULTS as WEB_DEFAULT_RESULTS
|
||||
from .websearch import WEB_SEARCH_TOOL, WebSearch
|
||||
|
||||
@@ -170,6 +171,7 @@ class OpenAIResponder(AIResponder, LeonardoAIDrawMixIn):
|
||||
self.codex = CodexSearch(lambda: self.config)
|
||||
# Web search (SPEC-015) via Exa; general "look it up" beyond fetch_url/news/codex
|
||||
self.web_search = WebSearch(lambda: self.config)
|
||||
self.weather = Weather(lambda: self.config)
|
||||
|
||||
def _available_tools(self) -> List[Dict[str, Any]]:
|
||||
"""Assemble the function-tool list from every enabled provider (URL-01)."""
|
||||
@@ -189,6 +191,8 @@ class OpenAIResponder(AIResponder, LeonardoAIDrawMixIn):
|
||||
functions.append(GET_NEWS_TOOL)
|
||||
if self.web_search.enabled(): # WEB-01
|
||||
functions.append(WEB_SEARCH_TOOL)
|
||||
if self.weather.enabled(): # WEA-01
|
||||
functions.append(GET_WEATHER_TOOL)
|
||||
return functions
|
||||
|
||||
async def _dispatch_tool(self, name: str, args: Dict[str, Any], author: str) -> Any:
|
||||
@@ -219,6 +223,12 @@ class OpenAIResponder(AIResponder, LeonardoAIDrawMixIn):
|
||||
return {"error": "daily web search limit reached"}
|
||||
self.ledger._add(f"web:{author}", 1)
|
||||
return await self.web_search.search(str(args.get("query", "")), int(args.get("num_results", WEB_DEFAULT_RESULTS)))
|
||||
if name == "get_weather":
|
||||
per_user_cap = int(self.config.get("weather-daily-per-user", 30))
|
||||
if self.ledger._get(f"weather:{author}") >= per_user_cap: # WEA-04
|
||||
return {"error": "daily weather lookup limit reached"}
|
||||
self.ledger._add(f"weather:{author}", 1)
|
||||
return await self.weather.forecast(args.get("location"))
|
||||
return await self._execute_igdb_function(name, args)
|
||||
|
||||
async def draw_openai(self, description: str, count: int = 1) -> List[BytesIO]:
|
||||
@@ -292,6 +302,8 @@ class OpenAIResponder(AIResponder, LeonardoAIDrawMixIn):
|
||||
model = self.config["model-vision"]
|
||||
else:
|
||||
messages[-1]["content"] = messages[-1]["content"][0]["text"]
|
||||
if getattr(self, "_factual", False) and "factual-model" in self.config:
|
||||
model = self.config["factual-model"] # BEH-10: facts get the stronger tier
|
||||
if self._use_retry_model and "retry-model" in self.config:
|
||||
model = self.config["retry-model"]
|
||||
except (KeyError, IndexError, TypeError) as e:
|
||||
|
||||
Reference in New Issue
Block a user