Skip to content

Commit

Permalink
✨ Add chat memory feature
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Nov 14, 2023
1 parent f52b4e7 commit b340d4e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/chatgpt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Simple chatgpt rebuild with memory/history.
"""
from funcchain import chain
from langchain.memory import ChatMessageHistory


history = ChatMessageHistory()


def ask(question: str) -> str:
return chain(
instruction=question,
system="You are an advanced AI Assistant.",
memory=history,
)


def chat_loop() -> None:
while True:
query = input("> ")

if query == "exit":
break

if query == "clear":
global history
history.clear()
print("\033c")
continue

print("AI:", ask(query))


if __name__ == "__main__":
print("Hey! How can I help you?")
chat_loop()

0 comments on commit b340d4e

Please sign in to comment.