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):
|
class OpenAISDK(OpenAI):
|
||||||
|
|
||||||
def __init__(
|
def __init__(self,
|
||||||
self,
|
path: str = 'gpt-3.5-turbo',
|
||||||
path: str = 'gpt-3.5-turbo',
|
max_seq_len: int = 16384,
|
||||||
max_seq_len: int = 16384,
|
query_per_second: int = 1,
|
||||||
query_per_second: int = 1,
|
rpm_verbose: bool = False,
|
||||||
rpm_verbose: bool = False,
|
retry: int = 2,
|
||||||
retry: int = 2,
|
key: str | List[str] = 'ENV',
|
||||||
key: str | List[str] = 'ENV',
|
org: str | List[str] | None = None,
|
||||||
org: str | List[str] | None = None,
|
meta_template: Dict | None = None,
|
||||||
meta_template: Dict | None = None,
|
openai_api_base: str | List[str] = OPENAISDK_API_BASE,
|
||||||
openai_api_base: str | List[str] = OPENAISDK_API_BASE,
|
openai_proxy_url: Optional[str] = None,
|
||||||
openai_proxy_url: Optional[str] = None,
|
mode: str = 'none',
|
||||||
mode: str = 'none',
|
logprobs: bool | None = False,
|
||||||
logprobs: bool | None = False,
|
top_logprobs: int | None = None,
|
||||||
top_logprobs: int | None = None,
|
temperature: float | None = None,
|
||||||
temperature: float | None = None,
|
tokenizer_path: str | None = None,
|
||||||
tokenizer_path: str | None = None,
|
extra_body: Dict | None = None,
|
||||||
extra_body: Dict | None = None,
|
verbose: bool = False,
|
||||||
verbose: bool = False,
|
http_client_cfg: dict = {},
|
||||||
status_code_mappings: dict = {},
|
status_code_mappings: dict = {},
|
||||||
think_tag: str = '</think>',
|
think_tag: str = '</think>'):
|
||||||
):
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
path,
|
path,
|
||||||
max_seq_len,
|
max_seq_len,
|
||||||
@ -605,20 +604,20 @@ class OpenAISDK(OpenAI):
|
|||||||
else:
|
else:
|
||||||
self.openai_api_base = openai_api_base
|
self.openai_api_base = openai_api_base
|
||||||
|
|
||||||
if self.proxy_url is None:
|
if self.proxy_url or http_client_cfg:
|
||||||
self.openai_client = OpenAI(base_url=self.openai_api_base,
|
if self.proxy_url:
|
||||||
api_key=key)
|
http_client_cfg['proxies'] = {
|
||||||
else:
|
'http://': self.proxy_url,
|
||||||
proxies = {
|
'https://': self.proxy_url,
|
||||||
'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:
|
if self.verbose:
|
||||||
self.logger.info(f'Used openai_client: {self.openai_client}')
|
self.logger.info(f'Used openai_client: {self.openai_client}')
|
||||||
self.status_code_mappings = status_code_mappings
|
self.status_code_mappings = status_code_mappings
|
||||||
@ -679,6 +678,7 @@ class OpenAISDK(OpenAI):
|
|||||||
try:
|
try:
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
self.logger.info('Start calling OpenAI API')
|
self.logger.info('Start calling OpenAI API')
|
||||||
|
|
||||||
responses = self.openai_client.chat.completions.create(
|
responses = self.openai_client.chat.completions.create(
|
||||||
**query_data, timeout=timeout) # timeout in seconds
|
**query_data, timeout=timeout) # timeout in seconds
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
@ -689,7 +689,6 @@ class OpenAISDK(OpenAI):
|
|||||||
self.logger.info(responses)
|
self.logger.info(responses)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass # noqa F841
|
pass # noqa F841
|
||||||
|
|
||||||
# Check if response is empty or content is empty
|
# Check if response is empty or content is empty
|
||||||
if (not responses.choices or not responses.choices[0].message
|
if (not responses.choices or not responses.choices[0].message
|
||||||
or
|
or
|
||||||
|
Loading…
Reference in New Issue
Block a user