refactored project to use poetry
This commit is contained in:
0
rag_system/app/__init__.py
Normal file
0
rag_system/app/__init__.py
Normal file
44
rag_system/app/rag_chain.py
Normal file
44
rag_system/app/rag_chain.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from llm.ollama import load_llm
|
||||
from vectordb.azure_search import retrieve
|
||||
from langchain.prompts import PromptTemplate
|
||||
from langchain_core.output_parsers import StrOutputParser
|
||||
|
||||
# Define the prompt template for the LLM
|
||||
prompt = PromptTemplate(
|
||||
template="""You are an assistant for question-answering tasks.
|
||||
Use the following context to answer the question.
|
||||
If you don't know the answer, just say that you don't know.
|
||||
Use three sentences maximum and keep the answer concise:
|
||||
Question: {question}
|
||||
Context: {context}
|
||||
Answer:
|
||||
""",
|
||||
input_variables=["question", "documents"],
|
||||
)
|
||||
|
||||
|
||||
def get_rag_response(query):
|
||||
print("⌄⌄⌄⌄ Retrieving ⌄⌄⌄⌄")
|
||||
retrieved_docs = retrieve(query, 10)
|
||||
print("Query Found %d documents." % len(retrieved_docs))
|
||||
|
||||
print("⌃⌃⌃⌃ Retrieving ⌃⌃⌃⌃ ")
|
||||
|
||||
print("⌄⌄⌄⌄ Augmented Prompt ⌄⌄⌄⌄")
|
||||
llm = load_llm()
|
||||
# Create a chain combining the prompt template and LLM
|
||||
rag_chain = prompt | llm | StrOutputParser()
|
||||
context = (
|
||||
(" ".join(doc.page_content) for doc in retrieved_docs)
|
||||
if retrieved_docs
|
||||
else "No relevant documents found."
|
||||
)
|
||||
|
||||
print("⌃⌃⌃⌃ Augmented Prompt ⌃⌃⌃⌃")
|
||||
|
||||
print("⌄⌄⌄⌄ Generation ⌄⌄⌄⌄")
|
||||
response = rag_chain.invoke({"question": query, "context": context})
|
||||
print(response)
|
||||
print("⌃⌃⌃⌃ Generation ⌃⌃⌃⌃")
|
||||
|
||||
return response
|
||||
9
rag_system/app/streamlit_app.py
Normal file
9
rag_system/app/streamlit_app.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import streamlit as st
|
||||
from rag_system.app.rag_chain import get_rag_response
|
||||
|
||||
st.title("RAG System")
|
||||
query = st.text_input("Ask a question:")
|
||||
if query:
|
||||
response = get_rag_response(query)
|
||||
st.write("### Response:")
|
||||
st.write(response)
|
||||
Reference in New Issue
Block a user