Spaces:
Sleeping
Sleeping
Update functions.py
Browse files- functions.py +13 -3
functions.py
CHANGED
|
@@ -9,7 +9,16 @@ import pandas as pd
|
|
| 9 |
import json
|
| 10 |
|
| 11 |
current_dir = os.getcwd()
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def load_dictionary(json_path):
|
| 15 |
with open(json_path, 'r', encoding='utf-8') as file:
|
|
@@ -55,7 +64,7 @@ def load_embeddings(file_path="embeddings/embeddings.xlsx"):
|
|
| 55 |
"model_name": model_name,
|
| 56 |
}
|
| 57 |
|
| 58 |
-
def generate_answer_with_references(query, data):
|
| 59 |
embeddings = data["embeddings"]
|
| 60 |
segment_contents = data["segment_contents"]
|
| 61 |
model_name = data["model_name"]
|
|
@@ -93,7 +102,8 @@ def generate_answer_with_references(query, data):
|
|
| 93 |
return resposta, total_tokens, prompt_tokens, top_segments, top_file_names, top_similarities, prompt_template
|
| 94 |
|
| 95 |
def rag_response(query, data, detailed_response):
|
| 96 |
-
|
|
|
|
| 97 |
file_names = [x[0] for x in top_file_names]
|
| 98 |
file_links = {x[0]: x[1] for x in top_file_names}
|
| 99 |
|
|
|
|
| 9 |
import json
|
| 10 |
|
| 11 |
current_dir = os.getcwd()
|
| 12 |
+
api_key_file = "api_key.json"
|
| 13 |
+
|
| 14 |
+
def load_api_key():
|
| 15 |
+
if not 'OPENAI_API_KEY' in os.environ:
|
| 16 |
+
with open(api_key_file, 'r') as file:
|
| 17 |
+
api_key = json.load(file)['api_key']
|
| 18 |
+
else:
|
| 19 |
+
api_key = os.getenv['OPENAI_API_KEY']
|
| 20 |
+
|
| 21 |
+
return api_key
|
| 22 |
|
| 23 |
def load_dictionary(json_path):
|
| 24 |
with open(json_path, 'r', encoding='utf-8') as file:
|
|
|
|
| 64 |
"model_name": model_name,
|
| 65 |
}
|
| 66 |
|
| 67 |
+
def generate_answer_with_references(query, data, api_key):
|
| 68 |
embeddings = data["embeddings"]
|
| 69 |
segment_contents = data["segment_contents"]
|
| 70 |
model_name = data["model_name"]
|
|
|
|
| 102 |
return resposta, total_tokens, prompt_tokens, top_segments, top_file_names, top_similarities, prompt_template
|
| 103 |
|
| 104 |
def rag_response(query, data, detailed_response):
|
| 105 |
+
api_key = load_api_key()
|
| 106 |
+
resposta, total_tokens, prompt_tokens, top_segments, top_file_names, top_similarities, prompt_template = generate_answer_with_references(query, data, api_key)
|
| 107 |
file_names = [x[0] for x in top_file_names]
|
| 108 |
file_links = {x[0]: x[1] for x in top_file_names}
|
| 109 |
|