feat: Implement main application shell with navigation and color scheme toggle
- Added Appshell component with responsive navbar and main content area - Integrated ColorSchemeToggle for light/dark mode switching - Created Welcome component with styled title and introductory text - Developed ChatPage for LLM interaction with WebSocket support - Implemented Biblioteca for managing notes with rich text editor - Added LoginPage for user authentication with error handling - Introduced MessageList and MessageBubble components for chat messages - Styled components with CSS modules for consistent design
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List
|
||||
|
||||
class EmbedderABC(ABC):
|
||||
@abstractmethod
|
||||
def encoder(self, text: str) -> List[float]:
|
||||
"""Genera los embeddings para un texto dado."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def dimension_number(self) -> int:
|
||||
"""Devuelve la dimensión del modelo de embedding."""
|
||||
pass
|
||||
@@ -0,0 +1,32 @@
|
||||
from typing import List
|
||||
from domains.Llms.Embedders.Base_Embedder import EmbedderABC # Asegúrate de que EmbedderABC esté en este módulo
|
||||
from domains.ApiKeys.openai_apikey import OpenAICredencial
|
||||
from domains.ConexionApis.OpenAi_conexion import OpenAICliente
|
||||
from domains.Security.GenerarIDs import GeneradorIDUnico
|
||||
|
||||
class OpenAIEmbedder(EmbedderABC):
|
||||
def __init__(self, credencial: OpenAICredencial,
|
||||
model: str,
|
||||
id: str = None):
|
||||
self.model = model
|
||||
self.client = OpenAICliente(credencial)
|
||||
self._dimension = None # Lazy loading
|
||||
self.id = id if id is not None else GeneradorIDUnico("OAMB").generar()
|
||||
|
||||
def encoder(self, text: str) -> List[float]:
|
||||
"""
|
||||
Genera los embeddings para un texto dado utilizando el modelo de OpenAI.
|
||||
"""
|
||||
response = self.client.embedding(model=self.model, input=text)
|
||||
embedding = response.data[0].embedding
|
||||
if self._dimension is None:
|
||||
self._dimension = len(embedding)
|
||||
return embedding
|
||||
|
||||
def dimension_number(self) -> int:
|
||||
"""
|
||||
Devuelve la dimensión del modelo de embedding, generando un embedding si no se ha calculado aún.
|
||||
"""
|
||||
if self._dimension is None:
|
||||
_ = self.encoder("dimension_check")
|
||||
return self._dimension
|
||||
@@ -0,0 +1,96 @@
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from sqlalchemy import Column, String
|
||||
from sqlalchemy import Column, String, ForeignKey
|
||||
|
||||
from domains.ArquitectureLayer.Mapper import Mapper_base
|
||||
from domains.ArquitectureLayer.Model import Model_base
|
||||
from domains.ArquitectureLayer.Repo import Repo_base
|
||||
|
||||
from domains.ConexionSql.Base_conexion import ConexionBase
|
||||
from domains.base import Base
|
||||
from domains.Security.GenerarIDs import GeneradorIDUnico
|
||||
from domains.Llms.Embedders.Openai_embedder import OpenAIEmbedder
|
||||
from domains.ApiKeys.openai_apikey import OpenAICredencial
|
||||
|
||||
# ----------------------
|
||||
# Cargar configuración desde .env si se requiere
|
||||
# ----------------------
|
||||
from entrypoint import ENV_PATH
|
||||
load_dotenv(ENV_PATH)
|
||||
|
||||
# ----------------------
|
||||
# MODELO (SQLAlchemy)
|
||||
# ----------------------
|
||||
|
||||
class OpenAIEmbedderModel(Base, Model_base):
|
||||
__tablename__ = "openai_embedders"
|
||||
|
||||
id = Column(String, primary_key=True)
|
||||
|
||||
api_key_id = Column(String, ForeignKey("openai_credenciales.id"), nullable=False)
|
||||
model = Column(String, nullable=False)
|
||||
|
||||
# ----------------------
|
||||
# MAPPER
|
||||
# ----------------------
|
||||
|
||||
class OpenAIEmbedderMapper(Mapper_base[OpenAIEmbedder, OpenAIEmbedderModel]):
|
||||
|
||||
@staticmethod
|
||||
def to_model(obj: OpenAIEmbedder) -> OpenAIEmbedderModel:
|
||||
return OpenAIEmbedderModel(
|
||||
id=obj.id,
|
||||
api_key_id=obj.client.credencial.id,
|
||||
model=obj.model
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def from_model(model: OpenAIEmbedderModel, credencial: OpenAICredencial) -> OpenAIEmbedder:
|
||||
return OpenAIEmbedder(
|
||||
id=model.id,
|
||||
credencial=credencial,
|
||||
model=model.model
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def to_dict(obj: OpenAIEmbedder) -> dict:
|
||||
return {
|
||||
"id": obj.id,
|
||||
"api_key_id": obj.client.credencial.id,
|
||||
"model": obj.model
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def from_dict(data: dict, credencial: OpenAICredencial) -> OpenAIEmbedder:
|
||||
return OpenAIEmbedder(
|
||||
id=data["id"],
|
||||
credencial=credencial,
|
||||
model=data["model"]
|
||||
)
|
||||
|
||||
# ----------------------
|
||||
# REPO
|
||||
# ----------------------
|
||||
|
||||
class OpenAIEmbedderRepo(Repo_base[OpenAIEmbedderModel, OpenAIEmbedder]):
|
||||
def __init__(self, conexion: ConexionBase):
|
||||
super().__init__(
|
||||
session=conexion.get_session(),
|
||||
modelo=OpenAIEmbedderModel,
|
||||
mapper=OpenAIEmbedderMapper
|
||||
)
|
||||
|
||||
def get_by_id(self, id_: str, credencial: OpenAICredencial) -> OpenAIEmbedder | None:
|
||||
model = self.session.get(self.Modelo, id_)
|
||||
return self.Mapper.from_model(model, credencial) if model else None
|
||||
|
||||
def get_all(self, credencial_loader: callable) -> list[OpenAIEmbedder]:
|
||||
"""
|
||||
:param credencial_loader: función que recibe un api_key_id y devuelve una instancia de OpenAICredencial
|
||||
"""
|
||||
models = self.session.query(self.Modelo).all()
|
||||
return [
|
||||
self.Mapper.from_model(m, credencial_loader(m.api_key_id))
|
||||
for m in models
|
||||
]
|
||||
Reference in New Issue
Block a user