Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use env key in curl #85

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chattool/__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__ = '3.3.2'
__version__ = '3.3.3'

import os, sys, requests, json
from .chattype import Chat, Resp
Expand Down
18 changes: 15 additions & 3 deletions chattool/chattype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chattool/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(" \\")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_curlcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading