Spaces:
Sleeping
Sleeping
Commit
·
1448822
1
Parent(s):
6f367b5
Added redis streams listener fix
Browse files
app.py
CHANGED
|
@@ -17,55 +17,6 @@ from langchain_core.runnables.history import RunnableWithMessageHistory
|
|
| 17 |
from langchain_core.chat_history import BaseChatMessageHistory
|
| 18 |
from langchain.chains import RetrievalQA
|
| 19 |
import nest_asyncio
|
| 20 |
-
import pymongo
|
| 21 |
-
import logging
|
| 22 |
-
from langchain.docstore.document import Document
|
| 23 |
-
import redis
|
| 24 |
-
import threading
|
| 25 |
-
|
| 26 |
-
# config
|
| 27 |
-
nest_asyncio.apply()
|
| 28 |
-
logging.basicConfig(level=logging.INFO)
|
| 29 |
-
database = "AlertSimAndRemediation"
|
| 30 |
-
collection = "alert_embed"
|
| 31 |
-
index_name = "alert_index"
|
| 32 |
-
stream_name = "alerts"
|
| 33 |
-
redis_port = 16652
|
| 34 |
-
|
| 35 |
-
# embedding model
|
| 36 |
-
embedding_args = {
|
| 37 |
-
"model_name" : "BAAI/bge-large-en-v1.5",
|
| 38 |
-
"model_kwargs" : {"device": "cpu"},
|
| 39 |
-
"encode_kwargs" : {"normalize_embeddings": True}
|
| 40 |
-
}
|
| 41 |
-
embedding_model = HuggingFaceEmbeddings(**embedding_args)
|
| 42 |
-
|
| 43 |
-
# Mongo Connection
|
| 44 |
-
connection = pymongo.MongoClient(os.environ["MONGO_URI"])
|
| 45 |
-
alert_collection = connection[database][collection]
|
| 46 |
-
|
| 47 |
-
# redis connection
|
| 48 |
-
r = redis.Redis(host=os.environ['REDIS_HOST'], password=os.environ['REDIS_PWD'], port=port)
|
| 49 |
-
|
| 50 |
-
Sure, here's the entire code with the Streamlit app and the Redis stream listener combined:
|
| 51 |
-
pythonCopy codeimport streamlit as st
|
| 52 |
-
import os
|
| 53 |
-
from collections.abc import Collection
|
| 54 |
-
from langchain.memory import ChatMessageHistory
|
| 55 |
-
from langchain_community.chat_message_histories import (
|
| 56 |
-
StreamlitChatMessageHistory,
|
| 57 |
-
)
|
| 58 |
-
from langchain_groq import ChatGroq
|
| 59 |
-
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 60 |
-
from langchain_community.vectorstores import MongoDBAtlasVectorSearch
|
| 61 |
-
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 62 |
-
from langchain.chains import create_history_aware_retriever, create_retrieval_chain
|
| 63 |
-
from langchain.chains.combine_documents import create_stuff_documents_chain
|
| 64 |
-
from langchain.output_parsers import ResponseSchema, StructuredOutputParser
|
| 65 |
-
from langchain_core.runnables.history import RunnableWithMessageHistory
|
| 66 |
-
from langchain_core.chat_history import BaseChatMessageHistory
|
| 67 |
-
from langchain.chains import RetrievalQA
|
| 68 |
-
import nest_asyncio
|
| 69 |
nest_asyncio.apply()
|
| 70 |
|
| 71 |
import pymongo
|
|
|
|
| 17 |
from langchain_core.chat_history import BaseChatMessageHistory
|
| 18 |
from langchain.chains import RetrievalQA
|
| 19 |
import nest_asyncio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
nest_asyncio.apply()
|
| 21 |
|
| 22 |
import pymongo
|