diff --git a/chattool/__init__.py b/chattool/__init__.py index 29e94bb..fc3cd50 100644 --- a/chattool/__init__.py +++ b/chattool/__init__.py @@ -2,7 +2,7 @@ __author__ = """Rex Wang""" __email__ = '1073853456@qq.com' -__version__ = '3.3.2' +__version__ = '3.3.3' import os, sys, requests, json from .chattype import Chat, Resp diff --git a/chattool/chattype.py b/chattool/chattype.py index 739e367..fa06d8c 100644 --- a/chattool/chattype.py +++ b/chattool/chattype.py @@ -398,14 +398,26 @@ def get_valid_models(self, gpt_only:bool=True)->List[str]: model_url = os.path.join(self.base_url, 'v1/models') return valid_models(self.api_key, model_url, gpt_only=gpt_only) - def get_curl(self, **options): - """Print the curl command""" + def get_curl(self, use_env_key:bool=False, **options): + """Get the curl command + + Args: + use_env_key (bool, optional): whether to replace the API key with environment variable. Defaults to False. + + Returns: + str: curl command + """ options = self._init_options(**options) api_key, chat_log, chat_url = self.api_key, self.chat_log, self.chat_url + if use_env_key: api_key = '$OPENAI_API_KEY' return curl_cmd_of_chat_completion(api_key, chat_url, chat_log, **options) def print_curl(self, **options): - """Print the curl command""" + """Print the curl command + + Args: + use_env_key (bool, optional): whether to use the environment key. Defaults to False. + """ print(self.get_curl(**options)) # Part5: properties and setters diff --git a/chattool/request.py b/chattool/request.py index 37301d8..d88ed7a 100644 --- a/chattool/request.py +++ b/chattool/request.py @@ -110,7 +110,7 @@ def curl_cmd_of_chat_completion( api_key:str } curl_cmd += f"\n -H 'Content-Type: application/json' \\" curl_cmd += f"\n -H 'Authorization: Bearer {api_key}' \\" - curl_cmd += f"\n -d '{json.dumps(payload, indent=4)}' \\" + curl_cmd += f"\n -d '{json.dumps(payload, indent=4, ensure_ascii=False)}' \\" if isinstance(timeout, int) and timeout > 0: curl_cmd += f"\n --max-time {timeout} \\" return curl_cmd.rstrip(" \\") diff --git a/setup.py b/setup.py index 5a62168..ec36d53 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open('README.md') as readme_file: readme = readme_file.read() -VERSION = '3.3.2' +VERSION = '3.3.3' requirements = [ 'Click>=7.0', 'requests>=2.20', "responses>=0.23", 'aiohttp>=3.8', diff --git a/tests/test_curlcmd.py b/tests/test_curlcmd.py index 2f2c14d..c5dd078 100644 --- a/tests/test_curlcmd.py +++ b/tests/test_curlcmd.py @@ -27,7 +27,7 @@ def add(a: int, b: int) -> int: def test_tool_call(): chat = Chat() chat.user("find the sum of 784359345 and 345345345") - chat.print_curl() + chat.print_curl(use_env_key=True) chat.settools([add]) chat.print_curl() chat.tool_type = 'function_call'