Skip to content

Commit f255bc1

Browse files
committed
♻️ 移除之前的无用函数
1 parent 282725a commit f255bc1

File tree

1 file changed

+0
-128
lines changed

1 file changed

+0
-128
lines changed

src/nonebot_plugin_nyaturingtest/session.py

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -932,134 +932,6 @@ def __chat_stage(
932932
except json.JSONDecodeError:
933933
raise ValueError("LLM response is not valid JSON, response: " + response)
934934

935-
def __emotion_feedback(self, knowledges: list[str], long_term_memory: list[str], llm: Callable[[str], str]):
936-
if len(self.last_response) == 0:
937-
return
938-
history = json.dumps(
939-
[
940-
{
941-
"user_name": msg.user_name,
942-
"content": msg.content,
943-
}
944-
for msg in self.global_memory.access()
945-
],
946-
ensure_ascii=False,
947-
indent=2,
948-
)
949-
prompt = f"""
950-
你是QQ群用户 {self.__name}(你称自己为 "{
951-
self.__name
952-
}"),正在回顾刚刚自己在群里的发言,以客观视角分析“你的最新情绪”,并输出新的 VAD 值。
953-
954-
---
955-
956-
## 1. 任务目标
957-
- 基于“上次发言”的内容和“历史聊天”的背景,评估你当前的情绪变化。
958-
- 情绪采用 VAD 模型,三个维度取值范围:
959-
- valence (愉悦度):[-1.0, 1.0]
960-
- arousal (唤醒度):[0.0, 1.0]
961-
- dominance (支配度):[-1.0, 1.0]
962-
963-
---
964-
965-
## 2. 输入信息
966-
967-
1. **历史聊天(仅供参考,无需打分)**
968-
```json
969-
{history}
970-
````
971-
972-
2. **之前的情绪状态**
973-
974-
```json
975-
{json.dumps(self.global_emotion.__dict__, ensure_ascii=False, indent=2)}
976-
```
977-
978-
3. 🧠 从记忆中联想到的过去聊天内容(不一定准确):
979-
980-
```
981-
{long_term_memory}
982-
```
983-
984-
4. 📚 从记忆中联想到的相关知识(知识库中明确定义的内容):
985-
986-
```
987-
{knowledges}
988-
```
989-
990-
5. **上次你发送的消息(需分析此部分)**
991-
992-
```json
993-
{
994-
json.dumps(
995-
[{"user_name": msg.user_name, "content": msg.content} for msg in self.last_response],
996-
ensure_ascii=False,
997-
indent=2,
998-
)
999-
}
1000-
```
1001-
1002-
---
1003-
1004-
## 3. 输出格式
1005-
1006-
* **只输出**下面的 JSON,不要任何额外文字、注释或格式标记:
1007-
1008-
```json
1009-
{{
1010-
"new_emotion": {{
1011-
"valence": 0.0≤float≤1.0,
1012-
"arousal": 0.0≤float≤1.0,
1013-
"dominance": -1.0≤float≤1.0
1014-
}}
1015-
}}
1016-
```
1017-
1018-
> 例如:
1019-
>
1020-
> ```json
1021-
> {{
1022-
> "new_emotion": {{
1023-
> "valence": 0.5,
1024-
> "arousal": 0.3,
1025-
> "dominance": -0.2
1026-
> }}
1027-
> }}
1028-
> ```
1029-
1030-
---
1031-
1032-
## 4. 行为说明
1033-
1034-
* **仅分析上次自己发的那条消息对情绪的即时影响**,不需要对历史消息打分。
1035-
* 若上次发言让你感到正向刺激,valence ↑;若遭遇质疑或负面反馈,valence ↓。
1036-
* 若上次内容引发紧张或兴奋,arousal ↑;若较平淡或无感,arousal 接近 0。
1037-
* 若上次发言让你感到更受控制,dominance ↑;若失去掌控感,dominance ↓。
1038-
1039-
---
1040-
1041-
请严格遵守以上说明,输出符合格式的纯 JSON,不要添加任何额外的文字或解释。
1042-
"""
1043-
score_response = llm(prompt)
1044-
logger.debug(f"LLM reply response: {score_response}")
1045-
score_response = re.sub(r"^```json\s*|\s*```$", "", score_response)
1046-
try:
1047-
score_response_dict: dict[str, dict] = json.loads(score_response)
1048-
except json.JSONDecodeError:
1049-
raise ValueError("LLM response is not valid JSON, response: " + score_response)
1050-
if "new_emotion" not in score_response:
1051-
raise ValueError("LLM response is not valid JSON, response: " + score_response)
1052-
if "valence" not in score_response_dict["new_emotion"]:
1053-
raise ValueError("LLM response is not valid JSON, response: " + score_response)
1054-
if "arousal" not in score_response_dict["new_emotion"]:
1055-
raise ValueError("LLM response is not valid JSON, response: " + score_response)
1056-
if "dominance" not in score_response_dict["new_emotion"]:
1057-
raise ValueError("LLM response is not valid JSON, response: " + score_response)
1058-
1059-
self.global_emotion.valence = score_response_dict["new_emotion"]["valence"]
1060-
self.global_emotion.arousal = score_response_dict["new_emotion"]["arousal"]
1061-
self.global_emotion.dominance = score_response_dict["new_emotion"]["dominance"]
1062-
1063935
def update(self, messages_chunk: list[Message], llm: Callable[[str], str]) -> list[str] | None:
1064936
"""
1065937
更新群聊消息

0 commit comments

Comments
 (0)