diff --git a/README.md b/README.md index 728d630..acb0a30 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ langs = ["python", "java", "Julia", "C++"] def data2chat(msg): chat = Chat() chat.user("请用语言 %s 打印 hello world" % msg) + # 注意,这里不需要 getresponse 而交给异步处理 return chat async_chat_completion(langs, chkpoint="async_chat.jsonl", nproc=2, data2chat=data2chat) diff --git a/README_en.md b/README_en.md index 7b4a42d..761b9cd 100644 --- a/README_en.md +++ b/README_en.md @@ -60,6 +60,7 @@ def msg2chat(msg): chat = Chat() chat.system("You are a helpful translator for numbers.") chat.user(f"Please translate the digit to Roman numerals: {msg}") + # We need to call `getresponse` here to get the response chat.getresponse() return chat @@ -80,6 +81,7 @@ langs = ["python", "java", "Julia", "C++"] def data2chat(msg): chat = Chat() chat.user("Please print hello world using %s" % msg) + # Note that we don't need to call `getresponse` here, and leave it to the asynchronous processing return chat async_chat_completion(langs, chkpoint="async_chat.jsonl", nproc=2, data2chat=data2chat) diff --git a/chattool/__init__.py b/chattool/__init__.py index faf0754..c80b1ef 100644 --- a/chattool/__init__.py +++ b/chattool/__init__.py @@ -2,7 +2,7 @@ __author__ = """Rex Wang""" __email__ = '1073853456@qq.com' -__version__ = '3.0.1' +__version__ = '3.1.0' import os, sys, requests from .chattool import Chat, Resp @@ -25,12 +25,12 @@ def load_envs(env:Union[None, str, dict]=None): for key, value in env.items(): os.environ[key] = value # else: load from environment variables - api_key = os.environ.get('OPENAI_API_KEY') - base_url = os.environ.get('OPENAI_API_BASE_URL', "https://api.openai.com") - api_base = os.environ.get('OPENAI_API_BASE', os.path.join(base_url, 'v1')) + api_key = os.getenv('OPENAI_API_KEY') + base_url = os.getenv('OPENAI_API_BASE_URL') or "https://api.openai.com" + api_base = os.getenv('OPENAI_API_BASE', os.path.join(base_url, 'v1')) base_url = request.normalize_url(base_url) api_base = request.normalize_url(api_base) - model = os.environ.get('OPENAI_API_MODEL', "gpt-3.5-turbo") + model = os.getenv('OPENAI_API_MODEL', "gpt-3.5-turbo") return True def save_envs(env_file:str): diff --git a/setup.py b/setup.py index 20bb558..a0286c9 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open('README.md') as readme_file: readme = readme_file.read() -VERSION = '3.0.1' +VERSION = '3.1.0' requirements = [ 'Click>=7.0', 'requests>=2.20', "responses>=0.23", 'aiohttp>=3.8',