|
""" |
|
Chatbot Nuevo Régimen Académico |
|
""" |
|
from chatbot.ui import ChatbotInterface |
|
from chatbot.llm import GeminiAI |
|
from chatbot.embeddings import init_embeddings |
|
from chatbot.vectorstore import ChromaDB |
|
from langchain.globals import set_verbose, set_debug |
|
|
|
|
|
def format_docs(docs): |
|
return "\n\n".join(doc.page_content for doc in docs) |
|
|
|
|
|
def respond(message, history): |
|
docs = retriever.invoke(message) |
|
chain = llm.main_prompt | llm.llm |
|
|
|
response = chain.invoke({"context": format_docs(docs), "message": message, "history": history}) |
|
return response.content |
|
|
|
|
|
if __name__ == "__main__": |
|
set_verbose(True) |
|
set_debug(True) |
|
|
|
embeddings = init_embeddings() |
|
retriever = ChromaDB(embeddings).db.as_retriever(search_type="similarity", search_kwargs={"k": 3}) |
|
|
|
llm = GeminiAI("gemini-1.5-flash") |
|
ui = ChatbotInterface(respond) |
|
|
|
ui.app.launch() |
|
|