-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchatbot.py
More file actions
26 lines (23 loc) · 1010 Bytes
/
chatbot.py
File metadata and controls
26 lines (23 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
from dotenv import load_dotenv
from poml.integration.langchain import LangchainPomlTemplate
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.output_parsers import StrOutputParser
load_dotenv()
llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash-lite", google_api_key=os.getenv("GEMINI_API_KEY"))
def chatbot(user_input, file_path=""):
"""
Unified chatbot function that handles both text-only and document chat.
POML handles all document parsing, conditional logic, and prompt generation.
"""
prompt_template = LangchainPomlTemplate.from_file("prompt.poml")
chain = prompt_template | llm | StrOutputParser()
return chain.invoke({"question": user_input, "file_path": file_path})
if __name__ == "__main__":
while True:
user_input = input("You: ")
if user_input.lower() in ["exit", "quit", "bye"]:
print("Goodbye!")
break
response = chatbot(user_input)
print("Caramel AI:", response)