Files
HaHafeng 1ece9a4ae8 feat(asl): Add DeepSearch smart literature retrieval MVP
Features:
- Integrate unifuncs DeepSearch API (OpenAI compatible protocol)
- SSE real-time streaming for AI thinking process display
- Natural language input, auto-generate PubMed search strategy
- Extract and display PubMed literature links
- Database storage for task records (asl_research_tasks)

Backend:
- researchService.ts - Core business logic with SSE streaming
- researchController.ts - SSE stream endpoint
- researchWorker.ts - Async task worker (backup mode)
- schema.prisma - AslResearchTask model

Frontend:
- ResearchSearch.tsx - Search page with unified content stream
- ResearchSearch.css - Styling (unifuncs-inspired simple design)
- ASLLayout.tsx - Enable menu item
- api/index.ts - Add research API functions

API Endpoints:
- POST /api/v1/asl/research/stream - SSE streaming search
- POST /api/v1/asl/research/tasks - Async task creation
- GET /api/v1/asl/research/tasks/:taskId/status - Task status

Documentation:
- Development record for DeepSearch integration
- Update ASL module status (v1.5)
- Update system status (v3.7)

Known limitations:
- SSE mode, task interrupts when leaving page
- Cost ~0.3 RMB per search (unifuncs API)
2026-01-18 19:15:55 +08:00

