[Feature] Calculate max_out_len without hard code for OpenAI model (#158)

* calulate max_out_len without hard code

* set default value

* update configs

* Update configs/eval_gpt3.5.py

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>

---------

Co-authored-by: Tong Gao <gaotongxiao@gmail.com>
This commit is contained in:
Zaida Zhou 2023-08-08 15:16:56 +08:00 committed by GitHub
parent 2f1949e7a1
commit af436f5951
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -24,7 +24,7 @@ models = [
key='ENV', # The key will be obtained from $OPENAI_API_KEY, but you can write down your key here as well key='ENV', # The key will be obtained from $OPENAI_API_KEY, but you can write down your key here as well
meta_template=api_meta_template, meta_template=api_meta_template,
query_per_second=1, query_per_second=1,
max_out_len=2048, max_seq_len=2048, batch_size=8), max_out_len=2048, max_seq_len=4096, batch_size=8),
] ]
infer = dict( infer = dict(

View File

@ -50,8 +50,8 @@ class OpenAI(BaseAPIModel):
is_api: bool = True is_api: bool = True
def __init__(self, def __init__(self,
path: str, path: str = 'gpt-3.5-turbo',
max_seq_len: int = 2048, max_seq_len: int = 4096,
query_per_second: int = 1, query_per_second: int = 1,
retry: int = 2, retry: int = 2,
key: Union[str, List[str]] = 'ENV', key: Union[str, List[str]] = 'ENV',
@ -146,7 +146,9 @@ class OpenAI(BaseAPIModel):
messages.append(msg) messages.append(msg)
# max num token for gpt-3.5-turbo is 4097 # max num token for gpt-3.5-turbo is 4097
max_out_len = min(max_out_len, 4000 - self.get_token_len(str(input))) max_out_len = min(
max_out_len,
self.max_seq_len - 50 - self.get_token_len(str(input)))
if max_out_len <= 0: if max_out_len <= 0:
return '' return ''