Saif Rehman Nasir
commited on
Commit
·
5abd48d
1
Parent(s):
e1fa991
Add debug statement, Increase output token limit
Browse files
rag.py
CHANGED
@@ -14,6 +14,7 @@ from langchain_huggingface import HuggingFaceEndpoint
|
|
14 |
|
15 |
from typing import Dict, Any
|
16 |
from tqdm import tqdm
|
|
|
17 |
|
18 |
NEO4J_URI = os.getenv("NEO4J_URI")
|
19 |
NEO4J_USERNAME = os.getenv("NEO4J_USERNAME")
|
@@ -23,7 +24,7 @@ vector_index = os.getenv("VECTOR_INDEX")
|
|
23 |
chat_llm = HuggingFaceEndpoint(
|
24 |
repo_id="meta-llama/Meta-Llama-3-8B-Instruct",
|
25 |
task="text-generation",
|
26 |
-
max_new_tokens=
|
27 |
do_sample=False,
|
28 |
)
|
29 |
|
@@ -215,7 +216,7 @@ def global_retriever(query: str, level: int, response_type: str):
|
|
215 |
|
216 |
where 1, 2, 3, 7, 34, 46, and 64 represent the id (not the index) of the relevant data record.
|
217 |
|
218 |
-
Do not include information where the supporting evidence for it is not provided.
|
219 |
|
220 |
|
221 |
---Target response length and format---
|
@@ -227,7 +228,7 @@ def global_retriever(query: str, level: int, response_type: str):
|
|
227 |
|
228 |
{report_data}
|
229 |
|
230 |
-
Add sections and commentary to the response as appropriate for the length and format.
|
231 |
|
232 |
---Real Data---
|
233 |
"""
|
@@ -265,13 +266,18 @@ def global_retriever(query: str, level: int, response_type: str):
|
|
265 |
# print(community_data)
|
266 |
intermediate_results = []
|
267 |
i = 0
|
268 |
-
for community in tqdm(community_data[:
|
269 |
intermediate_response = map_chain.invoke(
|
270 |
{"question": query, "context_data": community["output"]}
|
271 |
)
|
272 |
intermediate_results.append(intermediate_response)
|
273 |
i += 1
|
274 |
|
|
|
|
|
|
|
|
|
|
|
275 |
final_response = reduce_chain.invoke(
|
276 |
{
|
277 |
"report_data": intermediate_results,
|
|
|
14 |
|
15 |
from typing import Dict, Any
|
16 |
from tqdm import tqdm
|
17 |
+
import tiktoken
|
18 |
|
19 |
NEO4J_URI = os.getenv("NEO4J_URI")
|
20 |
NEO4J_USERNAME = os.getenv("NEO4J_USERNAME")
|
|
|
24 |
chat_llm = HuggingFaceEndpoint(
|
25 |
repo_id="meta-llama/Meta-Llama-3-8B-Instruct",
|
26 |
task="text-generation",
|
27 |
+
max_new_tokens=4096,
|
28 |
do_sample=False,
|
29 |
)
|
30 |
|
|
|
216 |
|
217 |
where 1, 2, 3, 7, 34, 46, and 64 represent the id (not the index) of the relevant data record.
|
218 |
|
219 |
+
Do not include information where the supporting evidence for it is not provided.
|
220 |
|
221 |
|
222 |
---Target response length and format---
|
|
|
228 |
|
229 |
{report_data}
|
230 |
|
231 |
+
Add sections and commentary to the response as appropriate for the length and format. Do not add references in your answer.
|
232 |
|
233 |
---Real Data---
|
234 |
"""
|
|
|
266 |
# print(community_data)
|
267 |
intermediate_results = []
|
268 |
i = 0
|
269 |
+
for community in tqdm(community_data[:5], desc="Processing communities"):
|
270 |
intermediate_response = map_chain.invoke(
|
271 |
{"question": query, "context_data": community["output"]}
|
272 |
)
|
273 |
intermediate_results.append(intermediate_response)
|
274 |
i += 1
|
275 |
|
276 |
+
###Debug####
|
277 |
+
enc = tiktoken.encoding_for_model("gpt-4")
|
278 |
+
tokens = enc.encode(intermediate_results)
|
279 |
+
print(f"Number of input tokens: {len(tokens)}")
|
280 |
+
###Debug###
|
281 |
final_response = reduce_chain.invoke(
|
282 |
{
|
283 |
"report_data": intermediate_results,
|