anthropic_llm
Module Contents
Classes
Base class for API model wrapper. |
|
Base class for API model wrapper. |
- class lagent.llms.anthropic_llm.ClaudeAPI(model_type='claude-3-5-sonnet-20241022', retry=5, key='ENV', proxies=None, 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='user')], temperature=NOT_GIVEN, max_new_tokens=512, top_p=NOT_GIVEN, top_k=NOT_GIVEN, repetition_penalty=0.0, stop_words=None)
Bases:
lagent.llms.base_api.BaseAPILLMBase class for API model wrapper.
- 参数:
model_type (str) – The type of model.
retry (int) – Number of retires if the API call fails. Defaults to 2.
meta_template (Dict, optional) – The model’s meta prompt template if needed, in case the requirement of injecting or wrapping of any meta instructions.
key (Union[str, List[str]]) –
proxies (Optional[Dict]) –
temperature (float) –
max_new_tokens (int) –
top_p (float) –
top_k (int) –
repetition_penalty (float) –
stop_words (Union[List[str], str]) –
- is_api: bool = True
- clients
- invalid_keys
- key_ctr = 0
- model_type = 'claude-3-5-sonnet-20241022'
- proxies = None
- chat(inputs, session_ids=None, **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
session_ids (Union[int, List[int]]) –
- 返回:
generated string(s)
- 返回类型:
Union[str, List[str]]
- generate_request_data(model_type, messages, gen_params)
Generates the request data for different model types.
- 参数:
model_type (str) – The type of the model (e.g., ‘gpt’, ‘internlm’, ‘qwen’).
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
- class lagent.llms.anthropic_llm.AsyncClaudeAPI(model_type='claude-3-5-sonnet-20241022', retry=5, key='ENV', proxies=None, 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='user')], temperature=NOT_GIVEN, max_new_tokens=512, top_p=NOT_GIVEN, top_k=NOT_GIVEN, repetition_penalty=0.0, stop_words=None)
Bases:
lagent.llms.base_api.AsyncBaseAPILLMBase class for API model wrapper.
- 参数:
model_type (str) – The type of model.
retry (int) – Number of retires if the API call fails. Defaults to 2.
meta_template (Dict, optional) – The model’s meta prompt template if needed, in case the requirement of injecting or wrapping of any meta instructions.
key (Union[str, List[str]]) –
proxies (Optional[Dict]) –
temperature (float) –
max_new_tokens (int) –
top_p (float) –
top_k (int) –
repetition_penalty (float) –
stop_words (Union[List[str], str]) –
- is_api: bool = True
- clients
- invalid_keys
- key_ctr = 0
- model_type = 'claude-3-5-sonnet-20241022'
- proxies = None
- async chat(inputs, session_ids=None, **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
session_ids (Union[int, List[int]]) –
- 返回:
generated string(s)
- 返回类型:
Union[str, List[str]]
- generate_request_data(model_type, messages, gen_params)
Generates the request data for different model types.
- 参数:
model_type (str) – The type of the model (e.g., ‘gpt’, ‘internlm’, ‘qwen’).
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