Spaces:
Runtime error
Runtime error
emar
commited on
Commit
•
86518f0
1
Parent(s):
981a527
revert to best working version
Browse files
app.py
CHANGED
@@ -21,39 +21,44 @@ Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-base-en-v1.5",
|
|
21 |
Settings.llm = HuggingFaceLLM(
|
22 |
model_name="meta-llama/Meta-Llama-3-8B-Instruct",
|
23 |
tokenizer_name="meta-llama/Meta-Llama-3-8B-Instruct",
|
24 |
-
context_window=
|
25 |
-
max_new_tokens=
|
26 |
-
generate_kwargs={"temperature": 0.
|
27 |
device_map="auto",
|
28 |
)
|
29 |
|
30 |
storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
|
31 |
index = load_index_from_storage(storage_context)
|
32 |
|
33 |
-
prompt_helper = PromptHelper(
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
)
|
39 |
|
40 |
-
retriever = VectorIndexRetriever(
|
41 |
-
|
42 |
-
|
43 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
node_postprocessors=[SimilarityPostprocessor(similarity_cutoff=0.7)],
|
48 |
-
prompt_helper=prompt_helper
|
49 |
)
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
|
58 |
|
59 |
@spaces.GPU
|
|
|
21 |
Settings.llm = HuggingFaceLLM(
|
22 |
model_name="meta-llama/Meta-Llama-3-8B-Instruct",
|
23 |
tokenizer_name="meta-llama/Meta-Llama-3-8B-Instruct",
|
24 |
+
context_window=2048,
|
25 |
+
max_new_tokens=256,
|
26 |
+
generate_kwargs={"temperature": 0.7, "top_k": 50, "top_p": 0.95},
|
27 |
device_map="auto",
|
28 |
)
|
29 |
|
30 |
storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
|
31 |
index = load_index_from_storage(storage_context)
|
32 |
|
33 |
+
# prompt_helper = PromptHelper(
|
34 |
+
# context_window=4096,
|
35 |
+
# num_output=512,
|
36 |
+
# chunk_overlap_ratio=0.1,
|
37 |
+
# chunk_size_limit=None
|
38 |
+
# )
|
39 |
|
40 |
+
# retriever = VectorIndexRetriever(
|
41 |
+
# index=index,
|
42 |
+
# similarity_top_k=5,
|
43 |
+
# )
|
44 |
+
|
45 |
+
# query_engine = RetrieverQueryEngine.from_args(
|
46 |
+
# retriever,
|
47 |
+
# node_postprocessors=[SimilarityPostprocessor(similarity_cutoff=0.7)],
|
48 |
+
# prompt_helper=prompt_helper
|
49 |
+
# )
|
50 |
|
51 |
+
rerank = SentenceTransformerRerank(
|
52 |
+
model="BAAI/bge-reranker-large", top_n=5 # Note here
|
|
|
|
|
53 |
)
|
54 |
+
query_engine = index.as_query_engine(streaming=True, similarity_top_k=1, node_postprocessors=[rerank])
|
55 |
|
56 |
+
|
57 |
+
# def chatbot_response(message, history):
|
58 |
+
# # Add a custom prompt template
|
59 |
+
# prompt = f"Based on the Elder Scrolls lore, please answer the following question:\n\n{message}\n\nAnswer:"
|
60 |
+
# response = query_engine.query(prompt)
|
61 |
+
# return str(response)
|
62 |
|
63 |
|
64 |
@spaces.GPU
|