-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
34 lines (24 loc) · 804 Bytes
/
main.py
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
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
from langchain_ollama import OllamaLLM
from langchain_core.prompts import ChatPromptTemplate
template = """
Answer the question below.
Here is the conversation history: {context}
Question: {question}
Answer:
"""
model = OllamaLLM(model='llama3')
prompt = ChatPromptTemplate.from_template(template)
chain = prompt | model
def handle_conversation():
context = ""
print("Welcome to the AI chatbot! Type 'exit' to quit the chat.")
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
break
result = chain.invoke({"context": context, "question": user_input})
print("Chatbot:", result)
context += f"\nUser: {user_input}\nChatbot: {result}"
if __name__ == "__main__":
handle_conversation()