sensenova
Module Contents
Classes
Model wrapper around SenseTime's models. |
Attributes
- lagent.llms.sensenova.SENSENOVA_API_BASE = 'https://api.sensenova.cn/v1/llm/chat-completions'
- lagent.llms.sensenova.sensechat_models
- class lagent.llms.sensenova.SensenovaAPI(model_type='SenseChat-5-Cantonese', retry=2, json_mode=False, key='ENV', meta_template=[dict(role='system', api_role='system'), dict(role='user', api_role='user'), dict(role='assistant', api_role='assistant'), dict(role='environment', api_role='system')], sensenova_api_base=SENSENOVA_API_BASE, proxies=None, **gen_params)
Bases:
lagent.llms.base_api.BaseAPILLMModel wrapper around SenseTime’s models.
- 参数:
model_type (str) – The name of SenseTime’s model.
retry (int) – Number of retires if the API call fails. Defaults to 2.
key (str or List[str]) – SenseTime key(s). In particular, when it is set to “ENV”, the key will be fetched from the environment variable $SENSENOVA_API_KEY. If it’s a list, the keys will be used in round-robin manner. Defaults to ‘ENV’.
meta_template (Dict, optional) – The model’s meta prompt template if needed, in case the requirement of injecting or wrapping of any meta instructions.
sensenova_api_base (str) – The base url of SenseTime’s API. Defaults to ‘https://api.sensenova.cn/v1/llm/chat-completions’.
gen_params – Default generation configuration which could be overridden on the fly of generation.
json_mode (bool) –
proxies (Optional[Dict]) –
- is_api: bool = True
- logger
- invalid_keys
- key_ctr = 0
- url = 'https://api.sensenova.cn/v1/llm/chat-completions'
- model_type = 'SenseChat-5-Cantonese'
- proxies = None
- json_mode = False
- chat(inputs, **gen_params)
Generate responses given the contexts.
- 参数:
inputs (Union[List[dict], List[List[dict]]]) – a list of messages or list of lists of messages
gen_params – additional generation configuration
- 返回:
generated string(s)
- 返回类型:
Union[str, List[str]]
- stream_chat(inputs, **gen_params)
Generate responses given the contexts.
- 参数:
inputs (List[dict]) – a list of messages
gen_params – additional generation configuration
- 生成器:
Tuple[ModelStatusCode, str, Optional[str]] – Status code, generated string, and optional metadata
- 返回类型:
Generator[Tuple[lagent.schema.ModelStatusCode, str, Optional[str]], None, None]
- generate_request_data(model_type, messages, gen_params, json_mode=False)
Generates the request data for different model types.
- 参数:
model_type (str) – The type of the model (e.g., ‘sense’).
messages (list) – The list of messages to be sent to the model.
gen_params (dict) – The generation parameters.
json_mode (bool) – Flag to determine if the response format should be JSON.
- 返回:
A tuple containing the header and the request data.
- 返回类型:
tuple
- tokenize(prompt)
Tokenize the input prompt.
- 参数:
prompt (str) – Input string.
- 返回:
token ids
- 返回类型:
list