mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-14 17:03:29 +03:00
feat: 🎸 brains (#2048)
update vectors at launch if missign # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
This commit is contained in:
parent
cdf5398ff5
commit
25a53a254b
@ -2,9 +2,8 @@ from enum import Enum
|
||||
from typing import List, Optional
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from modules.brain.entity.api_brain_definition_entity import ApiBrainDefinitionEntity
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class BrainType(str, Enum):
|
||||
|
@ -4,8 +4,7 @@ from logger import get_logger
|
||||
from models.settings import get_embeddings, get_supabase_client
|
||||
from modules.brain.dto.inputs import BrainUpdatableProperties
|
||||
from modules.brain.entity.brain_entity import BrainEntity, PublicBrain
|
||||
from modules.brain.repository.interfaces.brains_interface import \
|
||||
BrainsInterface
|
||||
from modules.brain.repository.interfaces.brains_interface import BrainsInterface
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
from uuid import UUID
|
||||
|
||||
from logger import get_logger
|
||||
from models.settings import get_supabase_client
|
||||
|
||||
from models.settings import get_embeddings, get_supabase_client
|
||||
from modules.brain.entity.brain_entity import BrainUser, MinimalUserBrainEntity
|
||||
from modules.brain.repository.interfaces.brains_users_interface import (
|
||||
BrainsUsersInterface,
|
||||
@ -16,11 +15,28 @@ class BrainsUsers(BrainsUsersInterface):
|
||||
supabase_client = get_supabase_client()
|
||||
self.db = supabase_client
|
||||
|
||||
def update_meaning(self, brain: MinimalUserBrainEntity):
|
||||
embeddings = get_embeddings()
|
||||
string_to_embed = f"Name: {brain.name} Description: {brain.description}"
|
||||
brain_meaning = embeddings.embed_query(string_to_embed)
|
||||
brain_dict = {"meaning": brain_meaning}
|
||||
response = (
|
||||
self.db.table("brains")
|
||||
.update(brain_dict)
|
||||
.match({"brain_id": brain.id})
|
||||
.execute()
|
||||
).data
|
||||
|
||||
if len(response) == 0:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def get_user_brains(self, user_id) -> list[MinimalUserBrainEntity]:
|
||||
response = (
|
||||
self.db.from_("brains_users")
|
||||
.select(
|
||||
"id:brain_id, rights, brains (brain_id, name, status, brain_type, description)"
|
||||
"id:brain_id, rights, brains (brain_id, name, status, brain_type, description, meaning)"
|
||||
)
|
||||
.filter("user_id", "eq", user_id)
|
||||
.execute()
|
||||
@ -40,6 +56,9 @@ class BrainsUsers(BrainsUsersInterface):
|
||||
)
|
||||
)
|
||||
user_brains[-1].rights = item["rights"]
|
||||
if item["brains"]["meaning"] is None:
|
||||
self.update_meaning(user_brains[-1])
|
||||
|
||||
return user_brains
|
||||
|
||||
def get_brain_for_user(self, user_id, brain_id):
|
||||
|
Loading…
Reference in New Issue
Block a user