Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions holmes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, List, Optional, Union

import requests # type: ignore
Comment thread
Avi-Robusta marked this conversation as resolved.
Resolved
import yaml # type: ignore
from pydantic import BaseModel, ConfigDict, FilePath, SecretStr

Expand All @@ -24,7 +25,6 @@
# Source plugin imports moved to their respective create methods to speed up startup
if TYPE_CHECKING:
from holmes.core.llm import LLM
from holmes.core.supabase_dal import SupabaseDal
from holmes.core.tool_calling_llm import IssueInvestigator, ToolCallingLLM
from holmes.plugins.destinations.slack import SlackDestination
from holmes.plugins.sources.github import GitHubSource
Expand All @@ -33,6 +33,7 @@
from holmes.plugins.sources.pagerduty import PagerDutySource
from holmes.plugins.sources.prometheus.plugin import AlertManagerSource

from holmes.core.supabase_dal import SupabaseDal
from holmes.core.config import config_path_dir
from holmes.utils.definitions import RobustaConfig
from holmes.utils.env import replace_env_vars_values
Expand Down Expand Up @@ -136,11 +137,47 @@ def toolset_manager(self) -> ToolsetManager:

def model_post_init(self, __context: Any) -> None:
self._model_list = parse_models_file(MODEL_LIST_FILE_LOCATION)
if self._should_load_robusta_ai():
logging.info("Loading Robusta AI model")
self._model_list[ROBUSTA_AI_MODEL_NAME] = {
"base_url": ROBUSTA_API_ENDPOINT,
}

if not self._should_load_robusta_ai():
return

self._load_robusta_ai_models()

def _load_robusta_ai_models(self) -> None:
try:
if not self.cluster_name:
self._load_default_robusta_config()
return

Comment thread
Avi-Robusta marked this conversation as resolved.
Resolved
dal = SupabaseDal(self.cluster_name)
account_id, token = dal.get_ai_credentials()
session_request = {"session_token": token, "account_id": account_id}

resp = requests.post(
f"{ROBUSTA_API_ENDPOINT}/api/llm/models",
json=session_request,
timeout=10,
)
resp.raise_for_status()
response_json = resp.json()

models = response_json.get("models", [ROBUSTA_AI_MODEL_NAME])
for model in models:
logging.info(f"Loading Robusta AI model: {model}")
Comment thread
Avi-Robusta marked this conversation as resolved.
Resolved
self._model_list[model] = {
"base_url": f"{ROBUSTA_API_ENDPOINT}/deployments/{model}",
}

Comment thread
Avi-Robusta marked this conversation as resolved.
Resolved
except Exception:
logging.exception("Failed to get all robusta models")
# fallback to default behavior
self._load_default_robusta_config()

def _load_default_robusta_config(self):
logging.info("Loading default Robusta AI model")
self._model_list[ROBUSTA_AI_MODEL_NAME] = {
"base_url": ROBUSTA_API_ENDPOINT,
}
Comment thread
Avi-Robusta marked this conversation as resolved.
Resolved

def configure_robusta_ai_model(self) -> None:
if self._should_load_robusta_ai() and self.api_key:
Expand Down
4 changes: 2 additions & 2 deletions holmes/utils/robusta.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from holmes.config import Config, ROBUSTA_AI_MODEL_NAME
from holmes.config import Config, ROBUSTA_AI
from holmes.core.supabase_dal import SupabaseDal
from pydantic import SecretStr


def load_robusta_api_key(dal: SupabaseDal, config: Config):
if ROBUSTA_AI_MODEL_NAME in config._model_list:
if ROBUSTA_AI:
account_id, token = dal.get_ai_credentials()
config.api_key = SecretStr(f"{account_id} {token}")
config.configure_robusta_ai_model()
Comment thread
Avi-Robusta marked this conversation as resolved.
Resolved