agentscope.models.post_model

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 | list[Msg] | None, multi_agent_mode: bool = True) 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, list[Msg], None]) – The input arguments to be formatted, where each argument should be a Msg object, or a list of Msg objects. The None input will be ignored.

  • multi_agent_mode (bool, defaults to True) – Formatting the messages in multi-agent mode or not. If false, the messages will be formatted in chat mode, where only a user and an assistant roles are involved.

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

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

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.