agentscope.models.model module
The model wrapper base class.
- class ModelWrapperBase(config_name: str | None = None, model_name: str | None = None, **kwargs: Any)[source]
Bases:
object
The base class for model wrapper.
- format(*args: Msg | Sequence[Msg]) List[dict] | str [source]
Format the input messages into the format that the model API required.
- static format_for_common_chat_models(*args: Msg | Sequence[Msg]) List[dict] [source]
A common format strategy for chat models, which will format the input messages into a system message (if provided) and a user message.
Note this strategy maybe not suitable for all scenarios, and developers are encouraged to implement their own prompt engineering strategies.
The following is an example:
prompt1 = model.format( Msg("system", "You're a helpful assistant", role="system"), Msg("Bob", "Hi, how can I help you?", role="assistant"), Msg("user", "What's the date today?", role="user") ) prompt2 = model.format( Msg("Bob", "Hi, how can I help you?", role="assistant"), Msg("user", "What's the date today?", role="user") )
The prompt will be as follows:
# prompt1 [ { "role": "system", "content": "You're a helpful assistant" }, { "role": "user", "content": ( "## Conversation History\n" "Bob: Hi, how can I help you?\n" "user: What's the date today?" ) } ] # prompt2 [ { "role": "user", "content": ( "## Conversation History\n" "Bob: Hi, how can I help you?\n" "user: What's the date today?" ) } ]
- 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:
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
The type of the model wrapper, which is to identify the model wrapper class in model configuration.