sahanes commited on
Commit
020c612
·
verified ·
1 Parent(s): ed76bd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -19,7 +19,11 @@ from langchain_community.vectorstores.faiss import FAISS
19
  #from langchain.vectorstores import FAISS
20
 
21
 
22
- export OPENAI_API_KEY='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'
 
 
 
 
23
 
24
  # db = faiss.read_index('index.pkl')
25
  #db = pickle.load('index.pkl')
@@ -28,8 +32,19 @@ export OPENAI_API_KEY='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'
28
  # db.save_local("faiss_index")
29
 
30
  # embeddings = OpenAIEmbeddings()
31
- OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY)
 
 
 
 
 
 
 
 
 
 
32
 
 
33
  db=FAISS.load_local("faiss_index", embeddings,allow_dangerous_deserialization=True)
34
  #-----------------------------------------------------------------------------
35
  def get_response_from_query(db, query, k=3):
 
19
  #from langchain.vectorstores import FAISS
20
 
21
 
22
+ #export OPENAI_API_KEY='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'
23
+ import os
24
+
25
+ # Set the OPENAI_API_KEY environment variable directly
26
+ os.environ["OPENAI_API_KEY"] = "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"
27
 
28
  # db = faiss.read_index('index.pkl')
29
  #db = pickle.load('index.pkl')
 
32
  # db.save_local("faiss_index")
33
 
34
  # embeddings = OpenAIEmbeddings()
35
+ # OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY)
36
+
37
+ from pydantic.error_wrappers import ValidationError
38
+ from openai import OpenAIEmbeddings
39
+
40
+ openai_api_key = os.getenv("OPENAI_API_KEY")
41
+
42
+ try:
43
+ embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
44
+ except ValidationError as e:
45
+ print(f"Error: {e}")
46
 
47
+ #------------------------------------------------------------------------------
48
  db=FAISS.load_local("faiss_index", embeddings,allow_dangerous_deserialization=True)
49
  #-----------------------------------------------------------------------------
50
  def get_response_from_query(db, query, k=3):