c47b9474f4
- Added `text_manager.py` to handle the creation of text libraries via FastAPI. - Introduced database connection management in `conexion.py` using PostgreSQL credentials from environment variables. - Created abstract base class `EmbedderABC` in `Base_Embedder.py` for embedding models. - Developed `OpenAIEmbedder` class to generate embeddings using OpenAI's API. - Implemented `OpenAIEmbedderModel` and repository pattern for managing OpenAI embedders in `Openai_embedder_mmr.py`. - Established `Biblioteca` class for managing text libraries and their associated notes in `biblioteca.py`. - Created SQLAlchemy models and mappers for `Biblioteca` and `Nota` in `biblioteca_mmr.py` and `notas_biblioteca_mmr.py`. - Added functionality for dynamic table generation for notes associated with libraries. - Included comprehensive methods for adding, retrieving, and managing notes and libraries in their respective repositories.
24 lines
944 B
Python
24 lines
944 B
Python
from src.Security.GenerarIDs import GeneradorIDUnico
|
|
|
|
class OpenAICredencial:
|
|
def __init__(self, titulo: str, api_key: str, organizacion: str = None, id: str = None):
|
|
"""
|
|
:param titulo: Nombre descriptivo para esta credencial.
|
|
:param api_key: Clave secreta de la API de OpenAI.
|
|
:param organizacion: (Opcional) ID de la organización asociada a la cuenta de OpenAI.
|
|
"""
|
|
self.id = id if id is not None else GeneradorIDUnico("OPAK").generar()
|
|
self.titulo = titulo
|
|
self.api_key = api_key
|
|
self.organizacion = organizacion
|
|
|
|
def get_headers(self) -> dict:
|
|
"""
|
|
Retorna los encabezados necesarios para autenticar una petición HTTP a OpenAI.
|
|
"""
|
|
headers = {
|
|
"Authorization": f"Bearer {self.api_key}"
|
|
}
|
|
if self.organizacion:
|
|
headers["OpenAI-Organization"] = self.organizacion
|
|
return headers |