Skip to content

Commit

Permalink
✨ Added chat export feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mraniki committed Sep 27, 2023
1 parent 96fd34e commit 5a0352b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ async def main():
time.sleep(10)
chat = await talky.chat("what is my name")
logger.info(chat)
# Your name is Jack, as you mentioned earlier.
# Your name is Jack, as you mentioned earlier

talky.conversation.export_messages()


app = FastAPI()
Expand Down
30 changes: 30 additions & 0 deletions history.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"role": "user",
"content": "You are a friendly AI, helping me with \ngeneral tasks.\n"
},
{
"role": "user",
"content": "My name is Jack"
},
{
"role": "ai",
"content": "Hello Jack, this is Bing. Nice to meet you. \ud83d\ude0a"
},
{
"role": "user",
"content": "tell me who is president of the united states?"
},
{
"role": "ai",
"content": "[1]: https://simple.wikipedia.org/wiki/President_of_the_United_States \"President of the United States - Simple English Wikipedia, the free ...\"\n[2]: https://www.history.com/topics/us-presidents/joe-biden \"Joe Biden: Age, Presidency, Family - HISTORY\"\n[3]: https://www.whitehouse.gov/about-the-white-house/presidents/barack-obama/ \"Barack Obama | The White House\"\n[4]: https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States \"List of presidents of the United States - Wikipedia\"\n[5]: https://www.whitehouse.gov/about-the-white-house/presidents/ \"Presidents | The White House\"\n[6]: https://www.britannica.com/topic/Presidents-of-the-United-States-1846696 \"list of presidents of the United States - Encyclopedia Britannica\"\n\nThe current president of the United States is **Joe Biden**, who took office in January 2021[^1^][1] [^2^][2]. He is the 46th president of the United States[^3^][4] [^4^][5]. Do you want to know more about him or any other president?"
},
{
"role": "user",
"content": "what is my name"
},
{
"role": "ai",
"content": "You told me your name is Jack. Is that correct?"
}
]
5 changes: 5 additions & 0 deletions myllm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import importlib
import json
from time import sleep

from g4f import Provider
Expand Down Expand Up @@ -123,3 +124,7 @@ def add_message(self, role: str, content: str):

def get_messages(self):
return self.messages

def export_messages(self):
with open("history.json", "w") as f:
json.dump(self.messages, f, indent=4)

Check warning on line 130 in myllm/main.py

View check run for this annotation

Codecov / codecov/patch

myllm/main.py#L129-L130

Added lines #L129 - L130 were not covered by tests
6 changes: 6 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ async def test_get_myllm_info(talky):
assert "ℹ️" in result


@pytest.mark.asyncio
async def test_clear_chat_history(talky):
history = talky.conversation.export_messages()
assert history is not None

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.


@pytest.mark.asyncio
async def test_clear_chat_history(talky):
await talky.clear_chat_history()
Expand Down

0 comments on commit 5a0352b

Please sign in to comment.