Spaces:
Sleeping
Sleeping
now able to store chat history into chroma db
Browse files
app.py
CHANGED
@@ -9,11 +9,35 @@ from innovation_pathfinder_ai.utils import logger
|
|
9 |
from innovation_pathfinder_ai.utils.utils import (
|
10 |
generate_uuid
|
11 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
logger = logger.get_console_logger("app")
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
if __name__ == "__main__":
|
16 |
|
|
|
|
|
|
|
|
|
17 |
def add_text(history, text):
|
18 |
history = history + [(text, None)]
|
19 |
return history, ""
|
@@ -34,6 +58,18 @@ if __name__ == "__main__":
|
|
34 |
"chat_history": history
|
35 |
}
|
36 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
return result
|
38 |
|
39 |
def vote(data: gr.LikeData):
|
|
|
9 |
from innovation_pathfinder_ai.utils.utils import (
|
10 |
generate_uuid
|
11 |
)
|
12 |
+
from langchain_community.vectorstores import Chroma
|
13 |
+
|
14 |
+
import chromadb
|
15 |
+
import dotenv
|
16 |
+
import os
|
17 |
+
|
18 |
+
dotenv.load_dotenv()
|
19 |
|
20 |
logger = logger.get_console_logger("app")
|
21 |
|
22 |
+
def initialize_chroma_db() -> Chroma:
|
23 |
+
collection_name=os.getenv("CONVERSATION_COLLECTION_NAME")
|
24 |
+
|
25 |
+
client = chromadb.PersistentClient()
|
26 |
+
|
27 |
+
collection = client.get_or_create_collection(
|
28 |
+
name=collection_name,
|
29 |
+
)
|
30 |
+
|
31 |
+
return collection
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
if __name__ == "__main__":
|
36 |
|
37 |
+
current_id = generate_uuid()
|
38 |
+
|
39 |
+
db = initialize_chroma_db()
|
40 |
+
|
41 |
def add_text(history, text):
|
42 |
history = history + [(text, None)]
|
43 |
return history, ""
|
|
|
58 |
"chat_history": history
|
59 |
}
|
60 |
)
|
61 |
+
|
62 |
+
db.add(
|
63 |
+
ids=[current_id],
|
64 |
+
documents=[result['output']],
|
65 |
+
metadatas=[
|
66 |
+
{
|
67 |
+
"query":query,
|
68 |
+
"intermediate_steps":result['intermediate_steps'].__str__()
|
69 |
+
}
|
70 |
+
]
|
71 |
+
)
|
72 |
+
|
73 |
return result
|
74 |
|
75 |
def vote(data: gr.LikeData):
|