switch_role
函数功能
切换当前LLM-DataDist的角色,建议仅在使用PagedAttention的场景使用,在开启CacheManager的情况下,不同角色功能没有限制,调用该接口直接返回,无任何作用。
函数原型
switch_role(role: LLMRole, switch_options: Optional[Dict[str, str]])
参数说明
| 参数名称 | 数据类型 | 取值说明 | 
|---|---|---|
| role | 切换的目标角色。 | |
| switch_options | options: Dict[str, str] | 切换角色配置项。 切换为Prompt时需要设置,其中需包含llm.listenIpInfo配置项。 | 
调用示例
from llm_datadist import LLMDataDist, LLMRole
llm_datadist = LLMDataDist(LLMRole.DECODER, 0)
...
switch_options = { 'llm.listenIpInfo': '127.0.0.1:26000' }
llm_datadist.switch_role(LLMRole.PROMPT, switch_options)
返回值
- 正常情况下无返回值。
- 传入数据类型错误情况下会抛出TypeError或ValueError异常。
- 如果初始化LLMDataDist时LLMConfig未使能enable_switch_role,调用该接口则会抛出LLMException,status_code为LLM_FEATURE_NOT_ENABLED。
- 如果switch_role时存在残留链路资源,则会抛出LLMException,status_code为LLM_EXIST_LINK。
- 如果switch_role的目标role与当前role相同,则会抛出LLMException,status_code为LLM_PARAM_INVALID。
约束说明
无。
父主题: LLMDataDist