diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 14fae22..25a2a6f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: include: - - python-version: "3.8" + - python-version: "3.9" os: ubuntu-latest - python-version: "3.8" os: macos-latest diff --git a/README-ZH.md b/README-ZH.md index aa8c674..ce838c5 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -52,6 +52,10 @@ askchat --all-valid-models askchat hello # 继续上一次对话:-c askchat -c 请给我讲个笑话 +# 重新生成最后一次对话:-r +askchat -r +# 修改并重新生成最后一次对话:-r +askchat -r give me some jokes please # 保存对话:-s/--save askchat -s joke # 加载对话:-l/--load diff --git a/README.md b/README.md index f891777..53e9f98 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ You can manage your chats with `askchat`: askchat hello # continue the last chat: -c askchat -c tell me a joke please +# regenerate the last conversation: -r +askchat -r +# regenerate the last conversation with new message: -r +askchat -r give me some jokes please # save the chat: -s/--save askchat -s joke # load the chat: -l/--load diff --git a/askchat/__init__.py b/askchat/__init__.py index 6424149..411c040 100644 --- a/askchat/__init__.py +++ b/askchat/__init__.py @@ -2,6 +2,6 @@ __author__ = """Rex Wang""" __email__ = '1073853456@qq.com' -__version__ = '0.3.1' +__version__ = '0.3.2' from .askchat import ask \ No newline at end of file diff --git a/askchat/askchat.py b/askchat/askchat.py index 2369d54..7c13bdf 100644 --- a/askchat/askchat.py +++ b/askchat/askchat.py @@ -157,28 +157,30 @@ def main(): names = args.print assert len(names) <= 1, "Only one file can be specified" new_file = os.path.join(CONFIG_PATH, names[0]) + ".json" if len(names) else LAST_CHAT_FILE - with open(new_file, "r") as f: - chatlog = json.load(f) - Chat(chatlog).print_log() + chat = Chat.load(new_file) + chat.print_log() call_history = True if call_history: return # Initial message msg = args.message if isinstance(msg, list): - msg = ' '.join(msg) - assert len(msg.strip()), 'Please specify message' + msg = ' '.join(msg).strip() + chat = Chat(msg) if os.path.exists(LAST_CHAT_FILE): - with open(LAST_CHAT_FILE, "r") as f: - chatlog = json.load(f) if args.c: - msg = chatlog + [{"role":"user", "content":msg}] + chat = Chat.load(LAST_CHAT_FILE) + chat.user(msg) elif args.r: - if len(chatlog) > 0:chatlog.pop() - if len(chatlog) > 0:chatlog.pop() - msg = chatlog + [{"role":"user", "content":msg}] - + # pop out the last two messages + chat = Chat.load(LAST_CHAT_FILE) + assert len(chat) > 1, "Please specify message!" + chat.pop() + if len(msg) != 0: # not empty message + chat.pop() + chat.user(msg) + # if msg is empty, regenerate the last message + assert len(chat) > 0 and len(chat.last_message) > 0, "Please specify message!" # call the function - chat = Chat(msg) - msg = asyncio.run(show_resp(chat)) - chat.assistant(msg) + newmsg = asyncio.run(show_resp(chat)) + chat.assistant(newmsg) chat.save(LAST_CHAT_FILE, mode='w') \ No newline at end of file diff --git a/setup.py b/setup.py index 05c7a06..6729fb2 100644 --- a/setup.py +++ b/setup.py @@ -4,12 +4,12 @@ from setuptools import setup, find_packages -VERSION = '0.3.1' +VERSION = '0.3.2' with open('README.md') as readme_file: readme = readme_file.read() -requirements = ['chattool>=2.5.0', "python-dotenv>=0.17.0"] +requirements = ['chattool>=2.6.0', "python-dotenv>=0.17.0"] test_requirements = ['pytest>=3']