引入二级大纲功能,新增父子节点关系及子节点排序,同时调整API与UI以支持嵌套大纲管理

This commit is contained in:
2026-03-22 16:53:33 +08:00
parent 20c759150a
commit 098ff4e16d
33 changed files with 2516 additions and 381 deletions

View File

@@ -103,6 +103,65 @@ def build_tool_results_messages(
]
async def simple_completion(
config: AIConfig,
messages: list[dict],
system_prompt: str = "",
) -> str:
"""非流式调用,返回完整文本。用于摘要压缩等场景。"""
if config.provider == "anthropic":
return await _simple_anthropic(config, messages, system_prompt)
return await _simple_openai(config, messages, system_prompt)
async def _simple_openai(config: AIConfig, messages: list[dict], system_prompt: str) -> str:
url = f"{config.base_url.rstrip('/')}/chat/completions"
payload_messages = []
if system_prompt:
payload_messages.append({"role": "system", "content": system_prompt})
payload_messages.extend(messages)
body = {"model": config.model, "messages": payload_messages, "stream": False}
async with httpx.AsyncClient(timeout=120) as client:
resp = await client.post(
url,
headers={"Authorization": f"Bearer {config.api_key}", "Content-Type": "application/json"},
json=body,
)
resp.raise_for_status()
data = resp.json()
return data["choices"][0]["message"]["content"] or ""
async def _simple_anthropic(config: AIConfig, messages: list[dict], system_prompt: str) -> str:
url = f"{config.base_url.rstrip('/')}/messages"
body: dict = {
"model": config.model,
"max_tokens": 4096,
"messages": messages,
"stream": False,
}
if system_prompt:
body["system"] = system_prompt
async with httpx.AsyncClient(timeout=120) as client:
resp = await client.post(
url,
headers={
"x-api-key": config.api_key,
"anthropic-version": "2023-06-01",
"Content-Type": "application/json",
},
json=body,
)
resp.raise_for_status()
data = resp.json()
for block in data.get("content", []):
if block.get("type") == "text":
return block["text"]
return ""
# ── OpenAI 兼容 ──