agentscope.models.post_model module
Model wrapper for post-based inference apis.
- class PostAPIChatWrapper(config_name: str, api_url: str, model_name: str | None = None, headers: dict | None = None, max_length: int = 2048, timeout: int = 30, json_args: dict | None = None, post_args: dict | None = None, max_retries: int = 3, messages_key: str = 'messages', retry_interval: int = 1, **kwargs: Any)[source]
Bases:
PostAPIModelWrapperBase
A post api model wrapper compatible with openai chat, e.g., vLLM, FastChat.
- format(*args: Msg | Sequence[Msg]) List[dict] [source]
Format the input messages into a list of dict according to the model name. For example, if the model name is prefixed with “gpt-”, the input messages will be formatted for OpenAI models.
- Parameters:
args (Union[Msg, Sequence[Msg]]) – The input arguments to be formatted, where each argument should be a Msg object, or a list of Msg objects. In distribution, placeholder is also allowed.
- Returns:
The formatted messages.
- Return type:
Union[List[dict]]
- config_name: str
The name of the model configuration.
- model_name: str
The name of the model, which is used in model api calling.
- model_type: str = 'post_api_chat'
The type of the model wrapper, which is to identify the model wrapper class in model configuration.
- class PostAPIDALLEWrapper(config_name: str, api_url: str, model_name: str | None = None, headers: dict | None = None, max_length: int = 2048, timeout: int = 30, json_args: dict | None = None, post_args: dict | None = None, max_retries: int = 3, messages_key: str = 'messages', retry_interval: int = 1, **kwargs: Any)[source]
Bases:
PostAPIModelWrapperBase
A post api model wrapper compatible with openai dall_e
- format(*args: Msg | Sequence[Msg]) List[dict] | str [source]
Format the input messages into the format that the model API required.
- model_type: str = 'post_api_dall_e'
The type of the model wrapper, which is to identify the model wrapper class in model configuration.
- class PostAPIEmbeddingWrapper(config_name: str, api_url: str, model_name: str | None = None, headers: dict | None = None, max_length: int = 2048, timeout: int = 30, json_args: dict | None = None, post_args: dict | None = None, max_retries: int = 3, messages_key: str = 'messages', retry_interval: int = 1, **kwargs: Any)[source]
Bases:
PostAPIModelWrapperBase
A post api model wrapper for embedding model
- format(*args: Msg | Sequence[Msg]) List[dict] | str [source]
Format the input messages into the format that the model API required.
- model_type: str = 'post_api_embedding'
The type of the model wrapper, which is to identify the model wrapper class in model configuration.
- class PostAPIModelWrapperBase(config_name: str, api_url: str, model_name: str | None = None, headers: dict | None = None, max_length: int = 2048, timeout: int = 30, json_args: dict | None = None, post_args: dict | None = None, max_retries: int = 3, messages_key: str = 'messages', retry_interval: int = 1, **kwargs: Any)[source]
Bases:
ModelWrapperBase
,ABC
The base model wrapper for the model deployed on the POST API.
- config_name: str
The name of the model configuration.
- model_name: str
The name of the model, which is used in model api calling.
- model_type: str
The type of the model wrapper, which is to identify the model wrapper class in model configuration.