Skip to content

Commit

Permalink
token handling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Szefler committed Jun 12, 2024
1 parent d49d265 commit d1f169d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions holmes/core/robusta_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def __init__(self, base_url: str, session_manager: SessionManager, runbook_manag

def call(self, system_prompt: str, user_prompt: str) -> LLMResult:
auth_token = self.session_manager.get_current_token()
if auth_token is None:
auth_token = self.session_manager.create_token()

payload = {
"auth": {"account_id": auth_token.account_id, "token": auth_token.token},
"system_message": system_prompt,
Expand Down
11 changes: 7 additions & 4 deletions holmes/core/supabase_dal.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,28 @@ def create_auth_token(self, token_type: str) -> AuthToken:
{
"account_id": self.account_id,
"user_id": self.user_id,
"token": uuid4(),
"token": str(uuid4()),
"type": token_type,
}
)
.execute()
)
return AuthToken(**result.data[0])

def get_freshest_auth_token(self, token_type: str) -> AuthToken:
def get_freshest_auth_token(self, token_type: str) -> Optional[AuthToken]:
result = (
self.client.table(TOKENS_TABLE)
.select("*")
.filter("token_type", "eq", token_type)
.filter("type", "eq", token_type)
.filter("deleted", "eq", False)
.order("created_at", desc=True)
.limit(1)
.execute()
)
return AuthToken(**result.data[0])
if not result.data:
return None
else:
return AuthToken(**result.data[0])

def invalidate_auth_token(self, token: AuthToken) -> None:
(
Expand Down
6 changes: 1 addition & 5 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
from fastapi import FastAPI
from rich.console import Console

from holmes.common.env_vars import (
ALLOWED_TOOLSETS,
HOLMES_HOST,
HOLMES_PORT,
)
from holmes.common.env_vars import ALLOWED_TOOLSETS, HOLMES_HOST, HOLMES_PORT
from holmes.config import BaseLLMConfig, LLMProviderType
from holmes.core.issue import Issue
from holmes.core.provider import LLMProviderFactory
Expand Down

0 comments on commit d1f169d

Please sign in to comment.