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 22ee822 commit e890dd2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions backend/chatbot_laura/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import numpy as np
import faiss
import pickle
import openai # Importa OpenAI aquí
from dotenv import load_dotenv

# Configurar logging
Expand All @@ -19,6 +20,9 @@

load_dotenv()

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

class ChatbotLauraView:
def __init__(self):
base_dir = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -32,8 +36,9 @@ def __init__(self):

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

0 comments on commit e890dd2

Please sign in to comment.