Skip to content

Commit

Permalink
fix: room typing state + albert-api base url format.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrckd committed Oct 2, 2024
1 parent c43bb74 commit bc73e2a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
18 changes: 10 additions & 8 deletions app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,17 @@ async def wrapper(ep: EventParser, matrix_client: MatrixClient):

config = user_configs[ep.sender]
is_allowed, msg = await tiam.is_user_allowed(config, ep.sender, refresh=True)
if is_allowed:
return await func(ep, matrix_client)
if not is_allowed:
if not msg or ep.is_command(COMMAND_PREFIX):
# Only send back the message for the generic albert_answer method
# ignoring other callbacks.
raise EventNotConcerned

if not msg or ep.is_command(COMMAND_PREFIX):
# Only send back the message for the generic albert_answer method
# ignoring other callbacks.
raise EventNotConcerned
await log_not_allowed(msg, ep, matrix_client)
return

await log_not_allowed(msg, ep, matrix_client)
await func(ep, matrix_client)
await matrix_client.room_typing(ep.room.room_id, typing_state=False)

return wrapper

Expand Down Expand Up @@ -404,7 +406,7 @@ async def albert_answer(ep: EventParser, matrix_client: MatrixClient):
)

config.update_last_activity()
await matrix_client.room_typing(ep.room.room_id, typing_state=True, timeout=180_000)
await matrix_client.room_typing(ep.room.room_id)
try:
# Build the messages history
# --
Expand Down
12 changes: 7 additions & 5 deletions app/core_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
#
# SPDX-License-Identifier: MIT

import os

import requests
from jinja2 import BaseLoader, Environment, Template, meta
from openai import OpenAI
from utils import log_and_raise_for_status

from config import Config
from utils import log_and_raise_for_status

API_PREFIX_V1 = "v1"


def get_available_models(config: Config) -> dict:
"""Fetch available models"""
api_key = config.albert_api_token
url = config.albert_api_url + API_PREFIX_V1
url = os.path.join(config.albert_api_url, API_PREFIX_V1)
headers = {"Authorization": f"Bearer {api_key}"}
response = requests.get(f"{url}/models", headers=headers)
log_and_raise_for_status(response)
Expand All @@ -31,7 +33,7 @@ def get_available_modes(config: Config) -> list[str]:

def generate(config: Config, messages: list, limit=7) -> str:
api_key = config.albert_api_token
url = config.albert_api_url + API_PREFIX_V1
url = os.path.join(config.albert_api_url, API_PREFIX_V1)
model = config.albert_model
mode = None if config.albert_mode == "norag" else config.albert_mode
rag_sources = []
Expand Down Expand Up @@ -76,7 +78,7 @@ def last_sources(self) -> list[dict]:
return self._last_sources

def fetch_collections(self) -> dict:
url = self.base_url + API_PREFIX_V1
url = self.base_url
headers = {"Authorization": f"Bearer {self.api_key}"}
response = requests.get(f"{url}/collections", headers=headers)
log_and_raise_for_status(response)
Expand Down Expand Up @@ -110,7 +112,7 @@ def semantic_search(
self, model: str, query: str, limit: int, collections: list[str]
) -> list[dict]:
"""Fetch available models"""
url = self.base_url + API_PREFIX_V1
url = self.base_url
headers = {"Authorization": f"Bearer {self.api_key}"}
params = {
"prompt": query,
Expand Down

0 comments on commit bc73e2a

Please sign in to comment.