Skip to content

Commit

Permalink
new feature: print curl command
Browse files Browse the repository at this point in the history
  • Loading branch information
RexWzh committed Jun 17, 2024
1 parent 38d83f7 commit 466a732
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Auxiliary features, such as generating configuration files, debugging logs, prin
| Parameter | Example | Explanation |
|--------------------------|----------------------------------|---------------------------------------|
| `--generate-config` | `askchat --generate-config` | Generate a configuration file, saved in `~/.askchat/.env` |
| `--print-curl` | `askchat hello --print-curl` | Print the actual request URL |
| `--debug` | `askchat --debug` | Print debugging logs |
| `--valid-models` | `askchat --valid-models` | Print a list of models containing "gpt" in their names |
| `--all-valid-models` | `askchat --all-valid-models` | Print all available models |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ ask hello world
| 参数 | 示例 | 解释 |
|---------------------------|----------------------|--------------------------------------------|
| `--generate-config` | `askchat --generate-config` | 生成配置文件,保存在 `~/.askchat/.env`|
| `--print-url` | `askchat hello --print-url` | 打印实际请求的 URL |
| `--debug` | `askchat --debug` | 打印调试日志 |
| `--valid-models` | `askchat --valid-models` | 打印包含 "gpt" 名称的模型列表 |
| `--all-valid-models` | `askchat --all-valid-models` | 打印所有的模型 |
Expand Down
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__ = '1073853456@qq.com'
__version__ = '1.1.6'
__version__ = '1.2.0'

import asyncio
from pathlib import Path
Expand Down
11 changes: 9 additions & 2 deletions askchat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ def cli():
@click.option('--debug', is_flag=True, callback=debug_log_callback, expose_value=False, help='Print debug log')
@click.option('--valid-models', is_flag=True, callback=valid_models_callback, expose_value=False, help='Print valid models that contain "gpt" in their names')
@click.option('--all-valid-models', is_flag=True, callback=all_valid_models_callback, expose_value=False, help='Print all valid models')
@click.option('--print-curl', is_flag=True, help='Print the curl command for the request')
@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, p, option):
, c, regenerate, p, option, print_curl):
"""Interact with ChatGPT in terminal via chattool"""
setup()
message_text = ' '.join(message).strip()
Expand Down Expand Up @@ -215,9 +216,15 @@ def main( message, model, base_url, api_base, api_key, use_env
option[key] = float(value)
else:
option = {}
# Add chat responses
if option.get('stream') in ['false', 0]:
option['stream'] = False
else:
option['stream'] = True
if print_curl:
chat.print_curl(**option)
return
# Add chat responses
if not option['stream']:
chat.getresponse(**option)
for text in chat.last_message:
print(text, end='', flush=True)
Expand Down
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 = '1.1.6'
VERSION = '1.2.0'

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

requirements = ['chattool>=3.1.4', "python-dotenv>=0.17.0", 'Click>=8.0']
requirements = ['chattool>=3.2.0', "python-dotenv>=0.17.0", 'Click>=8.0']

test_requirements = ['pytest>=3']

Expand Down

0 comments on commit 466a732

Please sign in to comment.