mirror of
https://github.com/open-compass/opencompass.git
synced 2025-05-30 16:03:24 +08:00
Update
This commit is contained in:
parent
57e98f30bb
commit
8fc6343119
@ -556,28 +556,27 @@ class OpenAI(BaseAPIModel):
|
||||
|
||||
class OpenAISDK(OpenAI):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
path: str = 'gpt-3.5-turbo',
|
||||
max_seq_len: int = 16384,
|
||||
query_per_second: int = 1,
|
||||
rpm_verbose: bool = False,
|
||||
retry: int = 2,
|
||||
key: str | List[str] = 'ENV',
|
||||
org: str | List[str] | None = None,
|
||||
meta_template: Dict | None = None,
|
||||
openai_api_base: str | List[str] = OPENAISDK_API_BASE,
|
||||
openai_proxy_url: Optional[str] = None,
|
||||
mode: str = 'none',
|
||||
logprobs: bool | None = False,
|
||||
top_logprobs: int | None = None,
|
||||
temperature: float | None = None,
|
||||
tokenizer_path: str | None = None,
|
||||
extra_body: Dict | None = None,
|
||||
verbose: bool = False,
|
||||
status_code_mappings: dict = {},
|
||||
think_tag: str = '</think>',
|
||||
):
|
||||
def __init__(self,
|
||||
path: str = 'gpt-3.5-turbo',
|
||||
max_seq_len: int = 16384,
|
||||
query_per_second: int = 1,
|
||||
rpm_verbose: bool = False,
|
||||
retry: int = 2,
|
||||
key: str | List[str] = 'ENV',
|
||||
org: str | List[str] | None = None,
|
||||
meta_template: Dict | None = None,
|
||||
openai_api_base: str | List[str] = OPENAISDK_API_BASE,
|
||||
openai_proxy_url: Optional[str] = None,
|
||||
mode: str = 'none',
|
||||
logprobs: bool | None = False,
|
||||
top_logprobs: int | None = None,
|
||||
temperature: float | None = None,
|
||||
tokenizer_path: str | None = None,
|
||||
extra_body: Dict | None = None,
|
||||
verbose: bool = False,
|
||||
http_client_cfg: dict = {},
|
||||
status_code_mappings: dict = {},
|
||||
think_tag: str = '</think>'):
|
||||
super().__init__(
|
||||
path,
|
||||
max_seq_len,
|
||||
@ -605,20 +604,20 @@ class OpenAISDK(OpenAI):
|
||||
else:
|
||||
self.openai_api_base = openai_api_base
|
||||
|
||||
if self.proxy_url is None:
|
||||
self.openai_client = OpenAI(base_url=self.openai_api_base,
|
||||
api_key=key)
|
||||
else:
|
||||
proxies = {
|
||||
'http://': self.proxy_url,
|
||||
'https://': self.proxy_url,
|
||||
}
|
||||
if self.proxy_url or http_client_cfg:
|
||||
if self.proxy_url:
|
||||
http_client_cfg['proxies'] = {
|
||||
'http://': self.proxy_url,
|
||||
'https://': self.proxy_url,
|
||||
}
|
||||
|
||||
self.openai_client = OpenAI(
|
||||
base_url=self.openai_api_base,
|
||||
api_key=key,
|
||||
http_client=httpx.Client(
|
||||
**http_client_cfg) if http_client_cfg else None,
|
||||
)
|
||||
|
||||
self.openai_client = OpenAI(
|
||||
base_url=self.openai_api_base,
|
||||
api_key=key,
|
||||
http_client=httpx.Client(proxies=proxies),
|
||||
)
|
||||
if self.verbose:
|
||||
self.logger.info(f'Used openai_client: {self.openai_client}')
|
||||
self.status_code_mappings = status_code_mappings
|
||||
@ -679,6 +678,7 @@ class OpenAISDK(OpenAI):
|
||||
try:
|
||||
if self.verbose:
|
||||
self.logger.info('Start calling OpenAI API')
|
||||
|
||||
responses = self.openai_client.chat.completions.create(
|
||||
**query_data, timeout=timeout) # timeout in seconds
|
||||
if self.verbose:
|
||||
@ -689,7 +689,6 @@ class OpenAISDK(OpenAI):
|
||||
self.logger.info(responses)
|
||||
except Exception:
|
||||
pass # noqa F841
|
||||
|
||||
# Check if response is empty or content is empty
|
||||
if (not responses.choices or not responses.choices[0].message
|
||||
or
|
||||
|
Loading…
Reference in New Issue
Block a user