Update app/logic/calc_b.py
Browse files- app/logic/calc_b.py +7 -3
app/logic/calc_b.py
CHANGED
|
@@ -21,10 +21,14 @@ df_base = pd.read_csv(csv_path)
|
|
| 21 |
def query_faiss_index(query_text,
|
| 22 |
faiss_index_path=None,
|
| 23 |
metadata_path=None,
|
| 24 |
-
openai_api_key="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",
|
| 25 |
top_k=5):
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
|
|
|
|
|
|
| 28 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 29 |
|
| 30 |
if faiss_index_path is None:
|
|
@@ -40,7 +44,7 @@ def query_faiss_index(query_text,
|
|
| 40 |
# Get embedding for query
|
| 41 |
response = client.embeddings.create(
|
| 42 |
input=query_text.lower(),
|
| 43 |
-
model="text-embedding-3-
|
| 44 |
)
|
| 45 |
query_embedding = response.data[0].embedding
|
| 46 |
query_embedding_np = np.array([query_embedding]).astype("float32")
|
|
|
|
| 21 |
def query_faiss_index(query_text,
|
| 22 |
faiss_index_path=None,
|
| 23 |
metadata_path=None,
|
|
|
|
| 24 |
top_k=5):
|
| 25 |
+
|
| 26 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 27 |
+
if not openai_api_key:
|
| 28 |
+
raise ValueError("OPENAI_API_KEY is not set")
|
| 29 |
|
| 30 |
+
client = OpenAI(api_key=openai_api_key)
|
| 31 |
+
|
| 32 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 33 |
|
| 34 |
if faiss_index_path is None:
|
|
|
|
| 44 |
# Get embedding for query
|
| 45 |
response = client.embeddings.create(
|
| 46 |
input=query_text.lower(),
|
| 47 |
+
model="text-embedding-3-small"
|
| 48 |
)
|
| 49 |
query_embedding = response.data[0].embedding
|
| 50 |
query_embedding_np = np.array([query_embedding]).astype("float32")
|