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

adapt to linux/macos #43

Merged
merged 2 commits into from
Sep 7, 2023
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
13 changes: 11 additions & 2 deletions openai_api_call/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

__author__ = """Rex Wang"""
__email__ = '[email protected]'
__version__ = '1.1.0'
__version__ = '1.1.1'

import os, requests
import os, sys, requests
from .chattool import Chat, Resp
from .checkpoint import load_chats, process_chats
from .proxy import proxy_on, proxy_off, proxy_status
Expand All @@ -25,6 +25,15 @@
base_url = "https://api.openai.com"
base_url = request.normalize_url(base_url)

# get the platform
platform = sys.platform
if platform.startswith("win"):
platform = "windows"
elif platform.startswith("linux"):
platform = "linux"
elif platform.startswith("darwin"):
platform = "macos"

def show_apikey():
if api_key is not None:
print(f"API key:\t{api_key}")
Expand Down
5 changes: 4 additions & 1 deletion openai_api_call/asynctool.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ async def chat_complete(ind, locker, chatlog, chkpoint, **options):
, chatlog=chatlog
, chkpoint=chkpoint
, **options)))
responses = await tqdm.gather(tasks)
if openai_api_call.platform == "macos":
responses = await tqdm.gather(tasks)
else: # not work for windows yet
responses = await asyncio.gather(*tasks)
return responses

def async_chat_completion( chatlogs:List[List[Dict]]
Expand Down
9 changes: 6 additions & 3 deletions openai_api_call/chattool.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ class Chat():
def __init__( self
, msg:Union[List[Dict], None, str]=None
, api_key:Union[None, str]=None
, chat_url:Union[None, str]=None) -> None:
, chat_url:Union[None, str]=None
, model:Union[None, str]=None):
"""Initialize the chat log

Args:
msg (Union[List[Dict], None, str], optional): chat log. Defaults to None.
api_key (Union[None, str], optional): API key. Defaults to None.
chat_url (Union[None, str], optional): base url. Defaults to None. Example: "https://api.openai.com/v1/chat/completions"
model (Union[None, str], optional): model to use. Defaults to None.

Raises:
ValueError: msg should be a list of dict, a string or None
Expand All @@ -35,7 +37,7 @@ def __init__( self
raise ValueError("msg should be a list of dict, a string or None")
self._api_key = openai_api_call.api_key if api_key is None else api_key
self._chat_url = chat_url
self._model = 'gpt-3.5-turbo'
self._model = 'gpt-3.5-turbo' if model is None else model

def prompt_token(self, model:str="gpt-3.5-turbo-0613"):
"""Get the prompt token for the model
Expand Down Expand Up @@ -234,4 +236,5 @@ def __eq__(self, chat: object) -> bool:

def __getitem__(self, index):
"""Get the message at index"""
return self._chat_log[index]
return self._chat_log[index]

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 = '1.1.0'
VERSION = '1.1.1'

requirements = [
'Click>=7.0', 'requests>=2.20',
Expand Down
Loading