Skip to content

Commit

Permalink
update chatlog initialize method
Browse files Browse the repository at this point in the history
  • Loading branch information
RexWzh committed Sep 14, 2023
1 parent 72d44fa commit 99632d6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ Example 3, process data in batch (asynchronous), print hello using different lan
from openai_api_call import async_chat_completion, load_chats

langs = ["python", "java", "Julia", "C++"]
chatlogs = [
[{"role":"user", "content":"print hello using %s" % lang}]
for lang in langs]
chatlogs = ["print hello using %s" % lang for lang in langs]
async_chat_completion(chatlogs, chkpoint="async_chat.jsonl", ncoroutines=2)
chats = load_chats("async_chat.jsonl")
```
Expand All @@ -98,7 +96,7 @@ This package is licensed under the MIT license. See the LICENSE file for more de

## update log

Current version `1.0.0` is a stable version, with the redundant feature `function call` removed, and the asynchronous data processing tool added.
Current version `1.0.0` is a stable version, with the redundant feature `function call` removed, and the asynchronous processing tool added.

### Beta version
- Since version `0.2.0`, `Chat` type is used to handle data
Expand Down
4 changes: 1 addition & 3 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ continue_chats = process_chats(msgs, msg2chat, checkpoint)
from openai_api_call import async_chat_completion, load_chats

langs = ["python", "java", "Julia", "C++"]
chatlogs = [
[{"role":"user", "content":"print hello using %s" % lang}]
for lang in langs]
chatlogs = ["print hello using %s" % lang for lang in langs]
async_chat_completion(chatlogs, chkpoint="async_chat.jsonl", ncoroutines=2)
chats = load_chats("async_chat.jsonl")
```
Expand Down
2 changes: 1 addition & 1 deletion openai_api_call/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """Rex Wang"""
__email__ = '[email protected]'
__version__ = '1.3.0'
__version__ = '1.3.1'

import os, sys, requests
from .chattool import Chat, Resp
Expand Down
8 changes: 6 additions & 2 deletions openai_api_call/asynctool.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def chat_complete(ind, locker, chatlog, chkpoint, **options):
responses = await asyncio.gather(*tasks)
return responses

def async_chat_completion( chatlogs:List[List[Dict]]
def async_chat_completion( chatlogs:Union[List[List[Dict]], str]
, chkpoint:str
, model:str='gpt-3.5-turbo'
, api_key:Union[str, None]=None
Expand All @@ -135,7 +135,7 @@ def async_chat_completion( chatlogs:List[List[Dict]]
"""Asynchronous chat completion
Args:
chatlogs (List[List[Dict]]): list of chat logs
chatlogs (Union[List[List[Dict]], str]): list of chat logs or chat message
chkpoint (str): checkpoint file
model (str, optional): model to use. Defaults to 'gpt-3.5-turbo'.
api_key (Union[str, None], optional): API key. Defaults to None.
Expand All @@ -144,10 +144,14 @@ def async_chat_completion( chatlogs:List[List[Dict]]
timeout (int, optional): timeout for the API call. Defaults to 0(no timeout).
timeinterval (int, optional): time interval between two API calls. Defaults to 0.
clearfile (bool, optional): whether to clear the checkpoint file. Defaults to False.
notrun (bool, optional): whether to run the async process. It should be True
when use in Jupyter Notebook. Defaults to False.
Returns:
List[Dict]: list of responses
"""
# read chatlogs | use method from the Chat object
chatlogs = [Chat(log).chat_log for log in chatlogs]
if clearfile and os.path.exists(chkpoint):
os.remove(chkpoint)
if api_key is None:
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 = '1.3.0'
VERSION = '1.3.1'

requirements = [
'Click>=7.0', 'requests>=2.20', "responses>=0.23",
Expand Down

0 comments on commit 99632d6

Please sign in to comment.