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:
Stan Girard 2024-01-21 17:03:25 -08:00 committed by GitHub
parent cdf5398ff5
commit 25a53a254b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 7 deletions

View File

@ -2,9 +2,8 @@ from enum import Enum
from typing import List, Optional from typing import List, Optional
from uuid import UUID from uuid import UUID
from pydantic import BaseModel
from modules.brain.entity.api_brain_definition_entity import ApiBrainDefinitionEntity from modules.brain.entity.api_brain_definition_entity import ApiBrainDefinitionEntity
from pydantic import BaseModel
class BrainType(str, Enum): class BrainType(str, Enum):

View File

@ -4,8 +4,7 @@ from logger import get_logger
from models.settings import get_embeddings, get_supabase_client from models.settings import get_embeddings, get_supabase_client
from modules.brain.dto.inputs import BrainUpdatableProperties from modules.brain.dto.inputs import BrainUpdatableProperties
from modules.brain.entity.brain_entity import BrainEntity, PublicBrain from modules.brain.entity.brain_entity import BrainEntity, PublicBrain
from modules.brain.repository.interfaces.brains_interface import \ from modules.brain.repository.interfaces.brains_interface import BrainsInterface
BrainsInterface
logger = get_logger(__name__) logger = get_logger(__name__)

View File

@ -1,8 +1,7 @@
from uuid import UUID from uuid import UUID
from logger import get_logger 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.entity.brain_entity import BrainUser, MinimalUserBrainEntity
from modules.brain.repository.interfaces.brains_users_interface import ( from modules.brain.repository.interfaces.brains_users_interface import (
BrainsUsersInterface, BrainsUsersInterface,
@ -16,11 +15,28 @@ class BrainsUsers(BrainsUsersInterface):
supabase_client = get_supabase_client() supabase_client = get_supabase_client()
self.db = 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]: def get_user_brains(self, user_id) -> list[MinimalUserBrainEntity]:
response = ( response = (
self.db.from_("brains_users") self.db.from_("brains_users")
.select( .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) .filter("user_id", "eq", user_id)
.execute() .execute()
@ -40,6 +56,9 @@ class BrainsUsers(BrainsUsersInterface):
) )
) )
user_brains[-1].rights = item["rights"] user_brains[-1].rights = item["rights"]
if item["brains"]["meaning"] is None:
self.update_meaning(user_brains[-1])
return user_brains return user_brains
def get_brain_for_user(self, user_id, brain_id): def get_brain_for_user(self, user_id, brain_id):