agentscope.models.yi_model module
Model wrapper for Yi models
- class YiChatWrapper(config_name: str, model_name: str, api_key: str, max_tokens: int | None = None, top_p: float = 0.9, temperature: float = 0.3, stream: bool = False)[source]
Bases:
ModelWrapperBase
The model wrapper for Yi Chat API.
- Response:
-
{ "id": "cmpl-ea89ae83", "object": "chat.completion", "created": 5785971, "model": "yi-large-rag", "usage": { "completion_tokens": 113, "prompt_tokens": 896, "total_tokens": 1009 }, "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Today in Los Angeles, the weather ...", }, "finish_reason": "stop" } ] }
- format(*args: Msg | Sequence[Msg]) List[dict] [source]
Format the messages into the required format of Yi Chat API.
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") )
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?" ) } ]
- 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 = 'yi_chat'
The type of the model wrapper, which is to identify the model wrapper class in model configuration.