MCPcopy Create free account
hub / github.com/InternScience/SciReason / OpenAI

Class OpenAI

opencompass/models/openai_api.py:32–559  ·  view source on GitHub ↗

Model wrapper around OpenAI's models. Args: path (str): The name of OpenAI's model. max_seq_len (int): The maximum allowed sequence length of a model. Note that the length of prompt + generated tokens shall not exceed this value. Defaults to 2048.

Source from the content-addressed store, hash-verified

30
31@MODELS.register_module()
32class OpenAI(BaseAPIModel):
33 """Model wrapper around OpenAI's models.
34
35 Args:
36 path (str): The name of OpenAI's model.
37 max_seq_len (int): The maximum allowed sequence length of a model.
38 Note that the length of prompt + generated tokens shall not exceed
39 this value. Defaults to 2048.
40 query_per_second (int): The maximum queries allowed per second
41 between two consecutive calls of the API. Defaults to 1.
42 retry (int): Number of retires if the API call fails. Defaults to 2.
43 key (str or List[str]): OpenAI key(s). In particular, when it
44 is set to "ENV", the key will be fetched from the environment
45 variable $OPENAI_API_KEY, as how openai defaults to be. If it's a
46 list, the keys will be used in round-robin manner. Defaults to
47 'ENV'.
48 org (str or List[str], optional): OpenAI organization(s). If not
49 specified, OpenAI uses the default organization bound to each API
50 key. If specified, the orgs will be posted with each request in
51 round-robin manner. Defaults to None.
52 meta_template (Dict, optional): The model's meta prompt
53 template if needed, in case the requirement of injecting or
54 wrapping of any meta instructions.
55 openai_api_base (str): The base url of OpenAI's API. Defaults to
56 'https://api.openai.com/v1/chat/completions'.
57 openai_proxy_url (str, optional): An optional proxy url to use when
58 connecting to OpenAI's API. When set to 'ENV', the url will be
59 fetched from the environment variable $OPENAI_PROXY_URL.
60 Defaults to None.
61 mode (str, optional): The method of input truncation when input length
62 exceeds max_seq_len. 'front','mid' and 'rear' represents the part
63 of input to truncate. Defaults to 'none'.
64 temperature (float, optional): What sampling temperature to use.
65 If not None, will override the temperature in the `generate()`
66 call. Defaults to None.
67 tokenizer_path (str, optional): The path to the tokenizer. Use path if
68 'tokenizer_path' is None, otherwise use the 'tokenizer_path'.
69 Defaults to None.
70 extra_body (Dict, optional): Add additional JSON properties to
71 the request
72 think_tag (str, optional): The tag to use for reasoning content.
73 Defaults to '</think>'.
74 """
75
76 is_api: bool = True
77
78 def __init__(
79 self,
80 path: str = 'gpt-3.5-turbo',
81 max_seq_len: int = 16384,
82 query_per_second: int = 1,
83 rpm_verbose: bool = False,
84 retry: int = 2,
85 key: Union[str, List[str]] = 'ENV',
86 org: Optional[Union[str, List[str]]] = None,
87 meta_template: Optional[Dict] = None,
88 openai_api_base: str = OPENAI_API_BASE,
89 openai_proxy_url: Optional[str] = None,

Callers 4

__init__Method · 0.90
__init__Method · 0.90
run_judge_pairMethod · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected