Update appChatbot.py
Browse files- appChatbot.py +14 -6
appChatbot.py
CHANGED
@@ -31,6 +31,8 @@ embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
|
31 |
ABS_PATH = os.path.dirname(os.path.abspath(__file__))
|
32 |
DB_DIR = os.path.join(ABS_PATH, "db")
|
33 |
|
|
|
|
|
34 |
def replace_newlines_and_spaces(text):
|
35 |
# Replace all newline characters with spaces
|
36 |
text = text.replace("\n", " ")
|
@@ -63,8 +65,7 @@ def init_chromadb():
|
|
63 |
# Create the vectorestore to use as the index
|
64 |
vectorstore = Chroma.from_documents(texts, embeddings, persist_directory=DB_DIR)
|
65 |
vectorstore.persist()
|
66 |
-
print(vectorstore)
|
67 |
-
vectorstore = None
|
68 |
|
69 |
def query_chromadb(ASK):
|
70 |
if not os.path.exists(DB_DIR):
|
@@ -75,8 +76,8 @@ def query_chromadb(ASK):
|
|
75 |
|
76 |
result = vectorstore.similarity_search_with_score(query=ASK, k=4)
|
77 |
jsonable_result = jsonable_encoder(result)
|
78 |
-
print(json.dumps(jsonable_result, indent=2))
|
79 |
-
return json.dumps(jsonable_result, indent=2)
|
80 |
|
81 |
|
82 |
def respond(
|
@@ -106,11 +107,18 @@ def respond(
|
|
106 |
temperature=temperature,
|
107 |
top_p=top_p,
|
108 |
):
|
|
|
109 |
token = message.choices[0].delta.content
|
110 |
|
111 |
response += token
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
|
116 |
"""
|
|
|
31 |
ABS_PATH = os.path.dirname(os.path.abspath(__file__))
|
32 |
DB_DIR = os.path.join(ABS_PATH, "db")
|
33 |
|
34 |
+
vectorstore = None
|
35 |
+
|
36 |
def replace_newlines_and_spaces(text):
|
37 |
# Replace all newline characters with spaces
|
38 |
text = text.replace("\n", " ")
|
|
|
65 |
# Create the vectorestore to use as the index
|
66 |
vectorstore = Chroma.from_documents(texts, embeddings, persist_directory=DB_DIR)
|
67 |
vectorstore.persist()
|
68 |
+
print("vectorstore::", vectorstore)
|
|
|
69 |
|
70 |
def query_chromadb(ASK):
|
71 |
if not os.path.exists(DB_DIR):
|
|
|
76 |
|
77 |
result = vectorstore.similarity_search_with_score(query=ASK, k=4)
|
78 |
jsonable_result = jsonable_encoder(result)
|
79 |
+
print("Json pdf response ::", json.dumps(jsonable_result, indent=2))
|
80 |
+
#return json.dumps(jsonable_result, indent=2)
|
81 |
|
82 |
|
83 |
def respond(
|
|
|
107 |
temperature=temperature,
|
108 |
top_p=top_p,
|
109 |
):
|
110 |
+
|
111 |
token = message.choices[0].delta.content
|
112 |
|
113 |
response += token
|
114 |
+
|
115 |
+
print ("message::",message)
|
116 |
+
print ("token::",token)
|
117 |
+
print ("response::",response)
|
118 |
+
print ("query_chromadb::",query_chromadb("how could an AI be used in smart water management systems?"))
|
119 |
+
|
120 |
+
yield response
|
121 |
+
#yield query_chromadb(message)
|
122 |
|
123 |
|
124 |
"""
|