refactor llm

This commit is contained in:
bridge
2025-12-20 22:13:26 +08:00
parent e8489fcc25
commit 162ea8efe2
12 changed files with 122 additions and 422 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
from typing import TYPE_CHECKING, List, Tuple, Optional
import asyncio
from src.classes.relation import (
Relation,
@@ -18,8 +19,6 @@ from src.utils.config import CONFIG
if TYPE_CHECKING:
from src.classes.avatar import Avatar
from src.utils.ai_batch import AITaskBatch
class RelationResolver:
TEMPLATE_PATH = CONFIG.paths.templates / "relation_update.txt"
@@ -137,25 +136,10 @@ class RelationResolver:
"""
if not pairs:
return []
events = []
# 使用 asyncio.gather 而不是 AITaskBatch.gather因为 AITaskBatch 没有 gather 方法
import asyncio
tasks = []
for a, b in pairs:
# 创建协程任务但不立即 await
tasks.append(RelationResolver.resolve_pair(a, b))
if not tasks:
return []
# 并发执行所有任务
tasks = [RelationResolver.resolve_pair(a, b) for a, b in pairs]
results = await asyncio.gather(*tasks)
# 收集结果
for res in results:
if res and isinstance(res, Event):
events.append(res)
return events
# 过滤掉 None 结果 (resolve_pair 失败或无变化时返回 None)
return [res for res in results if res]