fix(prompt): 修复 PromptComponentManager 的方法定义在类外部的问题
将多个本应属于 `PromptComponentManager` 的实例方法(如 `get_injections_for_prompt`, `get_rules_for_target` 等)移回正确的类定义内。 这些方法之前因缩进错误被意外地定义在了类外部,导致它们无法作为实例方法被正确调用。本次提交修正了这个问题,确保了类的封装性和方法的正确作用域。
This commit is contained in:
committed by
Windpicker-owo
parent
8412014d68
commit
4e1cac5b3f
@@ -206,7 +206,7 @@ class PromptComponentManager:
|
|||||||
injection_map[target] = info_list
|
injection_map[target] = info_list
|
||||||
return injection_map
|
return injection_map
|
||||||
|
|
||||||
async def get_injections_for_prompt(self, target_prompt_name: str) -> list[dict]:
|
async def get_injections_for_prompt(self, target_prompt_name: str) -> list[dict]:
|
||||||
"""获取指定核心提示词模板的所有注入信息(增强版,包含更多细节)。"""
|
"""获取指定核心提示词模板的所有注入信息(增强版,包含更多细节)。"""
|
||||||
rules_for_target = self._dynamic_rules.get(target_prompt_name, {})
|
rules_for_target = self._dynamic_rules.get(target_prompt_name, {})
|
||||||
if not rules_for_target:
|
if not rules_for_target:
|
||||||
@@ -226,7 +226,7 @@ async def get_injections_for_prompt(self, target_prompt_name: str) -> list[dict]
|
|||||||
info_list.sort(key=lambda x: x["priority"])
|
info_list.sort(key=lambda x: x["priority"])
|
||||||
return info_list
|
return info_list
|
||||||
|
|
||||||
def get_all_dynamic_rules(self) -> dict[str, dict[str, "InjectionRule"]]:
|
def get_all_dynamic_rules(self) -> dict[str, dict[str, "InjectionRule"]]:
|
||||||
"""获取所有当前的动态注入规则,以 InjectionRule 对象形式返回。"""
|
"""获取所有当前的动态注入规则,以 InjectionRule 对象形式返回。"""
|
||||||
rules_copy = {}
|
rules_copy = {}
|
||||||
# 只返回规则对象,隐藏 provider 实现细节
|
# 只返回规则对象,隐藏 provider 实现细节
|
||||||
@@ -237,7 +237,7 @@ def get_all_dynamic_rules(self) -> dict[str, dict[str, "InjectionRule"]]:
|
|||||||
rules_copy[target] = target_copy
|
rules_copy[target] = target_copy
|
||||||
return copy.deepcopy(rules_copy)
|
return copy.deepcopy(rules_copy)
|
||||||
|
|
||||||
def get_rules_for_target(self, target_prompt: str) -> dict[str, InjectionRule]:
|
def get_rules_for_target(self, target_prompt: str) -> dict[str, InjectionRule]:
|
||||||
"""
|
"""
|
||||||
获取所有注入到指定核心提示词的动态规则。
|
获取所有注入到指定核心提示词的动态规则。
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ def get_rules_for_target(self, target_prompt: str) -> dict[str, InjectionRule]:
|
|||||||
target_rules = self._dynamic_rules.get(target_prompt, {})
|
target_rules = self._dynamic_rules.get(target_prompt, {})
|
||||||
return {name: copy.deepcopy(rule_info[0]) for name, rule_info in target_rules.items()}
|
return {name: copy.deepcopy(rule_info[0]) for name, rule_info in target_rules.items()}
|
||||||
|
|
||||||
def get_rules_by_component(self, component_name: str) -> dict[str, InjectionRule]:
|
def get_rules_by_component(self, component_name: str) -> dict[str, InjectionRule]:
|
||||||
"""
|
"""
|
||||||
获取由指定的单个注入组件定义的所有动态规则。
|
获取由指定的单个注入组件定义的所有动态规则。
|
||||||
|
|
||||||
@@ -291,9 +291,9 @@ def get_rules_by_component(self, component_name: str) -> dict[str, InjectionRule
|
|||||||
found_rules[target] = copy.deepcopy(rule_info[0])
|
found_rules[target] = copy.deepcopy(rule_info[0])
|
||||||
return found_rules
|
return found_rules
|
||||||
|
|
||||||
async def preview_prompt_injections(
|
async def preview_prompt_injections(
|
||||||
self, target_prompt_name: str, params: PromptParameters
|
self, target_prompt_name: str, params: PromptParameters
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
【预览功能】模拟应用所有注入规则,返回最终生成的模板字符串,而不实际修改任何状态。
|
【预览功能】模拟应用所有注入规则,返回最终生成的模板字符串,而不实际修改任何状态。
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user