Skip to content

Commit

Permalink
allow regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
RexWzh committed Nov 25, 2023
1 parent 1f4e5bb commit 0f013d1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion askchat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

__author__ = """Rex Wang"""
__email__ = '[email protected]'
__version__ = '0.3.1'
__version__ = '0.3.2'

from .askchat import ask
32 changes: 17 additions & 15 deletions askchat/askchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Check warning on line 161 in askchat/askchat.py

View check run for this annotation

Codecov / codecov/patch

askchat/askchat.py#L160-L161

Added lines #L160 - L161 were not covered by tests
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:

Check warning on line 173 in askchat/askchat.py

View check run for this annotation

Codecov / codecov/patch

askchat/askchat.py#L167-L173

Added lines #L167 - L173 were not covered by tests
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)

Check warning on line 180 in askchat/askchat.py

View check run for this annotation

Codecov / codecov/patch

askchat/askchat.py#L175-L180

Added lines #L175 - L180 were not covered by tests
# if msg is empty, regenerate the last message
assert len(chat) > 0 and len(chat.last_message) > 0, "Please specify message!"

Check warning on line 182 in askchat/askchat.py

View check run for this annotation

Codecov / codecov/patch

askchat/askchat.py#L182

Added line #L182 was not covered by tests
# call the function
chat = Chat(msg)
msg = asyncio.run(show_resp(chat))
chat.assistant(msg)
newmsg = asyncio.run(show_resp(chat))
chat.assistant(newmsg)

Check warning on line 185 in askchat/askchat.py

View check run for this annotation

Codecov / codecov/patch

askchat/askchat.py#L184-L185

Added lines #L184 - L185 were not covered by tests
chat.save(LAST_CHAT_FILE, mode='w')
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down

0 comments on commit 0f013d1

Please sign in to comment.