Spaces:
Sleeping
Sleeping
MefhigosetH
commited on
Commit
•
a1d0ad2
1
Parent(s):
e742fa6
Primera version de RAG
Browse files- .gitignore +1 -0
- app.py +13 -1
- chatbot/llm.py +2 -1
.gitignore
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
Pipfile.lock
|
2 |
*.pdf
|
|
|
3 |
.env
|
4 |
chroma_db/
|
|
|
1 |
Pipfile.lock
|
2 |
*.pdf
|
3 |
+
*.zip
|
4 |
.env
|
5 |
chroma_db/
|
app.py
CHANGED
@@ -3,18 +3,30 @@ Chatbot Nuevo Régimen Académico
|
|
3 |
"""
|
4 |
from chatbot.ui import ChatbotInterface
|
5 |
from chatbot.llm import GeminiAI
|
|
|
|
|
6 |
from langchain.globals import set_verbose, set_debug
|
7 |
|
8 |
|
|
|
|
|
|
|
|
|
9 |
def respond(message, history):
|
|
|
10 |
chain = llm.main_prompt | llm.llm
|
11 |
-
|
|
|
12 |
return response.content
|
13 |
|
14 |
|
15 |
if __name__ == "__main__":
|
16 |
set_verbose(True)
|
17 |
set_debug(True)
|
|
|
|
|
|
|
|
|
18 |
llm = GeminiAI("gemini-1.5-flash")
|
19 |
ui = ChatbotInterface(respond)
|
20 |
|
|
|
3 |
"""
|
4 |
from chatbot.ui import ChatbotInterface
|
5 |
from chatbot.llm import GeminiAI
|
6 |
+
from chatbot.embeddings import init_embeddings
|
7 |
+
from chatbot.vectorstore import ChromaDB
|
8 |
from langchain.globals import set_verbose, set_debug
|
9 |
|
10 |
|
11 |
+
def format_docs(docs):
|
12 |
+
return "\n\n".join(doc.page_content for doc in docs)
|
13 |
+
|
14 |
+
|
15 |
def respond(message, history):
|
16 |
+
docs = retriever.invoke(message)
|
17 |
chain = llm.main_prompt | llm.llm
|
18 |
+
|
19 |
+
response = chain.invoke({"context": format_docs(docs), "message": message, "history": history})
|
20 |
return response.content
|
21 |
|
22 |
|
23 |
if __name__ == "__main__":
|
24 |
set_verbose(True)
|
25 |
set_debug(True)
|
26 |
+
|
27 |
+
embeddings = init_embeddings()
|
28 |
+
retriever = ChromaDB(embeddings).db.as_retriever(search_type="similarity", search_kwargs={"k": 3})
|
29 |
+
|
30 |
llm = GeminiAI("gemini-1.5-flash")
|
31 |
ui = ChatbotInterface(respond)
|
32 |
|
chatbot/llm.py
CHANGED
@@ -9,8 +9,9 @@ class GeminiAI:
|
|
9 |
"""
|
10 |
|
11 |
system_prompt = """
|
12 |
-
Eres un asesor experto en la Resolucion 1650/24 de la DGCyE de la Provincia de Buenos Aires
|
13 |
Tu tarea es utiliza la información de la conversación y el contexto disponible para responder las consultas del usuario.
|
|
|
14 |
"""
|
15 |
|
16 |
def __init__(self, llm_model_name: str) -> None:
|
|
|
9 |
"""
|
10 |
|
11 |
system_prompt = """
|
12 |
+
Eres un asesor experto en la Resolucion 1650/24 de la DGCyE de la Provincia de Buenos Aires.
|
13 |
Tu tarea es utiliza la información de la conversación y el contexto disponible para responder las consultas del usuario.
|
14 |
+
Contexto: {context}
|
15 |
"""
|
16 |
|
17 |
def __init__(self, llm_model_name: str) -> None:
|