Skip to content

Commit

Permalink
add keyword: stream
Browse files Browse the repository at this point in the history
  • Loading branch information
RexWzh committed May 31, 2024
1 parent 76a219d commit 3dc9f55
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion askchat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """Rex Wang"""
__email__ = '[email protected]'
__version__ = '1.1.5'
__version__ = '1.1.6'

import asyncio
from pathlib import Path
Expand Down
15 changes: 11 additions & 4 deletions askchat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def cli():
@click.option('-r', '--regenerate', is_flag=True, help='Regenerate the last conversation')
@click.option('-l', '--load', default=None, type=ChatFileCompletionType(), callback=load_chat_callback, expose_value=False, help='Load a conversation from a file')
# Handling chat history
@click.option('-p', '--print', is_flag=True, help='Print the last conversation or a specific conversation')
@click.option('-p', is_flag=True, help='Print the last conversation or a specific conversation')
@click.option('-s', '--save', callback=save_chat_callback, expose_value=False, help='Save the conversation to a file')
@click.option('-d', '--delete', type=ChatFileCompletionType(), callback=delete_chat_callback, expose_value=False, help='Delete the conversation from a file')
@click.option('--list', is_flag=True, callback=list_chats_callback, expose_value=False, help='List all the conversation files')
Expand All @@ -152,7 +152,7 @@ def cli():
@click.option('-v', '--version', is_flag=True, callback=version_callback, expose_value=False, help='Print the version')
@click.option('-o', '--option', multiple=True, type=(str, str), help='Additional options for show_resp in the form of key=value')
def main( message, model, base_url, api_base, api_key, use_env
, c, regenerate, print, option):
, c, regenerate, p, option):
"""Interact with ChatGPT in terminal via chattool"""
setup()
message_text = ' '.join(message).strip()
Expand All @@ -168,7 +168,7 @@ def main( message, model, base_url, api_base, api_key, use_env
os.environ['OPENAI_API_MODEL'] = model
chattool.load_envs() # update the environment variables in chattool
# print chat messages
if print:
if p:
fname = message_text if message_text else '_last_chat'
fname = f"{CONFIG_PATH}/{fname}.json"
try:
Expand Down Expand Up @@ -216,7 +216,14 @@ def main( message, model, base_url, api_base, api_key, use_env
else:
option = {}
# Add chat responses
chat.assistant(asyncio.run(show_resp(chat, **dict(option))))
if option.get('stream') in ['false', 0]:
option['stream'] = False
chat.getresponse(**option)
for text in chat.last_message:
print(text, end='', flush=True)
else:
chat.assistant(asyncio.run(show_resp(chat, **dict(option))))

chat.save(LAST_CHAT_FILE, mode='w')

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import setup, find_packages

VERSION = '1.1.5'
VERSION = '1.1.6'

with open('README.md') as readme_file:
readme = readme_file.read()
Expand Down

0 comments on commit 3dc9f55

Please sign in to comment.