mojuss commited on
Commit
84dd39a
·
verified ·
1 Parent(s): ec39ad5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -1,5 +1,8 @@
1
  from llama_index.core import SimpleDirectoryReader, GPTListIndex, GPTVectorStoreIndex, PromptHelper
2
- from llama_index.core import StorageContext, load_index_from_storage
 
 
 
3
  #from llama_index import LLMPredictor, PromptHelper
4
  #from langchain.chat_models import ChatOpenAI
5
  from langchain_community.embeddings import OpenAIEmbeddings
@@ -63,9 +66,26 @@ def construct_index(directory_path):
63
  def chatbotCustom(input):
64
  storage_context = StorageContext.from_defaults(persist_dir="index.json")
65
  index = load_index_from_storage(storage_context)
66
- query_engine = index.as_query_engine()
67
- response = query_engine.query(input, similarity_top_k=5, response_mode="tree_summarize")
68
- # response = index.query(input, similarity_top_k=5, response_mode="tree_summarize")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  return response.response
70
 
71
  #def chatbotGPT(input):
 
1
  from llama_index.core import SimpleDirectoryReader, GPTListIndex, GPTVectorStoreIndex, PromptHelper
2
+ from llama_index.core import StorageContext, load_index_from_storage, get_response_synthesizer
3
+ from llama_index.core.retrievers import VectorIndexRetriever
4
+ from llama_index.core.query_engine import RetrieverQueryEngine
5
+ from llama_index.core.postprocessor import SimilarityPostprocessor
6
  #from llama_index import LLMPredictor, PromptHelper
7
  #from langchain.chat_models import ChatOpenAI
8
  from langchain_community.embeddings import OpenAIEmbeddings
 
66
  def chatbotCustom(input):
67
  storage_context = StorageContext.from_defaults(persist_dir="index.json")
68
  index = load_index_from_storage(storage_context)
69
+ # query_engine = index.as_query_engine()
70
+ # response = query_engine.query(input, similarity_top_k=5, response_mode="tree_summarize")
71
+ ## response = index.query(input, similarity_top_k=5, response_mode="tree_summarize")
72
+ # configure retriever
73
+ retriever = VectorIndexRetriever(
74
+ index=index,
75
+ similarity_top_k=10,
76
+ )
77
+
78
+ # configure response synthesizer
79
+ response_synthesizer = get_response_synthesizer()
80
+
81
+ # assemble query engine
82
+ query_engine = RetrieverQueryEngine(
83
+ retriever=retriever,
84
+ response_synthesizer=response_synthesizer,
85
+ node_postprocessors=[SimilarityPostprocessor(similarity_cutoff=0.7)],
86
+ )
87
+
88
+ response = query_engine.query(input, response_mode="tree_summarize")
89
  return response.response
90
 
91
  #def chatbotGPT(input):