Skip to content

Commit

Permalink
Ajustes en views.py para integrar correctamente FAISS y OpenAI
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaister9 committed Oct 3, 2024
1 parent e890dd2 commit 5249509
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions backend/chatbot_laura/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
import numpy as np
import faiss
import pickle
import openai # Importa OpenAI aquí
from openai import OpenAI
from dotenv import load_dotenv

# Configurar logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

load_dotenv()
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY')) # Configura tu clave de API

# Configura la API Key de OpenAI
openai.api_key = os.getenv('OPENAI_API_KEY')

class ChatbotLauraView:
def __init__(self):
Expand All @@ -37,7 +36,7 @@ def __init__(self):
def get_embedding(self, text, model="text-embedding-ada-002"):
try:
# Usamos directamente la función de OpenAI para obtener embeddings
response = openai.Embedding.create(input=text, model=model)
response = client.embeddings.create(input=text, model=model)
return response['data'][0]['embedding']
except Exception as e:
logger.error(f"Error al obtener embedding: {str(e)}")
Expand Down

0 comments on commit 5249509

Please sign in to comment.