This repository has been archived on 2025-11-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Fitz_Studio/domains/Llms/Embedders/Openai_embedder.py
T
egutierrez aef8791151 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
2025-06-21 02:01:21 +02:00

32 lines
1.3 KiB
Python

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