314 lines
7.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
unifuncsAPI接入文档
两种模式:深度研究报告和深度搜索。
一、 深度研究报告模式
Model 选择请求模型。S2
API Keysk-2fNwqUH73elGq0aDKJEM4ReqP7Ry0iqHo4OXyidDe2WpQ9XQ
Introduction设定研究员的角色和口吻
Plan Approval执行研究前是否生成一份研究计划并等待用户批准或修改。默认关闭。
Reference Style指定引用文献的输出格式默认为 linkMarkDown
Max Depth研究的最大深度建议在25轮为最佳
Domain Scope自定义搜索网站限定范围内研究英文逗号分隔
Domain Blacklist搜索网站黑名单排除特定网站的内容英文逗号分隔
Output Type预期输出的文体类型默认为report
Output Prompt自定义输出提示词覆盖output_type的默认提示词。支持嵌入 {{introduction}} / {{output_length}} / {{content}} 占位符content为用户提问。
Output Length预期输出内容的长度模型不一定遵守
Stream是否流式响应
二、 深度搜索模式
[https://unifuncs.com/api\#deepsearch](https://unifuncs.com/api#deepsearch)
参数说明:
Model S2
API Key: sk-2fNwqUH73elGq0aDKJEM4ReqP7Ry0iqHo4OXyidDe2WpQ9XQ
Introduction:设定研究员的角色和口吻
Reference Style: link 和 character
指定引用文献的输出格式,默认为 link
Max Depth研究的最大深度建议在25轮为最佳
Domain Scope自定义搜索网站限定范围内研究英文逗号分隔
Domain Blacklist搜索网站黑名单排除特定网站的内容英文逗号分隔
Output Prompt自定义输出提示词覆盖output\_type的默认提示词。支持嵌入 {{introduction}} / {{output\_length}} / {{content}} 占位符content为用户提问。
Generate Summary: 是否开启异步任务完成后自动生成标题和摘要,默认关闭 (只有异步模式才有)
Stream是否流式响应只有**Open AI 兼容协议模式才有**
2种调用方式
**一、Open AI兼容协议**
适用于直接接入到支持 OpenAI 协议的客户端,如 Cherry Studio / Dify 或 OpenAI SDK等。
// Please install OpenAI SDK first: \`npm install openai\`
import OpenAI from 'openai';
const client \= new OpenAI({
baseURL: 'https://api.unifuncs.com/deepsearch/v1',
apiKey: 'sk-2fNwqUH73elGq0aDKJEM4ReqP7Ry0iqHo4OXyidDe2WpQ9XQ',
});
async function main() {
const stream \= await client.chat.completions.create({
model: 's2',
messages: \[{ role: 'user', content: 'hi' }\],
stream: true,
introduction: "你是一名医学研究专家,负责检索文献",
max\_depth: 25,
domain\_scope: \["https://pubmed.ncbi.nlm.nih.gov/"\],
domain\_blacklist: \["wanfang.com"\],
output\_prompt: "输出文献内容",
reference\_style: "link"
});
let thinking \= false;
for await (const chunk of stream) {
if (chunk.choices\[0\]?.delta?.reasoning\_content) {
if (\!thinking) {
process.stdout.write('\<think\>\\n');
thinking \= true;
}
process.stdout.write(chunk.choices\[0\]?.delta?.reasoning\_content);
} else {
if (thinking) {
process.stdout.write('\\n\</think\>\\n\\n');
thinking \= false;
}
process.stdout.write(chunk.choices\[0\]?.delta?.content || '');
}
}
}
main();
**二、 异步模式:**
####
#### **1\. 创建任务 /v1/create\_task**
提交研究需求后立即返回 task\_id后端在后台执行。
// Node 18+ has fetch built-in
const payload \= {
"model": "s2",
"messages": \[
{
"role": "user",
"content": "hi"
}
\],
"introduction": "你是一名医学研究专家,负责检索文献",
"max\_depth": 25,
"domain\_scope": \[
"https://pubmed.ncbi.nlm.nih.gov/"
\],
"domain\_blacklist": \[
"wanfang.com"
\],
"output\_prompt": "输出文献内容",
"reference\_style": "link"
};
const res \= await fetch("https://api.unifuncs.com/deepsearch/v1/create\_task", {
method: "POST",
headers: {
"Authorization": "Bearer sk-2fNwqUH73elGq0aDKJEM4ReqP7Ry0iqHo4OXyidDe2WpQ9XQ",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
console.log(await res.json());
示例响应:
{
"code": 0,
"message": "OK",
"data": {
"task\_id": "3aff2a91-7795-4b73-8dab-0593551a27a1",
"status": "pending",
"created\_at": "2025-12-09T03:52:40.771Z"
},
"requestId": "cd17faad-7310-4370-ba0c-0c2af6bc0597"
}
#### **2\. 查询任务 /v1/query\_task**
支持 GET / POST传入 task\_id 即可轮询状态;完成后会返回摘要与最终回答。
// Node 18+ has fetch built-in
const params \= new URLSearchParams({ task\_id: "3aff2a91-7795-4b73-8dab-0593551a27a1" });
const res \= await fetch("https://api.unifuncs.com/deepsearch/v1/query\_task?" \+ params.toString(), {
headers: {
"Authorization": "Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxx"
}
});
console.log(await res.json());
示例响应,已完成:
{
"code": 0,
"message": "OK",
"data": {
"task\_id": "3aff2a91-7795-4b73-8dab-0593551a27a1",
"status": "completed",
"result": {
"content": "你好我是U深搜一个专业的网络信息深度搜索专家 🤖\\n\\n我可以帮助你\\n- 🔍 精准搜索和提取关键信息\\n- 📊 进行深度分析和多源验证\\n- 🕒 获取最新、最可靠的信息\\n- 💡 提供结构化的洞察和建议\\n\\n有什么问题想要我帮你深入搜索和分析吗无论是技术资讯、市场动态、学术研究还是其他任何话题我都能为你提供专业、准确的信息服务",
"reasoning\_content": "用户只是简单地说了\\"hi\\",这是一个普通的问候。根据指导原则,如果是普通聊天或无法回答的问题,我应该使用友好的语气直接回复用户问题或介绍自己。\\n\\n这不需要进行任何搜索我应该直接友好地回复并简单介绍一下自己是U深搜这个深度搜索专家。"
},
"created\_at": "2025-12-09T03:52:40.771Z",
"updated\_at": "2025-12-09T03:52:45.912Z",
"progress": {
"current": 100,
"total": 100,
"message": "任务已完成"
},
"statistics": {
"iterations": 1,
"search\_count": 0,
"read\_count": 0,
"token\_usage": {
"prompt\_tokens": 4381,
"completion\_tokens": 167,
"total\_tokens": 4548
}
},
"session": {
"session\_id": "d3bee7f1-a44e-48b0-9283-a6866de723c3",
"status": "finished",
"model": "s2",
"title": "开启generate\_summary时生成标题",
"summary": "开启generate\_summary时生成摘要",
"question": "hi"
}
}
}