-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f52b4e7
commit b340d4e
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |