feat: 初始化 OnceLove GraphRAG 项目基础架构
- 添加完整的项目结构,包括前端(Vue3 + Vite)、后端(Fastify)和基础设施配置 - 实现核心 GraphRAG 服务,集成 Neo4j 图数据库和 Qdrant 向量数据库 - 添加用户认证系统和管理员登录界面 - 提供 Docker 容器化部署方案和开发环境配置 - 包含项目文档、API 文档(Swagger)和测试脚本
This commit is contained in:
62
.gitignore
vendored
Normal file
62
.gitignore
vendored
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# 环境变量(保护敏感信息)
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
.env.development
|
||||||
|
.env.test
|
||||||
|
.env.production
|
||||||
|
|
||||||
|
MiroFish
|
||||||
|
|
||||||
|
# Python
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
*.so
|
||||||
|
.Python
|
||||||
|
.venv/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
.eggs/
|
||||||
|
*.egg-info/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Node.js
|
||||||
|
node_modules/
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# 测试
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
htmlcov/
|
||||||
|
|
||||||
|
# Cursor
|
||||||
|
.cursor/
|
||||||
|
.claude/
|
||||||
|
|
||||||
|
# 文档与测试程序
|
||||||
|
mydoc/
|
||||||
|
mytest/
|
||||||
|
|
||||||
|
# 日志文件
|
||||||
|
backend/logs/
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# 上传文件
|
||||||
|
backend/uploads/
|
||||||
|
|
||||||
|
# Docker 数据
|
||||||
|
data/
|
||||||
117
OnceLove/README.md
Normal file
117
OnceLove/README.md
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
|
||||||
|
## 开发规范
|
||||||
|
|
||||||
|
### 项目结构规范
|
||||||
|
|
||||||
|
project /
|
||||||
|
├── src / 程序源码文件目录
|
||||||
|
│ ├── config / 配置目录
|
||||||
|
│ │ ├── swagger.js swagger 配置文件
|
||||||
|
│ │ └── logger.js 日志配置文件
|
||||||
|
│ │
|
||||||
|
│ ├── controllers / 控制器目录
|
||||||
|
│ │ ├── *.controller.js 控制器文件
|
||||||
|
│ │ └── index.js 控制器索引文件
|
||||||
|
│ │
|
||||||
|
│ ├── models / 模型目录
|
||||||
|
│ │ ├── *.model.js 模型文件
|
||||||
|
│ │ └── index.js 模型索引文件
|
||||||
|
│ │
|
||||||
|
│ ├── routes / 路由目录
|
||||||
|
│ │ ├── *.route.js 路由文件
|
||||||
|
│ │ └── index.js 路由索引文件
|
||||||
|
│ │
|
||||||
|
│ ├── services / 服务目录
|
||||||
|
│ │ ├── *.service.js 服务文件
|
||||||
|
│ │ └── index.js 服务索引文件
|
||||||
|
│ └── server.js 服务器入口文件
|
||||||
|
│
|
||||||
|
├── docs / 用于存储AI提示文档
|
||||||
|
│ └── *.md 文档文件
|
||||||
|
│
|
||||||
|
├── .env 环境变量配置文件
|
||||||
|
├── package.json 项目依赖配置文件
|
||||||
|
├── .gitignore git 忽略文件配置
|
||||||
|
├── package-lock.json 项目依赖锁文件
|
||||||
|
└── README.md 项目说明文档
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### controllers、models、routes 规范
|
||||||
|
|
||||||
|
- 每个目录下的文件都要符合命名规范
|
||||||
|
- 控制器文件:`*.controller.js`
|
||||||
|
- 模型文件:`*.model.js`
|
||||||
|
- 路由文件:`*.route.js`
|
||||||
|
|
||||||
|
并统一由index.js导出:
|
||||||
|
|
||||||
|
- controllers/index.js
|
||||||
|
- models/index.js
|
||||||
|
- routes/index.js
|
||||||
|
|
||||||
|
### swagger 规范
|
||||||
|
|
||||||
|
- 每个路由文件都要包含路由的详细信息,包括请求方法、路径、参数、响应等。
|
||||||
|
- 路由文件的注释要符合 swagger 规范,使用 jsdoc 格式。
|
||||||
|
- 每个模型文件都要包含模型的详细信息,包括属性、类型、是否必填等。
|
||||||
|
- 模型文件的注释要符合 swagger 规范,使用 jsdoc 格式。
|
||||||
|
|
||||||
|
### 运行与脚本
|
||||||
|
|
||||||
|
- 开发启动:`npm run dev`
|
||||||
|
- 普通启动:`npm run start`
|
||||||
|
- 文档入口:`/api-docs`
|
||||||
|
|
||||||
|
### 环境变量规范
|
||||||
|
|
||||||
|
- 使用 `dotenv` 加载 `.env`(入口:`src/server.js`)
|
||||||
|
- 变量约定:
|
||||||
|
- `PORT`:服务监听端口,默认 `3000`
|
||||||
|
- `APPLICATION_URL`:对外服务基址,用于 Swagger `servers`(未设置回退为 `http://localhost:${PORT}`)
|
||||||
|
- `LOG_LEVEL`:日志级别,默认 `info`(可选 `error|warn|info|debug`)
|
||||||
|
- 安全要求:不记录/提交敏感信息,`.gitignore` 已忽略 `.env` 与 `logs/`
|
||||||
|
|
||||||
|
### 日志规范
|
||||||
|
|
||||||
|
- 日志库:`winston`(配置:`src/config/logger.js`)
|
||||||
|
- 级别:`error`、`warn`、`info`、`debug`
|
||||||
|
- 输出:
|
||||||
|
- 控制台(彩色,便于开发)
|
||||||
|
- 文件:`logs/app.log`(综合)、`logs/error.log`(错误)
|
||||||
|
- 请求日志:在 `src/server.js` 统一中间件记录 `method path status 耗时`,错误 `>=500` 记 `error`,`>=400` 记 `warn`
|
||||||
|
- 全局错误处理:`src/server.js` 捕获未处理异常并输出结构化错误,响应 `500`
|
||||||
|
- 规范:避免日志中出现令牌、密钥、密码等敏感信息
|
||||||
|
|
||||||
|
### swagger-jsdoc 配置与注释规范
|
||||||
|
|
||||||
|
- 配置位置:`src/config/swagger.js`(`createSwaggerSpec(serverUrl)`)
|
||||||
|
- 扫描范围:`apis: ['src/**/*.js']`
|
||||||
|
- 路由注释:放在 `src/routes/*.route.js`,使用 `@openapi` JSDoc 块定义路径、方法、请求参数与响应
|
||||||
|
- 模型注释:可使用 `components/schemas` 定义结构体并在路由注释中引用
|
||||||
|
- 文档 UI:`swagger-ui-express` 挂载于 `/api-docs`
|
||||||
|
|
||||||
|
### 分层规范
|
||||||
|
|
||||||
|
- 路由(`routes`)只负责参数解析与转发,不直接书写异步业务逻辑
|
||||||
|
- 控制器(`controllers`)承载业务流程编排,必要时调用 `services`
|
||||||
|
- 服务(`services`)聚合外部 API、内部模块调用,保持可测试性
|
||||||
|
- 模型(`models`)声明数据结构(如后续有数据库或 DTO 定义)
|
||||||
|
- 统一导出:各层使用 `index.js` 聚合导出,便于维护与扫描
|
||||||
|
|
||||||
|
### 参考实现
|
||||||
|
|
||||||
|
- 路由聚合:`src/routes/index.js`
|
||||||
|
- 根路由与注释:`src/routes/root.route.js`
|
||||||
|
- 控制器:`src/controllers/root.controller.js`
|
||||||
|
- Swagger 配置:`src/config/swagger.js`
|
||||||
|
- 日志配置:`src/config/logger.js`
|
||||||
|
- 入口挂载:`src/server.js`
|
||||||
|
|
||||||
|
### 异步编程规范
|
||||||
|
- 所有异步操作都要使用 `async/await` 或 `Promise` 处理,避免回调地狱
|
||||||
|
- 控制器中调用服务时,要确保服务返回 `Promise`,并在控制器中 `await` 其结果
|
||||||
|
- 服务中调用外部 API 或数据库操作时,要确保返回 `Promise`,并在服务中 `await` 其结果
|
||||||
|
- 路由中处理异步操作时,要确保捕获异常并返回结构化错误响应
|
||||||
|
- 必须使用try...catch捕获异步操作中的异常,避免未处理异常导致服务崩溃
|
||||||
4
OnceLove/oncelove-graphrag/.env.example
Normal file
4
OnceLove/oncelove-graphrag/.env.example
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
NEO4J_PASSWORD=ChangeMe_Strong_Password_123!
|
||||||
|
QDRANT_API_KEY=ChangeMe_Qdrant_Key_456!
|
||||||
|
QDRANT_COLLECTION=oncelove_chunks
|
||||||
|
EMBEDDING_DIM=1024
|
||||||
11
OnceLove/oncelove-graphrag/api/Dockerfile
Normal file
11
OnceLove/oncelove-graphrag/api/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
FROM node:20-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package.json ./
|
||||||
|
RUN npm config set registry https://registry.npmmirror.com && npm install --omit=dev --no-audit --no-fund
|
||||||
|
|
||||||
|
COPY src ./src
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
CMD ["node", "src/index.js"]
|
||||||
1777
OnceLove/oncelove-graphrag/api/package-lock.json
generated
Normal file
1777
OnceLove/oncelove-graphrag/api/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
OnceLove/oncelove-graphrag/api/package.json
Normal file
20
OnceLove/oncelove-graphrag/api/package.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "oncelove-graphrag-api",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"type": "module",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "node --watch src/index.js",
|
||||||
|
"start": "node src/index.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@fastify/cors": "^8.5.0",
|
||||||
|
"@fastify/swagger": "^8.15.0",
|
||||||
|
"@fastify/swagger-ui": "^3.1.0",
|
||||||
|
"@qdrant/js-client-rest": "1.11.0",
|
||||||
|
"dotenv": "^16.4.5",
|
||||||
|
"fastify": "^4.28.1",
|
||||||
|
"neo4j-driver": "^5.24.0",
|
||||||
|
"swagger-jsdoc": "^6.2.8"
|
||||||
|
}
|
||||||
|
}
|
||||||
26
OnceLove/oncelove-graphrag/api/src/config/clients.js
Normal file
26
OnceLove/oncelove-graphrag/api/src/config/clients.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import neo4j from "neo4j-driver";
|
||||||
|
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||||
|
|
||||||
|
let neo4jDriver;
|
||||||
|
let qdrantClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化并缓存数据库客户端,避免重复创建连接对象。
|
||||||
|
*/
|
||||||
|
export const createClients = (env) => {
|
||||||
|
if (!neo4jDriver) {
|
||||||
|
neo4jDriver = neo4j.driver(
|
||||||
|
env.NEO4J_URI,
|
||||||
|
neo4j.auth.basic(env.NEO4J_USER, env.NEO4J_PASSWORD)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!qdrantClient) {
|
||||||
|
qdrantClient = new QdrantClient({
|
||||||
|
url: env.QDRANT_URL,
|
||||||
|
apiKey: env.QDRANT_API_KEY
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { neo4jDriver, qdrantClient };
|
||||||
|
};
|
||||||
30
OnceLove/oncelove-graphrag/api/src/config/env.js
Normal file
30
OnceLove/oncelove-graphrag/api/src/config/env.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import dotenv from "dotenv";
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一读取并导出运行时环境变量,供配置层与服务层复用。
|
||||||
|
*/
|
||||||
|
export const env = {
|
||||||
|
NODE_ENV: process.env.NODE_ENV ?? "production", // 运行环境,默认生产
|
||||||
|
PORT: Number(process.env.PORT ?? 3000), // 监听端口,默认 3000
|
||||||
|
APPLICATION_URL: process.env.APPLICATION_URL ?? `http://localhost:${Number(process.env.PORT ?? 3000)}`,
|
||||||
|
WEBUI_URL: process.env.WEBUI_URL ?? "http://localhost:8080",
|
||||||
|
NEO4J_URI: process.env.NEO4J_URI, // Neo4j 连接 URI
|
||||||
|
NEO4J_USER: process.env.NEO4J_USER, // Neo4j 用户名
|
||||||
|
NEO4J_PASSWORD: process.env.NEO4J_PASSWORD, // Neo4j 密码
|
||||||
|
QDRANT_URL: process.env.QDRANT_URL, // Qdrant 连接 URL
|
||||||
|
QDRANT_API_KEY: process.env.QDRANT_API_KEY, // Qdrant API 密钥
|
||||||
|
QDRANT_COLLECTION: process.env.QDRANT_COLLECTION ?? "oncelove_chunks", // Qdrant 集合名称,默认 oncelove_chunks
|
||||||
|
EMBEDDING_DIM: Number(process.env.EMBEDDING_DIM ?? 1024), // 嵌入向量维度,默认 1024
|
||||||
|
EMBEDDING_BASE_URL: process.env.EMBEDDING_BASE_URL ?? "",
|
||||||
|
EMBEDDING_API_KEY: process.env.EMBEDDING_API_KEY ?? "",
|
||||||
|
EMBEDDING_MODEL: process.env.EMBEDDING_MODEL ?? "",
|
||||||
|
RERANK_BASE_URL: process.env.RERANK_BASE_URL ?? "",
|
||||||
|
RERANK_API_KEY: process.env.RERANK_API_KEY ?? "",
|
||||||
|
RERANK_MODEL: process.env.RERANK_MODEL ?? "",
|
||||||
|
LLM_BASE_URL: process.env.LLM_BASE_URL ?? "",
|
||||||
|
LLM_API_KEY: process.env.LLM_API_KEY ?? "",
|
||||||
|
LLM_MODEL_NAME: process.env.LLM_MODEL_NAME ?? "",
|
||||||
|
ADMIN_PASSWORD: process.env.ADMIN_PASSWORD ?? "oncelove123"
|
||||||
|
};
|
||||||
18
OnceLove/oncelove-graphrag/api/src/config/swagger.js
Normal file
18
OnceLove/oncelove-graphrag/api/src/config/swagger.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import swaggerJsdoc from "swagger-jsdoc";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于路由注释生成 OpenAPI 规范。
|
||||||
|
*/
|
||||||
|
export const createSwaggerSpec = (env) =>
|
||||||
|
swaggerJsdoc({
|
||||||
|
definition: {
|
||||||
|
openapi: "3.0.3",
|
||||||
|
info: {
|
||||||
|
title: "OnceLove GraphRAG API",
|
||||||
|
version: "0.1.0",
|
||||||
|
description: "时序 GraphRAG 服务接口文档"
|
||||||
|
},
|
||||||
|
servers: [{ url: env.APPLICATION_URL }]
|
||||||
|
},
|
||||||
|
apis: ["src/routes/*.js"]
|
||||||
|
});
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* 统一服务层异常处理并输出标准响应结构。
|
||||||
|
*/
|
||||||
|
const sendServiceResult = async (reply, action) => {
|
||||||
|
try {
|
||||||
|
const data = await action();
|
||||||
|
return reply.send(data);
|
||||||
|
} catch (error) {
|
||||||
|
const statusCode = Number(error?.statusCode) || 500;
|
||||||
|
return reply.code(statusCode).send({
|
||||||
|
ok: false,
|
||||||
|
error: error?.message ?? "internal error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GraphRAG 控制器:负责请求转发与响应封装。
|
||||||
|
*/
|
||||||
|
export const createGraphRagController = (service) => ({
|
||||||
|
health: async (_request, reply) => reply.send({ ok: true }),
|
||||||
|
ready: async (_request, reply) => sendServiceResult(reply, () => service.ready()),
|
||||||
|
bootstrap: async (_request, reply) => sendServiceResult(reply, () => service.bootstrap()),
|
||||||
|
getGraphStats: async (_request, reply) => sendServiceResult(reply, () => service.getGraphStats()),
|
||||||
|
ingest: async (request, reply) => sendServiceResult(reply, () => service.ingest(request.body)),
|
||||||
|
queryTimeline: async (request, reply) =>
|
||||||
|
sendServiceResult(reply, () => service.queryTimeline(request.body)),
|
||||||
|
queryGraphRag: async (request, reply) =>
|
||||||
|
sendServiceResult(reply, () => service.queryGraphRag(request.body)),
|
||||||
|
analyzeAndIngest: async (request, reply) =>
|
||||||
|
sendServiceResult(reply, () => service.analyzeAndIngest(request.body.text))
|
||||||
|
});
|
||||||
1
OnceLove/oncelove-graphrag/api/src/controllers/index.js
Normal file
1
OnceLove/oncelove-graphrag/api/src/controllers/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { createGraphRagController } from "./graphrag.controller.js";
|
||||||
16
OnceLove/oncelove-graphrag/api/src/index.js
Normal file
16
OnceLove/oncelove-graphrag/api/src/index.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用启动入口。
|
||||||
|
*/
|
||||||
|
const start = async () => {
|
||||||
|
const { app, env } = await createServer();
|
||||||
|
try {
|
||||||
|
await app.listen({ port: env.PORT, host: "0.0.0.0" });
|
||||||
|
} catch (error) {
|
||||||
|
app.log.error(error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
start();
|
||||||
32
OnceLove/oncelove-graphrag/api/src/routes/auth.route.js
Normal file
32
OnceLove/oncelove-graphrag/api/src/routes/auth.route.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
export const registerAuthRoutes = async (app, env) => {
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /auth/verify:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - Auth
|
||||||
|
* summary: 验证管理员密码
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* password:
|
||||||
|
* type: string
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 验证成功
|
||||||
|
* 401:
|
||||||
|
* description: 密码错误
|
||||||
|
*/
|
||||||
|
app.post("/auth/verify", async (request, reply) => {
|
||||||
|
const { password } = request.body ?? {};
|
||||||
|
if (!password || password !== env.ADMIN_PASSWORD) {
|
||||||
|
reply.code(401).send({ ok: false, message: "密码错误或未提供" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
reply.send({ ok: true, message: "验证成功" });
|
||||||
|
});
|
||||||
|
};
|
||||||
248
OnceLove/oncelove-graphrag/api/src/routes/graphrag.route.js
Normal file
248
OnceLove/oncelove-graphrag/api/src/routes/graphrag.route.js
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
/**
|
||||||
|
* 注册 GraphRAG 相关 HTTP 路由。
|
||||||
|
*/
|
||||||
|
export const registerGraphRagRoutes = async (app, controller) => {
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /health:
|
||||||
|
* get:
|
||||||
|
* tags:
|
||||||
|
* - System
|
||||||
|
* summary: 存活检查
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 服务存活
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* ok:
|
||||||
|
* type: boolean
|
||||||
|
* example: true
|
||||||
|
*/
|
||||||
|
app.get("/health", controller.health);
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /ready:
|
||||||
|
* get:
|
||||||
|
* tags:
|
||||||
|
* - System
|
||||||
|
* summary: 就绪检查(Neo4j + Qdrant)
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 服务已就绪
|
||||||
|
* 500:
|
||||||
|
* description: 服务未就绪
|
||||||
|
*/
|
||||||
|
app.get("/ready", controller.ready);
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /bootstrap:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - System
|
||||||
|
* summary: 初始化约束与向量集合
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 初始化成功
|
||||||
|
*/
|
||||||
|
app.post("/bootstrap", controller.bootstrap);
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /graph/stats:
|
||||||
|
* get:
|
||||||
|
* tags:
|
||||||
|
* - GraphRAG
|
||||||
|
* summary: 获取图谱统计数据(nodes + links)供 D3.js 可视化
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 图谱统计数据
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* ok:
|
||||||
|
* type: boolean
|
||||||
|
* nodes:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* id:
|
||||||
|
* type: string
|
||||||
|
* name:
|
||||||
|
* type: string
|
||||||
|
* type:
|
||||||
|
* type: string
|
||||||
|
* occurred_at:
|
||||||
|
* type: string
|
||||||
|
* links:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* source:
|
||||||
|
* type: string
|
||||||
|
* target:
|
||||||
|
* type: string
|
||||||
|
* type:
|
||||||
|
* type: string
|
||||||
|
* total:
|
||||||
|
* type: integer
|
||||||
|
*/
|
||||||
|
app.get("/graph/stats", controller.getGraphStats);
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /ingest:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - GraphRAG
|
||||||
|
* summary: 写入人物、事件与向量数据(支持自动 embedding)
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* persons:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* id:
|
||||||
|
* type: string
|
||||||
|
* name:
|
||||||
|
* type: string
|
||||||
|
* events:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* id:
|
||||||
|
* type: string
|
||||||
|
* type:
|
||||||
|
* type: string
|
||||||
|
* summary:
|
||||||
|
* type: string
|
||||||
|
* occurred_at:
|
||||||
|
* type: string
|
||||||
|
* format: date-time
|
||||||
|
* participants:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* type: string
|
||||||
|
* topics:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* type: string
|
||||||
|
* chunks:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* id:
|
||||||
|
* type: string
|
||||||
|
* text:
|
||||||
|
* type: string
|
||||||
|
* description: 当未提供 vector 时,将使用 text 通过第三方 embedding 自动生成
|
||||||
|
* vector:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* type: number
|
||||||
|
* payload:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* event_id:
|
||||||
|
* type: string
|
||||||
|
* occurred_at:
|
||||||
|
* type: string
|
||||||
|
* format: date-time
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 入库成功
|
||||||
|
* 400:
|
||||||
|
* description: 参数错误
|
||||||
|
*/
|
||||||
|
app.post("/ingest", controller.ingest);
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /query/timeline:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - GraphRAG
|
||||||
|
* summary: 按双方人物查询时序事件链
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* required:
|
||||||
|
* - a_id
|
||||||
|
* - b_id
|
||||||
|
* properties:
|
||||||
|
* a_id:
|
||||||
|
* type: string
|
||||||
|
* b_id:
|
||||||
|
* type: string
|
||||||
|
* start:
|
||||||
|
* type: string
|
||||||
|
* format: date-time
|
||||||
|
* end:
|
||||||
|
* type: string
|
||||||
|
* format: date-time
|
||||||
|
* limit:
|
||||||
|
* type: integer
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 查询成功
|
||||||
|
* 400:
|
||||||
|
* description: 参数错误
|
||||||
|
*/
|
||||||
|
app.post("/query/timeline", controller.queryTimeline);
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /query/graphrag:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - GraphRAG
|
||||||
|
* summary: 向量召回 + 图谱时序上下文检索(支持 query_text 自动向量化)
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* query_vector:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* type: number
|
||||||
|
* query_text:
|
||||||
|
* type: string
|
||||||
|
* a_id:
|
||||||
|
* type: string
|
||||||
|
* b_id:
|
||||||
|
* type: string
|
||||||
|
* start:
|
||||||
|
* type: string
|
||||||
|
* format: date-time
|
||||||
|
* end:
|
||||||
|
* type: string
|
||||||
|
* format: date-time
|
||||||
|
* top_k:
|
||||||
|
* type: integer
|
||||||
|
* timeline_limit:
|
||||||
|
* type: integer
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 查询成功
|
||||||
|
* 400:
|
||||||
|
* description: 参数错误
|
||||||
|
*/
|
||||||
|
app.post("/query/graphrag", controller.queryGraphRag);
|
||||||
|
app.post("/analyze", controller.analyzeAndIngest);
|
||||||
|
};
|
||||||
10
OnceLove/oncelove-graphrag/api/src/routes/index.js
Normal file
10
OnceLove/oncelove-graphrag/api/src/routes/index.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { registerGraphRagRoutes } from "./graphrag.route.js";
|
||||||
|
import { registerAuthRoutes } from "./auth.route.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一注册全部路由模块。
|
||||||
|
*/
|
||||||
|
export const registerRoutes = async (app, controller, env) => {
|
||||||
|
await registerGraphRagRoutes(app, controller);
|
||||||
|
await registerAuthRoutes(app, env);
|
||||||
|
};
|
||||||
54
OnceLove/oncelove-graphrag/api/src/server.js
Normal file
54
OnceLove/oncelove-graphrag/api/src/server.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import Fastify from "fastify";
|
||||||
|
import cors from "@fastify/cors";
|
||||||
|
import swagger from "@fastify/swagger";
|
||||||
|
import swaggerUi from "@fastify/swagger-ui";
|
||||||
|
import { env } from "./config/env.js";
|
||||||
|
import { createClients } from "./config/clients.js";
|
||||||
|
import { createSwaggerSpec } from "./config/swagger.js";
|
||||||
|
import { EmbeddingService, RerankService, GraphRagService, LLMService } from "./services/index.js";
|
||||||
|
import { createGraphRagController } from "./controllers/index.js";
|
||||||
|
import { registerRoutes } from "./routes/index.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建 Fastify 应用并完成依赖装配与路由注册。
|
||||||
|
*/
|
||||||
|
export const createServer = async () => {
|
||||||
|
const app = Fastify({ logger: true });
|
||||||
|
|
||||||
|
await app.register(cors, {
|
||||||
|
origin: [env.WEBUI_URL, "http://localhost:8080", "http://127.0.0.1:8080", "http://localhost:5174", "http://127.0.0.1:5174", "http://localhost:5173", "http://127.0.0.1:5173"],
|
||||||
|
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
||||||
|
allowedHeaders: ["Content-Type", "Authorization"]
|
||||||
|
});
|
||||||
|
|
||||||
|
await app.register(swagger, {
|
||||||
|
mode: "static",
|
||||||
|
specification: {
|
||||||
|
document: createSwaggerSpec(env)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await app.register(swaggerUi, {
|
||||||
|
routePrefix: "/api-docs"
|
||||||
|
});
|
||||||
|
const { neo4jDriver, qdrantClient } = createClients(env);
|
||||||
|
const embeddingService = new EmbeddingService(env);
|
||||||
|
const rerankService = new RerankService(env);
|
||||||
|
const llmService = new LLMService(env);
|
||||||
|
const service = new GraphRagService({
|
||||||
|
driver: neo4jDriver,
|
||||||
|
qdrantClient,
|
||||||
|
embeddingService,
|
||||||
|
rerankService,
|
||||||
|
llmService,
|
||||||
|
env
|
||||||
|
});
|
||||||
|
const controller = createGraphRagController(service);
|
||||||
|
|
||||||
|
await registerRoutes(app, controller, env);
|
||||||
|
|
||||||
|
app.addHook("onClose", async () => {
|
||||||
|
await neo4jDriver.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
return { app, env };
|
||||||
|
};
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
const createHttpError = (statusCode, message) => {
|
||||||
|
const error = new Error(message);
|
||||||
|
error.statusCode = statusCode;
|
||||||
|
return error;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class EmbeddingService {
|
||||||
|
constructor(env) {
|
||||||
|
this.baseUrl = (env.EMBEDDING_BASE_URL ?? "").replace(/\/+$/, "");
|
||||||
|
this.apiKey = env.EMBEDDING_API_KEY ?? "";
|
||||||
|
this.model = env.EMBEDDING_MODEL ?? "";
|
||||||
|
this.dimension = env.EMBEDDING_DIM;
|
||||||
|
}
|
||||||
|
|
||||||
|
isEnabled() {
|
||||||
|
return Boolean(this.baseUrl && this.apiKey && this.model);
|
||||||
|
}
|
||||||
|
|
||||||
|
async embed(text) {
|
||||||
|
if (!this.isEnabled()) {
|
||||||
|
throw createHttpError(400, "embedding 服务未配置,请提供 EMBEDDING_BASE_URL/EMBEDDING_API_KEY/EMBEDDING_MODEL");
|
||||||
|
}
|
||||||
|
|
||||||
|
const cleaned = typeof text === "string" ? text.trim() : "";
|
||||||
|
if (!cleaned) {
|
||||||
|
throw createHttpError(400, "embedding 输入文本不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`${this.baseUrl}/v1/embeddings`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${this.apiKey}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: this.model,
|
||||||
|
input: cleaned
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw createHttpError(response.status, `embedding 请求失败: ${errorText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
const vector = data?.data?.[0]?.embedding;
|
||||||
|
if (!Array.isArray(vector) || vector.length !== this.dimension) {
|
||||||
|
throw createHttpError(400, `embedding 维度异常,期望 ${this.dimension}`);
|
||||||
|
}
|
||||||
|
return vector;
|
||||||
|
}
|
||||||
|
}
|
||||||
589
OnceLove/oncelove-graphrag/api/src/services/graphrag.service.js
Normal file
589
OnceLove/oncelove-graphrag/api/src/services/graphrag.service.js
Normal file
@@ -0,0 +1,589 @@
|
|||||||
|
import neo4j from "neo4j-driver";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 ISO 时间转换为秒级时间戳,用于 Qdrant 的范围过滤。
|
||||||
|
*/
|
||||||
|
const toTimestamp = (value) => {
|
||||||
|
if (!value) return null;
|
||||||
|
const ms = Date.parse(value);
|
||||||
|
if (Number.isNaN(ms)) return null;
|
||||||
|
return Math.floor(ms / 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
const normalizeOccurredAt = (value) => {
|
||||||
|
if (typeof value !== "string" || !value.trim()) {
|
||||||
|
return new Date().toISOString();
|
||||||
|
}
|
||||||
|
const ms = Date.parse(value);
|
||||||
|
if (Number.isNaN(ms)) {
|
||||||
|
return new Date().toISOString();
|
||||||
|
}
|
||||||
|
return new Date(ms).toISOString();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一 Neo4j 结果结构,避免控制器层处理图数据库 Record 细节。
|
||||||
|
*/
|
||||||
|
const toEventDto = (record) => ({
|
||||||
|
id: record.get("id"),
|
||||||
|
type: record.get("type"),
|
||||||
|
summary: record.get("summary"),
|
||||||
|
occurred_at: record.get("occurred_at"),
|
||||||
|
importance: record.get("importance"),
|
||||||
|
topics: record.get("topics") ?? [],
|
||||||
|
participants: record.get("participants") ?? []
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造标准业务错误,便于控制器返回统一 HTTP 状态码。
|
||||||
|
*/
|
||||||
|
const createHttpError = (statusCode, message) => {
|
||||||
|
const error = new Error(message);
|
||||||
|
error.statusCode = statusCode;
|
||||||
|
return error;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验 /ingest 入参与向量维度。
|
||||||
|
*/
|
||||||
|
const validateIngestInput = (body, embeddingDim, canAutoEmbed) => {
|
||||||
|
const persons = Array.isArray(body.persons) ? body.persons : [];
|
||||||
|
const events = Array.isArray(body.events) ? body.events : [];
|
||||||
|
const chunks = Array.isArray(body.chunks) ? body.chunks : [];
|
||||||
|
|
||||||
|
for (const person of persons) {
|
||||||
|
if (!person?.id) {
|
||||||
|
throw createHttpError(400, "persons[].id 必填");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const event of events) {
|
||||||
|
if (!event?.id || !event?.occurred_at) {
|
||||||
|
throw createHttpError(400, "events[].id 与 events[].occurred_at 必填");
|
||||||
|
}
|
||||||
|
if (!Array.isArray(event.participants) || event.participants.length === 0) {
|
||||||
|
throw createHttpError(400, "events[].participants 至少包含 1 个人物 id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const chunk of chunks) {
|
||||||
|
if (!chunk?.id) {
|
||||||
|
throw createHttpError(400, "chunks[].id 必填");
|
||||||
|
}
|
||||||
|
const hasVector = Array.isArray(chunk?.vector);
|
||||||
|
const hasText = typeof chunk?.text === "string" && chunk.text.trim().length > 0;
|
||||||
|
if (!hasVector && !(canAutoEmbed && hasText)) {
|
||||||
|
throw createHttpError(400, "chunks[] 需提供 vector,或在配置 embedding 后提供 text");
|
||||||
|
}
|
||||||
|
if (hasVector && chunk.vector.length !== embeddingDim) {
|
||||||
|
throw createHttpError(400, `chunks[].vector 维度必须为 ${embeddingDim}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { persons, events, chunks };
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GraphRAG 核心服务:
|
||||||
|
* 1) 图谱结构写入 Neo4j;
|
||||||
|
* 2) 文本向量写入 Qdrant;
|
||||||
|
* 3) 按时序与向量联合检索上下文。
|
||||||
|
*/
|
||||||
|
export class GraphRagService {
|
||||||
|
/**
|
||||||
|
* @param {{ driver: import("neo4j-driver").Driver, qdrantClient: any, env: Record<string, any> }} deps
|
||||||
|
*/
|
||||||
|
constructor({ driver, qdrantClient, embeddingService, rerankService, llmService, env }) {
|
||||||
|
this.driver = driver;
|
||||||
|
this.qdrantClient = qdrantClient;
|
||||||
|
this.embeddingService = embeddingService;
|
||||||
|
this.rerankService = rerankService;
|
||||||
|
this.llmService = llmService;
|
||||||
|
this.collection = env.QDRANT_COLLECTION;
|
||||||
|
this.embeddingDim = env.EMBEDDING_DIM;
|
||||||
|
}
|
||||||
|
|
||||||
|
async resolveChunkVector(chunk) {
|
||||||
|
if (Array.isArray(chunk?.vector)) {
|
||||||
|
if (chunk.vector.length !== this.embeddingDim) {
|
||||||
|
throw createHttpError(400, `chunks[].vector 维度必须为 ${this.embeddingDim}`);
|
||||||
|
}
|
||||||
|
return chunk.vector;
|
||||||
|
}
|
||||||
|
if (!this.embeddingService?.isEnabled()) {
|
||||||
|
throw createHttpError(400, "未检测到可用 embedding 配置");
|
||||||
|
}
|
||||||
|
return this.embeddingService.embed(chunk.text ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
async resolveQueryVector(body) {
|
||||||
|
const queryVector = body?.query_vector;
|
||||||
|
if (Array.isArray(queryVector)) {
|
||||||
|
if (queryVector.length !== this.embeddingDim) {
|
||||||
|
throw createHttpError(400, `query_vector 维度必须为 ${this.embeddingDim}`);
|
||||||
|
}
|
||||||
|
return queryVector;
|
||||||
|
}
|
||||||
|
const queryText = typeof body?.query_text === "string" ? body.query_text.trim() : "";
|
||||||
|
if (!queryText) {
|
||||||
|
throw createHttpError(400, `query_vector 维度必须为 ${this.embeddingDim},或提供 query_text`);
|
||||||
|
}
|
||||||
|
if (!this.embeddingService?.isEnabled()) {
|
||||||
|
throw createHttpError(400, "未检测到可用 embedding 配置,无法使用 query_text 检索");
|
||||||
|
}
|
||||||
|
return this.embeddingService.embed(queryText);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接就绪检查。
|
||||||
|
*/
|
||||||
|
async ready() {
|
||||||
|
const session = this.driver.session();
|
||||||
|
try {
|
||||||
|
await session.run("RETURN 1 AS ok");
|
||||||
|
await this.qdrantClient.getCollections();
|
||||||
|
return { ok: true };
|
||||||
|
} finally {
|
||||||
|
await session.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图谱统计数据,用于前端 D3.js 可视化渲染。
|
||||||
|
* 返回 nodes(人物/事件/主题)和 links(关系边)。
|
||||||
|
*/
|
||||||
|
async getGraphStats() {
|
||||||
|
const runQuery = async (query) => {
|
||||||
|
const session = this.driver.session();
|
||||||
|
try { return await session.run(query) }
|
||||||
|
finally { await session.close() }
|
||||||
|
};
|
||||||
|
const [personResult, eventResult, topicResult, personEventResult, eventTopicResult] =
|
||||||
|
await Promise.all([
|
||||||
|
runQuery(`MATCH (p:Person) RETURN p.id AS id, p.name AS name, 'person' AS type LIMIT 200`),
|
||||||
|
runQuery(`MATCH (e:Event) RETURN e.id AS id, e.summary AS name, 'event' AS type, e.occurred_at AS occurred_at LIMIT 200`),
|
||||||
|
runQuery(`MATCH (t:Topic) RETURN t.name AS id, t.name AS name, 'topic' AS type LIMIT 100`),
|
||||||
|
runQuery(`MATCH (p:Person)-[:PARTICIPATES_IN]->(e:Event) RETURN p.id AS source, e.id AS target, 'PARTICIPATES_IN' AS type LIMIT 500`),
|
||||||
|
runQuery(`MATCH (e:Event)-[:ABOUT]->(t:Topic) RETURN e.id AS source, t.name AS target, 'ABOUT' AS type LIMIT 300`)
|
||||||
|
]);
|
||||||
|
|
||||||
|
const nodes = [];
|
||||||
|
const idSet = new Set();
|
||||||
|
|
||||||
|
const addNode = (record) => {
|
||||||
|
const id = record.get("id");
|
||||||
|
if (!id || idSet.has(id)) return;
|
||||||
|
idSet.add(id);
|
||||||
|
const occurredAt = record.keys.includes("occurred_at") ? record.get("occurred_at") : null;
|
||||||
|
nodes.push({
|
||||||
|
id,
|
||||||
|
name: record.get("name") ?? id,
|
||||||
|
type: record.get("type"),
|
||||||
|
occurred_at: occurredAt
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
personResult.records.forEach(addNode);
|
||||||
|
eventResult.records.forEach(addNode);
|
||||||
|
topicResult.records.forEach(addNode);
|
||||||
|
|
||||||
|
const links = [
|
||||||
|
...personEventResult.records.map((r) => ({
|
||||||
|
source: r.get("source"),
|
||||||
|
target: r.get("target"),
|
||||||
|
type: r.get("type")
|
||||||
|
})),
|
||||||
|
...eventTopicResult.records.map((r) => ({
|
||||||
|
source: r.get("source"),
|
||||||
|
target: r.get("target"),
|
||||||
|
type: r.get("type")
|
||||||
|
}))
|
||||||
|
];
|
||||||
|
|
||||||
|
return { ok: true, nodes, links, total: nodes.length };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化图谱约束与向量集合。
|
||||||
|
*/
|
||||||
|
async bootstrap() {
|
||||||
|
const session = this.driver.session();
|
||||||
|
try {
|
||||||
|
await session.run("CREATE CONSTRAINT person_id IF NOT EXISTS FOR (p:Person) REQUIRE p.id IS UNIQUE");
|
||||||
|
await session.run("CREATE CONSTRAINT event_id IF NOT EXISTS FOR (e:Event) REQUIRE e.id IS UNIQUE");
|
||||||
|
await session.run("CREATE CONSTRAINT topic_name IF NOT EXISTS FOR (t:Topic) REQUIRE t.name IS UNIQUE");
|
||||||
|
await session.run("CREATE INDEX event_time IF NOT EXISTS FOR (e:Event) ON (e.occurred_at)");
|
||||||
|
|
||||||
|
const collections = await this.qdrantClient.getCollections();
|
||||||
|
const exists = collections.collections?.some((item) => item.name === this.collection);
|
||||||
|
if (!exists) {
|
||||||
|
await this.qdrantClient.createCollection(this.collection, {
|
||||||
|
vectors: { size: this.embeddingDim, distance: "Cosine" }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ok: true, collection: this.collection };
|
||||||
|
} finally {
|
||||||
|
await session.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入人物、事件、主题关系,并可同步写入向量分片。
|
||||||
|
*/
|
||||||
|
async ingest(body) {
|
||||||
|
const { persons, events, chunks } = validateIngestInput(
|
||||||
|
body ?? {},
|
||||||
|
this.embeddingDim,
|
||||||
|
this.embeddingService?.isEnabled() ?? false
|
||||||
|
);
|
||||||
|
const session = this.driver.session();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await session.executeWrite(async (tx) => {
|
||||||
|
for (const person of persons) {
|
||||||
|
await tx.run(
|
||||||
|
`
|
||||||
|
MERGE (p:Person {id: $id})
|
||||||
|
SET p.name = coalesce($name, p.name),
|
||||||
|
p.updated_at = datetime()
|
||||||
|
`,
|
||||||
|
{ id: person.id, name: person.name ?? null }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const event of events) {
|
||||||
|
await tx.run(
|
||||||
|
`
|
||||||
|
MERGE (e:Event {id: $id})
|
||||||
|
SET e.type = $type,
|
||||||
|
e.summary = $summary,
|
||||||
|
e.occurred_at = datetime($occurred_at),
|
||||||
|
e.importance = $importance,
|
||||||
|
e.updated_at = datetime()
|
||||||
|
`,
|
||||||
|
{
|
||||||
|
id: event.id,
|
||||||
|
type: event.type ?? "event",
|
||||||
|
summary: event.summary ?? "",
|
||||||
|
occurred_at: event.occurred_at,
|
||||||
|
importance: event.importance ?? 0.5
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const personId of event.participants) {
|
||||||
|
await tx.run(
|
||||||
|
`
|
||||||
|
MERGE (p:Person {id: $person_id})
|
||||||
|
SET p.updated_at = datetime()
|
||||||
|
WITH p
|
||||||
|
MATCH (e:Event {id: $event_id})
|
||||||
|
MERGE (p)-[:PARTICIPATES_IN]->(e)
|
||||||
|
`,
|
||||||
|
{ person_id: personId, event_id: event.id }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const topics = Array.isArray(event.topics) ? event.topics : [];
|
||||||
|
for (const topicName of topics) {
|
||||||
|
await tx.run(
|
||||||
|
`
|
||||||
|
MERGE (t:Topic {name: $name})
|
||||||
|
WITH t
|
||||||
|
MATCH (e:Event {id: $event_id})
|
||||||
|
MERGE (e)-[:ABOUT]->(t)
|
||||||
|
`,
|
||||||
|
{ name: topicName, event_id: event.id }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (chunks.length > 0) {
|
||||||
|
const points = await Promise.all(chunks.map(async (chunk) => {
|
||||||
|
const vector = await this.resolveChunkVector(chunk);
|
||||||
|
const payload = chunk.payload ?? {};
|
||||||
|
return {
|
||||||
|
id: chunk.id,
|
||||||
|
vector,
|
||||||
|
payload: {
|
||||||
|
text: chunk.text ?? payload.text ?? "",
|
||||||
|
event_id: payload.event_id ?? null,
|
||||||
|
occurred_at: payload.occurred_at ?? null,
|
||||||
|
occurred_ts: toTimestamp(payload.occurred_at),
|
||||||
|
person_ids: Array.isArray(payload.person_ids) ? payload.person_ids : [],
|
||||||
|
source: payload.source ?? "unknown"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
|
||||||
|
await this.qdrantClient.upsert(this.collection, { points, wait: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
ingested: {
|
||||||
|
persons: persons.length,
|
||||||
|
events: events.length,
|
||||||
|
chunks: chunks.length
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
await session.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询两个人在时间窗内的时序事件链。
|
||||||
|
*/
|
||||||
|
async queryTimeline(body) {
|
||||||
|
const { a_id, b_id, start, end, limit = 100 } = body ?? {};
|
||||||
|
if (!a_id || !b_id) {
|
||||||
|
throw createHttpError(400, "a_id 和 b_id 必填");
|
||||||
|
}
|
||||||
|
|
||||||
|
const session = this.driver.session();
|
||||||
|
try {
|
||||||
|
const result = await session.run(
|
||||||
|
`
|
||||||
|
MATCH (a:Person {id: $a_id})-[:PARTICIPATES_IN]->(e:Event)<-[:PARTICIPATES_IN]-(b:Person {id: $b_id})
|
||||||
|
WHERE ($start IS NULL OR e.occurred_at >= datetime($start))
|
||||||
|
AND ($end IS NULL OR e.occurred_at <= datetime($end))
|
||||||
|
OPTIONAL MATCH (e)-[:ABOUT]->(t:Topic)
|
||||||
|
WITH e, collect(DISTINCT t.name) AS topics
|
||||||
|
OPTIONAL MATCH (p:Person)-[:PARTICIPATES_IN]->(e)
|
||||||
|
WITH e, topics, collect(DISTINCT {id: p.id, name: p.name}) AS participants
|
||||||
|
RETURN
|
||||||
|
e.id AS id,
|
||||||
|
e.type AS type,
|
||||||
|
e.summary AS summary,
|
||||||
|
toString(e.occurred_at) AS occurred_at,
|
||||||
|
e.importance AS importance,
|
||||||
|
topics AS topics,
|
||||||
|
participants AS participants
|
||||||
|
ORDER BY e.occurred_at ASC
|
||||||
|
LIMIT $limit
|
||||||
|
`,
|
||||||
|
{
|
||||||
|
a_id,
|
||||||
|
b_id,
|
||||||
|
start: start ?? null,
|
||||||
|
end: end ?? null,
|
||||||
|
limit: neo4j.int(limit)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
total: result.records.length,
|
||||||
|
timeline: result.records.map(toEventDto)
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
await session.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 先做向量召回,再回查图谱事件上下文,输出 GraphRAG 检索结果。
|
||||||
|
*/
|
||||||
|
async queryGraphRag(body) {
|
||||||
|
const {
|
||||||
|
a_id = null,
|
||||||
|
b_id = null,
|
||||||
|
start = null,
|
||||||
|
end = null,
|
||||||
|
top_k = 8,
|
||||||
|
timeline_limit = 60
|
||||||
|
} = body ?? {};
|
||||||
|
const queryVector = await this.resolveQueryVector(body ?? {});
|
||||||
|
|
||||||
|
const filterMust = [];
|
||||||
|
const startTs = toTimestamp(start);
|
||||||
|
const endTs = toTimestamp(end);
|
||||||
|
if (startTs !== null || endTs !== null) {
|
||||||
|
filterMust.push({
|
||||||
|
key: "occurred_ts",
|
||||||
|
range: {
|
||||||
|
...(startTs !== null ? { gte: startTs } : {}),
|
||||||
|
...(endTs !== null ? { lte: endTs } : {})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchResult = await this.qdrantClient.search(this.collection, {
|
||||||
|
vector: queryVector,
|
||||||
|
limit: top_k,
|
||||||
|
with_payload: true,
|
||||||
|
...(filterMust.length > 0 ? { filter: { must: filterMust } } : {})
|
||||||
|
});
|
||||||
|
|
||||||
|
let chunks = searchResult.map((item) => ({
|
||||||
|
id: item.id,
|
||||||
|
score: item.score,
|
||||||
|
text: item.payload?.text ?? "",
|
||||||
|
payload: item.payload ?? {}
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (body?.query_text && this.rerankService?.isEnabled()) {
|
||||||
|
chunks = await this.rerankService.rerank(body.query_text, chunks);
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventIds = Array.from(
|
||||||
|
new Set(
|
||||||
|
chunks
|
||||||
|
.map((item) => item.payload?.event_id)
|
||||||
|
.filter((id) => typeof id === "string" && id.length > 0)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const session = this.driver.session();
|
||||||
|
try {
|
||||||
|
const result = await session.run(
|
||||||
|
`
|
||||||
|
MATCH (e:Event)
|
||||||
|
WHERE (size($event_ids) = 0 OR e.id IN $event_ids)
|
||||||
|
AND ($start IS NULL OR e.occurred_at >= datetime($start))
|
||||||
|
AND ($end IS NULL OR e.occurred_at <= datetime($end))
|
||||||
|
AND ($a_id IS NULL OR EXISTS { MATCH (:Person {id: $a_id})-[:PARTICIPATES_IN]->(e) })
|
||||||
|
AND ($b_id IS NULL OR EXISTS { MATCH (:Person {id: $b_id})-[:PARTICIPATES_IN]->(e) })
|
||||||
|
OPTIONAL MATCH (e)-[:ABOUT]->(t:Topic)
|
||||||
|
WITH e, collect(DISTINCT t.name) AS topics
|
||||||
|
OPTIONAL MATCH (p:Person)-[:PARTICIPATES_IN]->(e)
|
||||||
|
WITH e, topics, collect(DISTINCT {id: p.id, name: p.name}) AS participants
|
||||||
|
RETURN
|
||||||
|
e.id AS id,
|
||||||
|
e.type AS type,
|
||||||
|
e.summary AS summary,
|
||||||
|
toString(e.occurred_at) AS occurred_at,
|
||||||
|
e.importance AS importance,
|
||||||
|
topics AS topics,
|
||||||
|
participants AS participants
|
||||||
|
ORDER BY e.occurred_at DESC
|
||||||
|
LIMIT $timeline_limit
|
||||||
|
`,
|
||||||
|
{
|
||||||
|
event_ids: eventIds,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
a_id,
|
||||||
|
b_id,
|
||||||
|
timeline_limit: neo4j.int(timeline_limit)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
retrieved_chunks: chunks,
|
||||||
|
timeline_context: result.records.map(toEventDto)
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
await session.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async analyzeAndIngest(text) {
|
||||||
|
if (!this.llmService?.isEnabled()) {
|
||||||
|
throw createHttpError(400, "LLM 服务未配置,请检查 LLM_BASE_URL/LLM_API_KEY/LLM_MODEL_NAME");
|
||||||
|
}
|
||||||
|
|
||||||
|
const analysis = await this.llmService.analyzeText(text);
|
||||||
|
console.log("[DEBUG] LLM analysis result:", JSON.stringify(analysis));
|
||||||
|
if (!analysis || (!analysis.persons && !analysis.events && !analysis.topics)) {
|
||||||
|
throw createHttpError(500, `LLM 返回数据异常: ${JSON.stringify(analysis)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const session = this.driver.session();
|
||||||
|
console.log("[DEBUG] Got session, driver:", !!this.driver);
|
||||||
|
try {
|
||||||
|
const deleteResult = await session.run("MATCH (n) DETACH DELETE n", {});
|
||||||
|
console.log("[DEBUG] Delete result:", deleteResult?.summary?.counters);
|
||||||
|
|
||||||
|
const personMap = {};
|
||||||
|
for (const person of (analysis.persons || [])) {
|
||||||
|
console.log("[DEBUG] Creating person:", person);
|
||||||
|
const result = await session.run(
|
||||||
|
`CREATE (p:Person {id: $id, name: $name, description: $description}) RETURN p.id AS id`,
|
||||||
|
{ id: person.id, name: person.name, description: person.description || "" }
|
||||||
|
);
|
||||||
|
console.log("[DEBUG] Person create result:", result?.records?.length);
|
||||||
|
if (result?.records?.length > 0) {
|
||||||
|
personMap[person.id] = person.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const topicMap = {};
|
||||||
|
for (const topic of (analysis.topics || [])) {
|
||||||
|
await session.run(
|
||||||
|
`CREATE (t:Topic {name: $name})`,
|
||||||
|
{ name: topic.name }
|
||||||
|
);
|
||||||
|
topicMap[topic.id] = topic.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const event of (analysis.events || [])) {
|
||||||
|
const normalizedOccurredAt = normalizeOccurredAt(event.occurred_at);
|
||||||
|
await session.run(
|
||||||
|
`CREATE (e:Event {
|
||||||
|
id: $id,
|
||||||
|
type: $type,
|
||||||
|
summary: $summary,
|
||||||
|
occurred_at: datetime($occurred_at),
|
||||||
|
importance: $importance
|
||||||
|
})`,
|
||||||
|
{
|
||||||
|
id: event.id,
|
||||||
|
type: event.type || "general",
|
||||||
|
summary: event.summary || "",
|
||||||
|
occurred_at: normalizedOccurredAt,
|
||||||
|
importance: neo4j.int(event.importance || 5)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const pid of (event.participants || [])) {
|
||||||
|
await session.run(
|
||||||
|
`MATCH (p:Person {id: $pid}), (e:Event {id: $eid})
|
||||||
|
MERGE (p)-[:PARTICIPATES_IN]->(e)`,
|
||||||
|
{ pid, eid: event.id }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const tid of (event.topics || [])) {
|
||||||
|
const topicName = topicMap[tid];
|
||||||
|
if (topicName) {
|
||||||
|
await session.run(
|
||||||
|
`MATCH (e:Event {id: $eid}), (t:Topic {name: $tname})
|
||||||
|
MERGE (e)-[:ABOUT]->(t)`,
|
||||||
|
{ eid: event.id, tname: topicName }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const rel of (analysis.relations || [])) {
|
||||||
|
const sourceName = personMap[rel.source];
|
||||||
|
const targetName = personMap[rel.target];
|
||||||
|
if (sourceName && targetName) {
|
||||||
|
await session.run(
|
||||||
|
`MATCH (s:Person {name: $sname}), (t:Person {name: $tname})
|
||||||
|
MERGE (s)-[r:${rel.type}]->(t)`,
|
||||||
|
{ sname: sourceName, tname: targetName }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
message: "分析并导入成功",
|
||||||
|
analysis,
|
||||||
|
stats: {
|
||||||
|
persons: (analysis.persons || []).length,
|
||||||
|
events: (analysis.events || []).length,
|
||||||
|
topics: (analysis.topics || []).length,
|
||||||
|
relations: (analysis.relations || []).length
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
await session.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
4
OnceLove/oncelove-graphrag/api/src/services/index.js
Normal file
4
OnceLove/oncelove-graphrag/api/src/services/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export { EmbeddingService } from "./embedding.service.js";
|
||||||
|
export { RerankService } from "./rerank.service.js";
|
||||||
|
export { GraphRagService } from "./graphrag.service.js";
|
||||||
|
export { LLMService } from "./llm.service.js";
|
||||||
127
OnceLove/oncelove-graphrag/api/src/services/llm.service.js
Normal file
127
OnceLove/oncelove-graphrag/api/src/services/llm.service.js
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
const createHttpError = (statusCode, message) => {
|
||||||
|
const error = new Error(message);
|
||||||
|
error.statusCode = statusCode;
|
||||||
|
return error;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class LLMService {
|
||||||
|
constructor(env) {
|
||||||
|
this.baseUrl = (env.LLM_BASE_URL ?? "").replace(/\/+$/, "");
|
||||||
|
this.apiKey = env.LLM_API_KEY ?? "";
|
||||||
|
this.model = env.LLM_MODEL_NAME ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
isEnabled() {
|
||||||
|
return Boolean(this.baseUrl && this.apiKey && this.model);
|
||||||
|
}
|
||||||
|
|
||||||
|
async chat(messages, temperature = 0.7) {
|
||||||
|
if (!this.isEnabled()) {
|
||||||
|
throw createHttpError(400, "LLM 服务未配置,请提供 LLM_BASE_URL/LLM_API_KEY/LLM_MODEL_NAME");
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${this.apiKey}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: this.model,
|
||||||
|
messages: messages,
|
||||||
|
temperature: temperature
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw createHttpError(response.status, `LLM 请求失败:${errorText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async analyzeText(text) {
|
||||||
|
if (!text?.trim()) {
|
||||||
|
throw createHttpError(400, "分析文本不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
const systemPrompt = `你是一个实体关系分析专家。请分析用户输入的文本,提取人物、事件、主题、关系。
|
||||||
|
|
||||||
|
## 输出格式
|
||||||
|
{
|
||||||
|
"persons": [{"id": "p1", "name": "人物名称", "description": "人物描述"}],
|
||||||
|
"events": [{"id": "e1", "type": "事件类型", "summary": "事件摘要", "occurred_at": "ISO 时间", "participants": ["p1"], "topics": ["t1"], "importance": 5}],
|
||||||
|
"topics": [{"id": "t1", "name": "主题名称"}],
|
||||||
|
"relations": [{"source": "p1", "target": "p2", "type": "关系类型", "description": "关系描述"}]
|
||||||
|
}
|
||||||
|
|
||||||
|
## 注意
|
||||||
|
- 时间用 ISO 格式,如文本没明确时间用当前时间
|
||||||
|
- importance 是重要性评分 1-10
|
||||||
|
- 关系类型:PARTICIPATES_IN, ABOUT, LOVES, FIGHTS_WITH, GIVES, PROPOSES_TO 等
|
||||||
|
- 如果文本涉及"我",推断另一个角色(如"她")
|
||||||
|
- 即使文本很短也要提取信息,不要返回空数组
|
||||||
|
|
||||||
|
只返回 JSON,不要有其他文字。`;
|
||||||
|
|
||||||
|
const messages = [
|
||||||
|
{ role: "system", content: systemPrompt },
|
||||||
|
{ role: "user", content: text }
|
||||||
|
];
|
||||||
|
console.log("[DEBUG] LLM request messages:", JSON.stringify(messages));
|
||||||
|
const result = await this.chat(messages, 0.3);
|
||||||
|
|
||||||
|
const content = result?.choices?.[0]?.message?.content;
|
||||||
|
console.log("[DEBUG] LLM raw response:", content);
|
||||||
|
if (!content) {
|
||||||
|
throw createHttpError(500, "LLM 返回内容为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
let parsed;
|
||||||
|
try {
|
||||||
|
const jsonMatch = content.match(/\{[\s\S]*\}/);
|
||||||
|
parsed = jsonMatch ? JSON.parse(jsonMatch[0]) : JSON.parse(content);
|
||||||
|
} catch (e) {
|
||||||
|
throw createHttpError(500, `LLM 返回格式错误:${content.substring(0, 200)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isEmptyAnalysis(parsed)) {
|
||||||
|
const retryMessages = [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content: "你是信息抽取器。必须输出非空 JSON:{persons:[{id,name,description}],events:[{id,type,summary,occurred_at,participants,topics,importance}],topics:[{id,name}],relations:[{source,target,type,description}]}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: `从下列文本提取实体关系,至少给出 2 个 persons、1 个 event、1 个 relation,且仅返回 JSON:${text}`
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const retryResult = await this.chat(retryMessages, 0.2);
|
||||||
|
const retryContent = retryResult?.choices?.[0]?.message?.content;
|
||||||
|
if (!retryContent) {
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const retryJsonMatch = retryContent.match(/\{[\s\S]*\}/);
|
||||||
|
const retryParsed = retryJsonMatch ? JSON.parse(retryJsonMatch[0]) : JSON.parse(retryContent);
|
||||||
|
if (!this.isEmptyAnalysis(retryParsed)) {
|
||||||
|
return retryParsed;
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
isEmptyAnalysis(data) {
|
||||||
|
return !data
|
||||||
|
|| (!Array.isArray(data.persons) || data.persons.length === 0)
|
||||||
|
&& (!Array.isArray(data.events) || data.events.length === 0)
|
||||||
|
&& (!Array.isArray(data.topics) || data.topics.length === 0)
|
||||||
|
&& (!Array.isArray(data.relations) || data.relations.length === 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
const createHttpError = (statusCode, message) => {
|
||||||
|
const error = new Error(message);
|
||||||
|
error.statusCode = statusCode;
|
||||||
|
return error;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class RerankService {
|
||||||
|
constructor(env) {
|
||||||
|
this.baseUrl = (env.RERANK_BASE_URL ?? "").replace(/\/+$/, "");
|
||||||
|
this.apiKey = env.RERANK_API_KEY ?? "";
|
||||||
|
this.model = env.RERANK_MODEL ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
isEnabled() {
|
||||||
|
return Boolean(this.baseUrl && this.apiKey && this.model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用第三方 rerank 模型对结果进行重排
|
||||||
|
* @param {string} query 查询语句
|
||||||
|
* @param {Array<{id: string, text: string, [key: string]: any}>} chunks 待重排的文档块
|
||||||
|
* @returns {Promise<Array>} 返回重排后的文档块列表
|
||||||
|
*/
|
||||||
|
async rerank(query, chunks) {
|
||||||
|
if (!this.isEnabled()) {
|
||||||
|
return chunks; // 未配置则直接返回原结果
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chunks || chunks.length === 0) {
|
||||||
|
return chunks;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cleanedQuery = typeof query === "string" ? query.trim() : "";
|
||||||
|
if (!cleanedQuery) {
|
||||||
|
return chunks;
|
||||||
|
}
|
||||||
|
|
||||||
|
const texts = chunks.map(c => c.text);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 假设使用类似 OpenAI 或通用的 rerank 接口格式
|
||||||
|
// 实际使用时需根据具体第三方模型的 API 调整参数和路径
|
||||||
|
const response = await fetch(`${this.baseUrl}/v1/rerank`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${this.apiKey}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: this.model,
|
||||||
|
query: cleanedQuery,
|
||||||
|
texts: texts
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw createHttpError(response.status, `rerank 请求失败: ${errorText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
// data.results 格式通常为: [{ index: 0, relevance_score: 0.9 }, ...]
|
||||||
|
const results = data?.results;
|
||||||
|
|
||||||
|
if (!Array.isArray(results)) {
|
||||||
|
throw createHttpError(500, "rerank 返回格式异常");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据重排结果重新排序 chunks
|
||||||
|
const rerankedChunks = results
|
||||||
|
.sort((a, b) => b.relevance_score - a.relevance_score)
|
||||||
|
.map(r => ({
|
||||||
|
...chunks[r.index],
|
||||||
|
relevance_score: r.relevance_score
|
||||||
|
}));
|
||||||
|
|
||||||
|
return rerankedChunks;
|
||||||
|
} catch (error) {
|
||||||
|
// 重排失败时,为了不阻断流程,可以选择直接返回原结果并记录日志,或者抛出错误
|
||||||
|
console.error("Rerank error:", error);
|
||||||
|
return chunks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
96
OnceLove/oncelove-graphrag/docker-compose.yml
Normal file
96
OnceLove/oncelove-graphrag/docker-compose.yml
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
version: "3.9"
|
||||||
|
|
||||||
|
services:
|
||||||
|
neo4j:
|
||||||
|
image: neo4j:5.26-community
|
||||||
|
container_name: oncelove-neo4j
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
- NEO4J_AUTH=neo4j/${NEO4J_PASSWORD}
|
||||||
|
- NEO4J_dbms_default__database=neo4j
|
||||||
|
- NEO4J_server_memory_heap_initial__size=512m
|
||||||
|
- NEO4J_server_memory_heap_max__size=1024m
|
||||||
|
- NEO4J_server_memory_pagecache_size=512m
|
||||||
|
- NEO4J_server_bolt_advertised__address=neo4j:7687
|
||||||
|
volumes:
|
||||||
|
- neo4j_data:/data
|
||||||
|
- neo4j_logs:/logs
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:7474:7474"
|
||||||
|
- "127.0.0.1:7687:7687"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "wget -qO- http://localhost:7474 || exit 1"]
|
||||||
|
interval: 15s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 20
|
||||||
|
networks:
|
||||||
|
- oncelove_net
|
||||||
|
|
||||||
|
qdrant:
|
||||||
|
image: qdrant/qdrant:v1.13.4
|
||||||
|
container_name: oncelove-qdrant
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- qdrant_data:/qdrant/storage
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:6333:6333"
|
||||||
|
- "127.0.0.1:6334:6334"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "wget -qO- http://localhost:6333/healthz || exit 1"]
|
||||||
|
interval: 15s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 20
|
||||||
|
networks:
|
||||||
|
- oncelove_net
|
||||||
|
|
||||||
|
api:
|
||||||
|
build:
|
||||||
|
context: ./api
|
||||||
|
container_name: oncelove-api
|
||||||
|
restart: unless-stopped
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
- PORT=3000
|
||||||
|
- APPLICATION_URL=${APPLICATION_URL}
|
||||||
|
- WEBUI_URL=${WEBUI_URL}
|
||||||
|
- NEO4J_URI=bolt://neo4j:7687
|
||||||
|
- NEO4J_USER=neo4j
|
||||||
|
- NEO4J_PASSWORD=${NEO4J_PASSWORD}
|
||||||
|
- QDRANT_URL=http://qdrant:6333
|
||||||
|
- QDRANT_API_KEY=${QDRANT_API_KEY}
|
||||||
|
- QDRANT_COLLECTION=${QDRANT_COLLECTION}
|
||||||
|
- EMBEDDING_DIM=${EMBEDDING_DIM}
|
||||||
|
depends_on:
|
||||||
|
neo4j:
|
||||||
|
condition: service_healthy
|
||||||
|
qdrant:
|
||||||
|
condition: service_healthy
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:3000:3000"
|
||||||
|
networks:
|
||||||
|
- oncelove_net
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: ./frontend
|
||||||
|
args:
|
||||||
|
- VITE_API_BASE_URL=${APPLICATION_URL}
|
||||||
|
container_name: oncelove-frontend
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8080:80"
|
||||||
|
networks:
|
||||||
|
- oncelove_net
|
||||||
|
depends_on:
|
||||||
|
- api
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
neo4j_data:
|
||||||
|
neo4j_logs:
|
||||||
|
qdrant_data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
oncelove_net:
|
||||||
|
driver: bridge
|
||||||
1
OnceLove/oncelove-graphrag/dy
Normal file
1
OnceLove/oncelove-graphrag/dy
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"statusCode":400,"code":"FST_ERR_CTP_EMPTY_JSON_BODY","error":"Bad Request","message":"Body cannot be empty when content-type is set to 'application/json'"}
|
||||||
24
OnceLove/oncelove-graphrag/frontend/.gitignore
vendored
Normal file
24
OnceLove/oncelove-graphrag/frontend/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
18
OnceLove/oncelove-graphrag/frontend/Dockerfile
Normal file
18
OnceLove/oncelove-graphrag/frontend/Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Build stage
|
||||||
|
FROM node:22-alpine AS build-stage
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm config set registry https://registry.npmmirror.com && npm install --no-audit --no-fund
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ARG VITE_API_BASE_URL
|
||||||
|
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM nginx:alpine
|
||||||
|
COPY --from=build-stage /app/dist /usr/share/nginx/html
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
EXPOSE 80
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
5
OnceLove/oncelove-graphrag/frontend/README.md
Normal file
5
OnceLove/oncelove-graphrag/frontend/README.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Vue 3 + Vite
|
||||||
|
|
||||||
|
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||||
|
|
||||||
|
Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).
|
||||||
13
OnceLove/oncelove-graphrag/frontend/index.html
Normal file
13
OnceLove/oncelove-graphrag/frontend/index.html
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>frontend</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module" src="/src/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
15
OnceLove/oncelove-graphrag/frontend/nginx.conf
Normal file
15
OnceLove/oncelove-graphrag/frontend/nginx.conf
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html index.htm;
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
}
|
||||||
2284
OnceLove/oncelove-graphrag/frontend/package-lock.json
generated
Normal file
2284
OnceLove/oncelove-graphrag/frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
OnceLove/oncelove-graphrag/frontend/package.json
Normal file
21
OnceLove/oncelove-graphrag/frontend/package.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^1.13.6",
|
||||||
|
"d3": "^7.9.0",
|
||||||
|
"vue": "^3.5.30",
|
||||||
|
"vue-router": "^5.0.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@vitejs/plugin-vue": "^6.0.5",
|
||||||
|
"vite": "^8.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
1
OnceLove/oncelove-graphrag/frontend/public/favicon.svg
Normal file
1
OnceLove/oncelove-graphrag/frontend/public/favicon.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 9.3 KiB |
24
OnceLove/oncelove-graphrag/frontend/public/icons.svg
Normal file
24
OnceLove/oncelove-graphrag/frontend/public/icons.svg
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<symbol id="bluesky-icon" viewBox="0 0 16 17">
|
||||||
|
<g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
|
||||||
|
<defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="discord-icon" viewBox="0 0 20 19">
|
||||||
|
<path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="documentation-icon" viewBox="0 0 21 20">
|
||||||
|
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
|
||||||
|
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
|
||||||
|
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="github-icon" viewBox="0 0 19 19">
|
||||||
|
<path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="social-icon" viewBox="0 0 20 20">
|
||||||
|
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
|
||||||
|
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="x-icon" viewBox="0 0 19 19">
|
||||||
|
<path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
|
||||||
|
</symbol>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 4.9 KiB |
43
OnceLove/oncelove-graphrag/frontend/src/App.vue
Normal file
43
OnceLove/oncelove-graphrag/frontend/src/App.vue
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<template>
|
||||||
|
<router-view />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
font-family: 'JetBrains Mono', 'Space Grotesk', 'Noto Sans SC', monospace;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
color: #000000;
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: #f1f1f1;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: #000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: #333333;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
BIN
OnceLove/oncelove-graphrag/frontend/src/assets/hero.png
Normal file
BIN
OnceLove/oncelove-graphrag/frontend/src/assets/hero.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
1
OnceLove/oncelove-graphrag/frontend/src/assets/vite.svg
Normal file
1
OnceLove/oncelove-graphrag/frontend/src/assets/vite.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 8.5 KiB |
1
OnceLove/oncelove-graphrag/frontend/src/assets/vue.svg
Normal file
1
OnceLove/oncelove-graphrag/frontend/src/assets/vue.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 496 B |
@@ -0,0 +1,93 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import viteLogo from '../assets/vite.svg'
|
||||||
|
import heroImg from '../assets/hero.png'
|
||||||
|
import vueLogo from '../assets/vue.svg'
|
||||||
|
|
||||||
|
const count = ref(0)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section id="center">
|
||||||
|
<div class="hero">
|
||||||
|
<img :src="heroImg" class="base" width="170" height="179" alt="" />
|
||||||
|
<img :src="vueLogo" class="framework" alt="Vue logo" />
|
||||||
|
<img :src="viteLogo" class="vite" alt="Vite logo" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h1>Get started</h1>
|
||||||
|
<p>Edit <code>src/App.vue</code> and save to test <code>HMR</code></p>
|
||||||
|
</div>
|
||||||
|
<button class="counter" @click="count++">Count is {{ count }}</button>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div class="ticks"></div>
|
||||||
|
|
||||||
|
<section id="next-steps">
|
||||||
|
<div id="docs">
|
||||||
|
<svg class="icon" role="presentation" aria-hidden="true">
|
||||||
|
<use href="/icons.svg#documentation-icon"></use>
|
||||||
|
</svg>
|
||||||
|
<h2>Documentation</h2>
|
||||||
|
<p>Your questions, answered</p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://vite.dev/" target="_blank">
|
||||||
|
<img class="logo" :src="viteLogo" alt="" />
|
||||||
|
Explore Vite
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://vuejs.org/" target="_blank">
|
||||||
|
<img class="button-icon" :src="vueLogo" alt="" />
|
||||||
|
Learn more
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div id="social">
|
||||||
|
<svg class="icon" role="presentation" aria-hidden="true">
|
||||||
|
<use href="/icons.svg#social-icon"></use>
|
||||||
|
</svg>
|
||||||
|
<h2>Connect with us</h2>
|
||||||
|
<p>Join the Vite community</p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://github.com/vitejs/vite" target="_blank">
|
||||||
|
<svg class="button-icon" role="presentation" aria-hidden="true">
|
||||||
|
<use href="/icons.svg#github-icon"></use>
|
||||||
|
</svg>
|
||||||
|
GitHub
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://chat.vite.dev/" target="_blank">
|
||||||
|
<svg class="button-icon" role="presentation" aria-hidden="true">
|
||||||
|
<use href="/icons.svg#discord-icon"></use>
|
||||||
|
</svg>
|
||||||
|
Discord
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://x.com/vite_js" target="_blank">
|
||||||
|
<svg class="button-icon" role="presentation" aria-hidden="true">
|
||||||
|
<use href="/icons.svg#x-icon"></use>
|
||||||
|
</svg>
|
||||||
|
X.com
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://bsky.app/profile/vite.dev" target="_blank">
|
||||||
|
<svg class="button-icon" role="presentation" aria-hidden="true">
|
||||||
|
<use href="/icons.svg#bluesky-icon"></use>
|
||||||
|
</svg>
|
||||||
|
Bluesky
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div class="ticks"></div>
|
||||||
|
<section id="spacer"></section>
|
||||||
|
</template>
|
||||||
9
OnceLove/oncelove-graphrag/frontend/src/main.js
Normal file
9
OnceLove/oncelove-graphrag/frontend/src/main.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { createApp } from 'vue'
|
||||||
|
import App from './App.vue'
|
||||||
|
import router from './router'
|
||||||
|
|
||||||
|
const app = createApp(App)
|
||||||
|
|
||||||
|
app.use(router)
|
||||||
|
|
||||||
|
app.mount('#app')
|
||||||
35
OnceLove/oncelove-graphrag/frontend/src/router/index.js
Normal file
35
OnceLove/oncelove-graphrag/frontend/src/router/index.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
|
|
||||||
|
const routes = [
|
||||||
|
{
|
||||||
|
path: '/login',
|
||||||
|
name: 'Login',
|
||||||
|
component: () => import('../views/Login.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
name: 'Dashboard',
|
||||||
|
component: () => import('../views/Dashboard.vue'),
|
||||||
|
meta: { requiresAuth: true }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const router = createRouter({
|
||||||
|
history: createWebHistory(),
|
||||||
|
routes
|
||||||
|
})
|
||||||
|
|
||||||
|
router.beforeEach((to, from, next) => {
|
||||||
|
if (to.meta.requiresAuth) {
|
||||||
|
const authStatus = localStorage.getItem('auth_token')
|
||||||
|
if (authStatus) {
|
||||||
|
next()
|
||||||
|
} else {
|
||||||
|
next('/login')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default router
|
||||||
296
OnceLove/oncelove-graphrag/frontend/src/style.css
Normal file
296
OnceLove/oncelove-graphrag/frontend/src/style.css
Normal file
@@ -0,0 +1,296 @@
|
|||||||
|
:root {
|
||||||
|
--text: #6b6375;
|
||||||
|
--text-h: #08060d;
|
||||||
|
--bg: #fff;
|
||||||
|
--border: #e5e4e7;
|
||||||
|
--code-bg: #f4f3ec;
|
||||||
|
--accent: #aa3bff;
|
||||||
|
--accent-bg: rgba(170, 59, 255, 0.1);
|
||||||
|
--accent-border: rgba(170, 59, 255, 0.5);
|
||||||
|
--social-bg: rgba(244, 243, 236, 0.5);
|
||||||
|
--shadow:
|
||||||
|
rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px;
|
||||||
|
|
||||||
|
--sans: system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
--heading: system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
--mono: ui-monospace, Consolas, monospace;
|
||||||
|
|
||||||
|
font: 18px/145% var(--sans);
|
||||||
|
letter-spacing: 0.18px;
|
||||||
|
color-scheme: light dark;
|
||||||
|
color: var(--text);
|
||||||
|
background: var(--bg);
|
||||||
|
font-synthesis: none;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--text: #9ca3af;
|
||||||
|
--text-h: #f3f4f6;
|
||||||
|
--bg: #16171d;
|
||||||
|
--border: #2e303a;
|
||||||
|
--code-bg: #1f2028;
|
||||||
|
--accent: #c084fc;
|
||||||
|
--accent-bg: rgba(192, 132, 252, 0.15);
|
||||||
|
--accent-border: rgba(192, 132, 252, 0.5);
|
||||||
|
--social-bg: rgba(47, 48, 58, 0.5);
|
||||||
|
--shadow:
|
||||||
|
rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#social .button-icon {
|
||||||
|
filter: invert(1) brightness(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2 {
|
||||||
|
font-family: var(--heading);
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-h);
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 56px;
|
||||||
|
letter-spacing: -1.68px;
|
||||||
|
margin: 32px 0;
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
font-size: 36px;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
font-size: 24px;
|
||||||
|
line-height: 118%;
|
||||||
|
letter-spacing: -0.24px;
|
||||||
|
margin: 0 0 8px;
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
code,
|
||||||
|
.counter {
|
||||||
|
font-family: var(--mono);
|
||||||
|
display: inline-flex;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: var(--text-h);
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 135%;
|
||||||
|
padding: 4px 8px;
|
||||||
|
background: var(--code-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.counter {
|
||||||
|
font-size: 16px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
color: var(--accent);
|
||||||
|
background: var(--accent-bg);
|
||||||
|
border: 2px solid transparent;
|
||||||
|
transition: border-color 0.3s;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: var(--accent-border);
|
||||||
|
}
|
||||||
|
&:focus-visible {
|
||||||
|
outline: 2px solid var(--accent);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.base,
|
||||||
|
.framework,
|
||||||
|
.vite {
|
||||||
|
inset-inline: 0;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.base {
|
||||||
|
width: 170px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.framework,
|
||||||
|
.vite {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.framework {
|
||||||
|
z-index: 1;
|
||||||
|
top: 34px;
|
||||||
|
height: 28px;
|
||||||
|
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg)
|
||||||
|
scale(1.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.vite {
|
||||||
|
z-index: 0;
|
||||||
|
top: 107px;
|
||||||
|
height: 26px;
|
||||||
|
width: auto;
|
||||||
|
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg)
|
||||||
|
scale(0.8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
width: 1126px;
|
||||||
|
max-width: 100%;
|
||||||
|
margin: 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
border-inline: 1px solid var(--border);
|
||||||
|
min-height: 100svh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
#center {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 25px;
|
||||||
|
place-content: center;
|
||||||
|
place-items: center;
|
||||||
|
flex-grow: 1;
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
padding: 32px 20px 24px;
|
||||||
|
gap: 18px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#next-steps {
|
||||||
|
display: flex;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
& > div {
|
||||||
|
flex: 1 1 0;
|
||||||
|
padding: 32px;
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
padding: 24px 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#docs {
|
||||||
|
border-right: 1px solid var(--border);
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
border-right: none;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#next-steps ul {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin: 32px 0 0;
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: var(--text-h);
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: var(--social-bg);
|
||||||
|
display: flex;
|
||||||
|
padding: 6px 12px;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: box-shadow 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
}
|
||||||
|
.button-icon {
|
||||||
|
height: 18px;
|
||||||
|
width: 18px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
margin-top: 20px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
li {
|
||||||
|
flex: 1 1 calc(50% - 8px);
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#spacer {
|
||||||
|
height: 88px;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
height: 48px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ticks {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
&::before,
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: -4.5px;
|
||||||
|
border: 5px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
left: 0;
|
||||||
|
border-left-color: var(--border);
|
||||||
|
}
|
||||||
|
&::after {
|
||||||
|
right: 0;
|
||||||
|
border-right-color: var(--border);
|
||||||
|
}
|
||||||
|
}
|
||||||
768
OnceLove/oncelove-graphrag/frontend/src/views/Dashboard.vue
Normal file
768
OnceLove/oncelove-graphrag/frontend/src/views/Dashboard.vue
Normal file
@@ -0,0 +1,768 @@
|
|||||||
|
<template>
|
||||||
|
<div class="dashboard">
|
||||||
|
<aside class="sidebar">
|
||||||
|
<div class="sidebar-header">
|
||||||
|
<div class="logo-mark">
|
||||||
|
<svg width="32" height="32" viewBox="0 0 48 48" fill="none">
|
||||||
|
<circle cx="24" cy="24" r="20" stroke="#6366f1" stroke-width="2.5"/>
|
||||||
|
<circle cx="24" cy="24" r="6" fill="#6366f1"/>
|
||||||
|
<line x1="24" y1="4" x2="24" y2="18" stroke="#6366f1" stroke-width="2.5"/>
|
||||||
|
<line x1="24" y1="30" x2="24" y2="44" stroke="#6366f1" stroke-width="2.5"/>
|
||||||
|
<line x1="4" y1="24" x2="18" y2="24" stroke="#6366f1" stroke-width="2.5"/>
|
||||||
|
<line x1="30" y1="24" x2="44" y2="24" stroke="#6366f1" stroke-width="2.5"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="logo-text">
|
||||||
|
<span class="logo-name">GraphRAG</span>
|
||||||
|
<span class="logo-sub">管理平台</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<nav class="sidebar-nav">
|
||||||
|
<button
|
||||||
|
v-for="item in navItems"
|
||||||
|
:key="item.id"
|
||||||
|
class="nav-btn"
|
||||||
|
:class="{ active: activeTab === item.id }"
|
||||||
|
@click="activeTab = item.id"
|
||||||
|
>
|
||||||
|
<span class="nav-icon" v-html="item.icon"></span>
|
||||||
|
<span>{{ item.label }}</span>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="sidebar-footer">
|
||||||
|
<div class="user-card">
|
||||||
|
<div class="user-avatar">A</div>
|
||||||
|
<div class="user-info">
|
||||||
|
<span class="user-role">管理员</span>
|
||||||
|
<span class="user-name">Admin</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="logout-btn" @click="handleLogout">
|
||||||
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/>
|
||||||
|
<polyline points="16 17 21 12 16 7"/>
|
||||||
|
<line x1="21" y1="12" x2="9" y2="12"/>
|
||||||
|
</svg>
|
||||||
|
退出登录
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<main class="main-panel">
|
||||||
|
<header class="top-header">
|
||||||
|
<div class="header-left">
|
||||||
|
<h1 class="page-title">{{ currentNav.label }}</h1>
|
||||||
|
<p class="page-desc">{{ currentNav.desc }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="header-actions">
|
||||||
|
<button class="btn-ghost" @click="refreshData">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<polyline points="23 4 23 10 17 10"/>
|
||||||
|
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>
|
||||||
|
</svg>
|
||||||
|
刷新
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="content-area">
|
||||||
|
<div v-if="activeTab === 'graph'" class="graph-view">
|
||||||
|
<div class="graph-toolbar">
|
||||||
|
<div class="toolbar-left">
|
||||||
|
<span class="data-badge">实时数据</span>
|
||||||
|
<span class="node-count">{{ graphStats.nodes }} 节点 · {{ graphStats.edges }} 关系</span>
|
||||||
|
</div>
|
||||||
|
<div class="toolbar-right">
|
||||||
|
<button class="btn-outline" @click="zoomIn">+ 放大</button>
|
||||||
|
<button class="btn-outline" @click="zoomOut">- 缩小</button>
|
||||||
|
<button class="btn-primary" @click="fitView">适应画布</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="graph-canvas" ref="graphCanvas">
|
||||||
|
<div v-if="graphLoading" class="graph-loading">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<p>加载图谱数据...</p>
|
||||||
|
</div>
|
||||||
|
<svg v-show="!graphLoading" ref="svgEl" class="graph-svg"></svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="activeTab === 'ingest'" class="ingest-view">
|
||||||
|
<div class="panel-grid">
|
||||||
|
<div class="panel-card">
|
||||||
|
<div class="panel-header">
|
||||||
|
<h3>文本导入</h3>
|
||||||
|
<span class="panel-tag">Ingest</span>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<textarea
|
||||||
|
v-model="ingestText"
|
||||||
|
class="text-area"
|
||||||
|
placeholder="在此输入文本内容,系统将自动完成分句、向量化并写入 Neo4j 与 Qdrant..."
|
||||||
|
rows="8"
|
||||||
|
></textarea>
|
||||||
|
<div class="panel-actions">
|
||||||
|
<button class="btn-primary" @click="handleIngest" :disabled="!ingestText || ingestLoading">
|
||||||
|
{{ ingestLoading ? '导入中...' : '开始导入' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel-card">
|
||||||
|
<div class="panel-header">
|
||||||
|
<h3>导入记录</h3>
|
||||||
|
<span class="panel-tag info">Recent</span>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="log-list">
|
||||||
|
<div v-for="(log, i) in ingestLogs" :key="i" class="log-item" :class="log.type">
|
||||||
|
<span class="log-time">{{ log.time }}</span>
|
||||||
|
<span class="log-msg">{{ log.msg }}</span>
|
||||||
|
</div>
|
||||||
|
<p v-if="!ingestLogs.length" class="log-empty">暂无导入记录</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="activeTab === 'query'" class="query-view">
|
||||||
|
<div class="panel-grid">
|
||||||
|
<div class="panel-card wide">
|
||||||
|
<div class="panel-header">
|
||||||
|
<h3>时序检索</h3>
|
||||||
|
<span class="panel-tag">Query</span>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="query-input-row">
|
||||||
|
<input
|
||||||
|
v-model="queryText"
|
||||||
|
class="query-input"
|
||||||
|
placeholder="输入查询内容,例如:张三和张四的关系是什么?"
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
/>
|
||||||
|
<button class="btn-primary" @click="handleQuery" :disabled="!queryText || queryLoading">
|
||||||
|
{{ queryLoading ? '检索中...' : '检索' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="queryResult" class="query-result">
|
||||||
|
<div class="result-section">
|
||||||
|
<h4>检索结果</h4>
|
||||||
|
<p class="result-text">{{ queryResult.answer }}</p>
|
||||||
|
</div>
|
||||||
|
<div v-if="queryResult.chunks?.length" class="result-section">
|
||||||
|
<h4>相关片段</h4>
|
||||||
|
<div class="chunk-list">
|
||||||
|
<div v-for="(chunk, i) in queryResult.chunks" :key="i" class="chunk-item">
|
||||||
|
<p>{{ chunk.text || chunk.content }}</p>
|
||||||
|
<span v-if="chunk.score" class="chunk-score">相关度: {{ (chunk.score * 100).toFixed(1) }}%</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="activeTab === 'api'" class="api-view">
|
||||||
|
<div class="panel-grid">
|
||||||
|
<div class="panel-card wide">
|
||||||
|
<div class="panel-header">
|
||||||
|
<h3>接口调试</h3>
|
||||||
|
<span class="panel-tag">API Tester</span>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="api-row">
|
||||||
|
<select v-model="apiMethod" class="method-select">
|
||||||
|
<option value="GET">GET</option>
|
||||||
|
<option value="POST">POST</option>
|
||||||
|
<option value="PUT">PUT</option>
|
||||||
|
<option value="DELETE">DELETE</option>
|
||||||
|
</select>
|
||||||
|
<input v-model="apiUrl" class="api-url-input" placeholder="/graph/stats" @keyup.enter="sendApiRequest" />
|
||||||
|
<button class="btn-primary" @click="sendApiRequest" :disabled="apiLoading">
|
||||||
|
{{ apiLoading ? '发送中...' : '发送' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="api-endpoints">
|
||||||
|
<span class="endpoint-label">快速调用:</span>
|
||||||
|
<button v-for="ep in quickEndpoints" :key="ep.path" class="endpoint-chip" @click="fillApi(ep)">
|
||||||
|
<span class="chip-method" :class="ep.method.toLowerCase()">{{ ep.method }}</span>
|
||||||
|
{{ ep.path }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div v-if="apiMethod === 'POST' || apiMethod === 'PUT'" class="api-body-section">
|
||||||
|
<h4 class="body-label">请求体 (JSON)</h4>
|
||||||
|
<textarea v-model="apiBody" class="text-area code-area" placeholder='{"key": "value"}' rows="8"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="api-response-section">
|
||||||
|
<div class="response-header">
|
||||||
|
<h4>响应结果</h4>
|
||||||
|
<span v-if="apiStatus" class="status-badge" :class="apiStatus >= 200 && apiStatus < 300 ? 'success' : 'error'">
|
||||||
|
{{ apiStatus }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<pre class="response-pre">{{ apiResponse || '等待发送请求...' }}</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
import * as d3 from 'd3'
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const activeTab = ref('graph')
|
||||||
|
const graphLoading = ref(false)
|
||||||
|
const ingestLoading = ref(false)
|
||||||
|
const queryLoading = ref(false)
|
||||||
|
const ingestText = ref('')
|
||||||
|
const queryText = ref('')
|
||||||
|
const queryResult = ref(null)
|
||||||
|
const ingestLogs = ref([])
|
||||||
|
const graphStats = ref({ nodes: 0, edges: 0 })
|
||||||
|
const graphCanvas = ref(null)
|
||||||
|
const svgEl = ref(null)
|
||||||
|
const apiMethod = ref('GET')
|
||||||
|
const apiUrl = ref('')
|
||||||
|
const apiBody = ref('')
|
||||||
|
const apiResponse = ref('')
|
||||||
|
const apiStatus = ref(null)
|
||||||
|
const apiLoading = ref(false)
|
||||||
|
const quickEndpoints = [
|
||||||
|
{ method: 'GET', path: '/health', body: '' },
|
||||||
|
{ method: 'GET', path: '/ready', body: '' },
|
||||||
|
{ method: 'POST', path: '/bootstrap', body: '{}' },
|
||||||
|
{ method: 'GET', path: '/graph/stats', body: '' },
|
||||||
|
{ method: 'POST', path: '/ingest', body: '{"persons":[{"id":"p1","name":"张三"}],"events":[{"id":"e1","summary":"测试事件","occurred_at":"2024-01-01T00:00:00Z","participants":["p1"],"topics":["t1"]}],"chunks":[{"id":"c1","text":"这是测试内容","payload":{"event_id":"e1"}}]}' },
|
||||||
|
{ method: 'POST', path: '/query/timeline', body: '{"a_id":"p1","b_id":"p2"}' },
|
||||||
|
{ method: 'POST', path: '/query/graphrag', body: '{"query_text":"张三的事件","top_k":5}' },
|
||||||
|
{ method: 'POST', path: '/auth/verify', body: '{"password":"your-password"}' }
|
||||||
|
]
|
||||||
|
|
||||||
|
const fillApi = (ep) => {
|
||||||
|
apiMethod.value = ep.method
|
||||||
|
apiUrl.value = ep.path
|
||||||
|
apiBody.value = ep.body
|
||||||
|
}
|
||||||
|
|
||||||
|
const sendApiRequest = async () => {
|
||||||
|
if (!apiUrl.value) return
|
||||||
|
apiLoading.value = true
|
||||||
|
apiResponse.value = ''
|
||||||
|
apiStatus.value = null
|
||||||
|
try {
|
||||||
|
let targetUrl = apiUrl.value
|
||||||
|
if (!targetUrl.startsWith('http://') && !targetUrl.startsWith('https://')) {
|
||||||
|
const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'
|
||||||
|
targetUrl = `${apiBase}${apiUrl.value}`
|
||||||
|
}
|
||||||
|
const opts = { method: apiMethod.value, headers: { 'Content-Type': 'application/json' } }
|
||||||
|
if ((apiMethod.value === 'POST' || apiMethod.value === 'PUT') && apiBody.value) {
|
||||||
|
opts.body = apiBody.value
|
||||||
|
}
|
||||||
|
const res = await fetch(targetUrl, opts)
|
||||||
|
apiStatus.value = res.status
|
||||||
|
const text = await res.text()
|
||||||
|
try { apiResponse.value = JSON.stringify(JSON.parse(text), null, 2) }
|
||||||
|
catch { apiResponse.value = text }
|
||||||
|
} catch (err) {
|
||||||
|
apiStatus.value = 0
|
||||||
|
apiResponse.value = '请求失败: ' + err.message
|
||||||
|
} finally {
|
||||||
|
apiLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const navItems = [
|
||||||
|
{ id: 'graph', label: '知识图谱', desc: '可视化关系网络与时序事件', icon: '◉' },
|
||||||
|
{ id: 'ingest', label: '数据导入', desc: '导入文本并自动完成向量化', icon: '↓' },
|
||||||
|
{ id: 'query', label: '时序检索', desc: '基于 GraphRAG 的智能问答', icon: '⌕' },
|
||||||
|
{ id: 'api', label: 'API 测试', desc: '在线调试后端接口', icon: '⚡' }
|
||||||
|
]
|
||||||
|
|
||||||
|
const currentNav = computed(() => navItems.find(n => n.id === activeTab.value) || navItems[0])
|
||||||
|
|
||||||
|
const handleLogout = () => {
|
||||||
|
localStorage.removeItem('auth_token')
|
||||||
|
router.push('/login')
|
||||||
|
}
|
||||||
|
|
||||||
|
const refreshData = () => {
|
||||||
|
if (activeTab.value === 'graph') renderGraph()
|
||||||
|
}
|
||||||
|
|
||||||
|
const zoomIn = () => {
|
||||||
|
if (!svgEl.value) return
|
||||||
|
d3.select(svgEl.value).transition().call(d3.zoom().scaleBy, 1.3)
|
||||||
|
}
|
||||||
|
|
||||||
|
const zoomOut = () => {
|
||||||
|
if (!svgEl.value) return
|
||||||
|
d3.select(svgEl.value).transition().call(d3.zoom().scaleBy, 0.7)
|
||||||
|
}
|
||||||
|
|
||||||
|
const fitView = () => {
|
||||||
|
if (!svgEl.value) return
|
||||||
|
d3.select(svgEl.value).transition().call(d3.zoom().transform, d3.zoomIdentity)
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchGraphData = async () => {
|
||||||
|
const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${apiBase}/graph/stats`, { method: 'GET' })
|
||||||
|
if (res.ok) return await res.json()
|
||||||
|
} catch {}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const renderGraph = async () => {
|
||||||
|
if (!graphCanvas.value || !svgEl.value) return
|
||||||
|
graphLoading.value = true
|
||||||
|
|
||||||
|
const width = graphCanvas.value.clientWidth
|
||||||
|
const height = graphCanvas.value.clientHeight
|
||||||
|
|
||||||
|
d3.select(svgEl.value).selectAll('*').remove()
|
||||||
|
|
||||||
|
const svg = d3.select(svgEl.value)
|
||||||
|
.attr('width', width)
|
||||||
|
.attr('height', height)
|
||||||
|
|
||||||
|
const data = await fetchGraphData()
|
||||||
|
const nodes = Array.isArray(data?.nodes) ? data.nodes : []
|
||||||
|
const links = Array.isArray(data?.links) ? data.links : []
|
||||||
|
graphStats.value = { nodes: nodes.length, edges: links.length }
|
||||||
|
|
||||||
|
if (!nodes.length) {
|
||||||
|
svg.append('text')
|
||||||
|
.attr('x', width / 2)
|
||||||
|
.attr('y', height / 2)
|
||||||
|
.attr('text-anchor', 'middle')
|
||||||
|
.attr('font-size', 14)
|
||||||
|
.attr('fill', '#9ca3af')
|
||||||
|
.text('暂无节点数据')
|
||||||
|
graphLoading.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const colorMap = { person: '#6366f1', event: '#10b981', topic: '#f59e0b' }
|
||||||
|
const color = d => colorMap[d.type] || '#6366f1'
|
||||||
|
|
||||||
|
const g = svg.append('g')
|
||||||
|
|
||||||
|
svg.call(d3.zoom().scaleExtent([0.2, 3]).on('zoom', (event) => {
|
||||||
|
g.attr('transform', event.transform)
|
||||||
|
}))
|
||||||
|
|
||||||
|
const simulation = d3.forceSimulation(nodes)
|
||||||
|
.force('link', d3.forceLink(links).id(d => d.id).distance(140))
|
||||||
|
.force('charge', d3.forceManyBody().strength(-350))
|
||||||
|
.force('center', d3.forceCenter(width / 2, height / 2))
|
||||||
|
.force('collision', d3.forceCollide().radius(40))
|
||||||
|
|
||||||
|
const link = g.append('g')
|
||||||
|
.selectAll('line')
|
||||||
|
.data(links)
|
||||||
|
.join('line')
|
||||||
|
.attr('stroke', '#e5e7eb')
|
||||||
|
.attr('stroke-width', 1.5)
|
||||||
|
|
||||||
|
const nodeGroup = g.append('g')
|
||||||
|
.selectAll('g')
|
||||||
|
.data(nodes)
|
||||||
|
.join('g')
|
||||||
|
.call(d3.drag()
|
||||||
|
.on('start', (event, d) => { if (!event.active) simulation.alphaTarget(0.3).restart(); d.fx = d.x; d.fy = d.y })
|
||||||
|
.on('drag', (event, d) => { d.fx = event.x; d.fy = event.y })
|
||||||
|
.on('end', (event, d) => { if (!event.active) simulation.alphaTarget(0); d.fx = null; d.fy = null })
|
||||||
|
)
|
||||||
|
|
||||||
|
nodeGroup.append('circle')
|
||||||
|
.attr('r', 24)
|
||||||
|
.attr('fill', d => color(d))
|
||||||
|
.attr('stroke', '#fff')
|
||||||
|
.attr('stroke-width', 2)
|
||||||
|
|
||||||
|
nodeGroup.append('text')
|
||||||
|
.attr('dy', 36)
|
||||||
|
.attr('text-anchor', 'middle')
|
||||||
|
.attr('font-size', 12)
|
||||||
|
.attr('fill', '#6b7280')
|
||||||
|
.text(d => d.name)
|
||||||
|
|
||||||
|
simulation.on('tick', () => {
|
||||||
|
link
|
||||||
|
.attr('x1', d => d.source.x)
|
||||||
|
.attr('y1', d => d.source.y)
|
||||||
|
.attr('x2', d => d.target.x)
|
||||||
|
.attr('y2', d => d.target.y)
|
||||||
|
nodeGroup.attr('transform', d => `translate(${d.x},${d.y})`)
|
||||||
|
})
|
||||||
|
|
||||||
|
graphLoading.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleIngest = async () => {
|
||||||
|
if (!ingestText.value) return
|
||||||
|
ingestLoading.value = true
|
||||||
|
const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'
|
||||||
|
const now = new Date().toLocaleTimeString()
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${apiBase}/ingest`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ text: ingestText.value })
|
||||||
|
})
|
||||||
|
const data = await res.json()
|
||||||
|
ingestLogs.value.unshift({ time: now, msg: `导入成功: ${data.chunks?.length || 0} 个 chunk`, type: 'success' })
|
||||||
|
ingestText.value = ''
|
||||||
|
} catch (e) {
|
||||||
|
ingestLogs.value.unshift({ time: now, msg: `导入失败: ${e.message}`, type: 'error' })
|
||||||
|
} finally {
|
||||||
|
ingestLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleQuery = async () => {
|
||||||
|
if (!queryText.value) return
|
||||||
|
queryLoading.value = true
|
||||||
|
const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${apiBase}/query/graphrag`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ query: queryText.value })
|
||||||
|
})
|
||||||
|
queryResult.value = await res.json()
|
||||||
|
} catch (e) {
|
||||||
|
queryResult.value = { answer: `检索失败: ${e.message}`, chunks: [] }
|
||||||
|
} finally {
|
||||||
|
queryLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let resizeObserver
|
||||||
|
let graphRendered = false
|
||||||
|
onMounted(() => {
|
||||||
|
renderGraph()
|
||||||
|
graphRendered = true
|
||||||
|
if (graphCanvas.value) {
|
||||||
|
resizeObserver = new ResizeObserver(() => {
|
||||||
|
if (graphRendered) renderGraph()
|
||||||
|
})
|
||||||
|
resizeObserver.observe(graphCanvas.value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
resizeObserver?.disconnect()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
|
|
||||||
|
.dashboard {
|
||||||
|
display: flex;
|
||||||
|
height: 100vh;
|
||||||
|
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||||
|
background: #f7f8fa;
|
||||||
|
color: #1f2937;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
width: 240px;
|
||||||
|
background: #fff;
|
||||||
|
border-right: 1px solid #e5e7eb;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 24px 20px;
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo-mark { flex-shrink: 0; }
|
||||||
|
|
||||||
|
.logo-text { display: flex; flex-direction: column; }
|
||||||
|
.logo-name { font-size: 1rem; font-weight: 700; color: #0f0f0f; }
|
||||||
|
.logo-sub { font-size: 0.75rem; color: #9ca3af; }
|
||||||
|
|
||||||
|
.sidebar-nav {
|
||||||
|
flex: 1;
|
||||||
|
padding: 16px 12px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #6b7280;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
text-align: left;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-btn:hover { background: #f3f4f6; color: #1f2937; }
|
||||||
|
.nav-btn.active { background: #eef2ff; color: #6366f1; font-weight: 600; }
|
||||||
|
.nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }
|
||||||
|
|
||||||
|
.sidebar-footer {
|
||||||
|
padding: 16px 12px;
|
||||||
|
border-top: 1px solid #e5e7eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-card {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-avatar {
|
||||||
|
width: 32px; height: 32px;
|
||||||
|
background: #6366f1;
|
||||||
|
border-radius: 50%;
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
color: white; font-size: 0.85rem; font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-info { display: flex; flex-direction: column; }
|
||||||
|
.user-role { font-size: 0.7rem; color: #9ca3af; }
|
||||||
|
.user-name { font-size: 0.85rem; font-weight: 600; color: #1f2937; }
|
||||||
|
|
||||||
|
.logout-btn {
|
||||||
|
display: flex; align-items: center; gap: 8px;
|
||||||
|
width: 100%; padding: 8px 12px;
|
||||||
|
background: transparent; border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 8px; cursor: pointer;
|
||||||
|
font-size: 0.85rem; color: #6b7280;
|
||||||
|
transition: all 0.15s;
|
||||||
|
}
|
||||||
|
.logout-btn:hover { background: #fee2e2; color: #ef4444; border-color: #fca5a5; }
|
||||||
|
|
||||||
|
.main-panel {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 24px 32px;
|
||||||
|
background: #fff;
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-title { font-size: 1.25rem; font-weight: 700; color: #0f0f0f; }
|
||||||
|
.page-desc { font-size: 0.85rem; color: #9ca3af; margin-top: 2px; }
|
||||||
|
|
||||||
|
.btn-ghost {
|
||||||
|
display: flex; align-items: center; gap: 6px;
|
||||||
|
padding: 8px 16px;
|
||||||
|
background: transparent; border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 8px; cursor: pointer;
|
||||||
|
font-size: 0.85rem; color: #6b7280;
|
||||||
|
transition: all 0.15s;
|
||||||
|
}
|
||||||
|
.btn-ghost:hover { background: #f3f4f6; color: #1f2937; }
|
||||||
|
|
||||||
|
.content-area { flex: 1; overflow: hidden; padding: 24px 32px; }
|
||||||
|
|
||||||
|
.graph-view { height: 100%; display: flex; flex-direction: column; gap: 16px; }
|
||||||
|
|
||||||
|
.graph-toolbar {
|
||||||
|
display: flex; align-items: center; justify-content: space-between;
|
||||||
|
background: #fff; padding: 12px 16px;
|
||||||
|
border-radius: 10px; border: 1px solid #e5e7eb;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-left { display: flex; align-items: center; gap: 16px; }
|
||||||
|
|
||||||
|
.data-badge {
|
||||||
|
background: #dcfce7; color: #16a34a;
|
||||||
|
font-size: 0.75rem; font-weight: 600;
|
||||||
|
padding: 3px 10px; border-radius: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node-count { font-size: 0.85rem; color: #6b7280; }
|
||||||
|
|
||||||
|
.toolbar-right { display: flex; gap: 8px; }
|
||||||
|
|
||||||
|
.btn-outline {
|
||||||
|
padding: 6px 14px;
|
||||||
|
background: transparent; border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 6px; cursor: pointer;
|
||||||
|
font-size: 0.8rem; color: #6b7280;
|
||||||
|
transition: all 0.15s;
|
||||||
|
}
|
||||||
|
.btn-outline:hover { background: #f3f4f6; color: #1f2937; }
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
padding: 6px 16px;
|
||||||
|
background: #6366f1; color: white;
|
||||||
|
border: none; border-radius: 6px;
|
||||||
|
cursor: pointer; font-size: 0.8rem; font-weight: 600;
|
||||||
|
transition: all 0.15s;
|
||||||
|
}
|
||||||
|
.btn-primary:hover:not(:disabled) { background: #4f46e5; }
|
||||||
|
.btn-primary:disabled { background: #d1d5db; cursor: not-allowed; }
|
||||||
|
|
||||||
|
.graph-canvas {
|
||||||
|
flex: 1;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-loading {
|
||||||
|
position: absolute; inset: 0;
|
||||||
|
display: flex; flex-direction: column;
|
||||||
|
align-items: center; justify-content: center; gap: 12px;
|
||||||
|
background: rgba(255,255,255,0.9);
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
width: 32px; height: 32px;
|
||||||
|
border: 3px solid #e5e7eb;
|
||||||
|
border-top-color: #6366f1;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 0.8s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin { to { transform: rotate(360deg); } }
|
||||||
|
|
||||||
|
.graph-loading p { font-size: 0.9rem; color: #6b7280; }
|
||||||
|
|
||||||
|
.graph-svg { width: 100%; height: 100%; }
|
||||||
|
|
||||||
|
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; height: 100%; }
|
||||||
|
.panel-grid .wide { grid-column: 1 / -1; }
|
||||||
|
|
||||||
|
.panel-card {
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 10px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-header {
|
||||||
|
display: flex; align-items: center; justify-content: space-between;
|
||||||
|
padding: 16px 20px;
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-header h3 { font-size: 0.95rem; font-weight: 700; }
|
||||||
|
|
||||||
|
.panel-tag {
|
||||||
|
font-size: 0.7rem; font-weight: 600;
|
||||||
|
padding: 2px 8px; border-radius: 20px;
|
||||||
|
background: #e0e7ff; color: #6366f1;
|
||||||
|
}
|
||||||
|
.panel-tag.info { background: #dbeafe; color: #2563eb; }
|
||||||
|
|
||||||
|
.panel-body { flex: 1; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
|
||||||
|
|
||||||
|
.text-area {
|
||||||
|
width: 100%; padding: 12px;
|
||||||
|
border: 1px solid #e5e7eb; border-radius: 8px;
|
||||||
|
font-size: 0.9rem; resize: none; outline: none;
|
||||||
|
font-family: inherit;
|
||||||
|
transition: border-color 0.15s;
|
||||||
|
}
|
||||||
|
.text-area:focus { border-color: #6366f1; }
|
||||||
|
|
||||||
|
.panel-actions { display: flex; justify-content: flex-end; }
|
||||||
|
|
||||||
|
.log-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; max-height: 300px; }
|
||||||
|
|
||||||
|
.log-item {
|
||||||
|
display: flex; align-items: flex-start; gap: 10px;
|
||||||
|
padding: 8px 10px; border-radius: 6px;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
.log-item.success { background: #dcfce7; color: #16a34a; }
|
||||||
|
.log-item.error { background: #fee2e2; color: #ef4444; }
|
||||||
|
|
||||||
|
.log-time { color: #9ca3af; flex-shrink: 0; }
|
||||||
|
.log-msg { flex: 1; }
|
||||||
|
.log-empty { color: #9ca3af; font-size: 0.85rem; text-align: center; padding: 20px; }
|
||||||
|
|
||||||
|
.query-input-row { display: flex; gap: 12px; }
|
||||||
|
|
||||||
|
.query-input {
|
||||||
|
flex: 1; padding: 10px 14px;
|
||||||
|
border: 1px solid #e5e7eb; border-radius: 8px;
|
||||||
|
font-size: 0.9rem; outline: none;
|
||||||
|
transition: border-color 0.15s;
|
||||||
|
}
|
||||||
|
.query-input:focus { border-color: #6366f1; }
|
||||||
|
|
||||||
|
.query-result { display: flex; flex-direction: column; gap: 16px; margin-top: 8px; }
|
||||||
|
|
||||||
|
.result-section { display: flex; flex-direction: column; gap: 8px; }
|
||||||
|
.result-section h4 { font-size: 0.85rem; font-weight: 600; color: #6b7280; }
|
||||||
|
.result-text { font-size: 0.95rem; color: #1f2937; line-height: 1.6; }
|
||||||
|
|
||||||
|
.chunk-list { display: flex; flex-direction: column; gap: 8px; }
|
||||||
|
.chunk-item {
|
||||||
|
padding: 10px 12px;
|
||||||
|
background: #f9fafb; border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 6px; font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
.chunk-score { color: #6366f1; font-size: 0.75rem; margin-top: 4px; display: block; }
|
||||||
|
.api-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
|
||||||
|
.method-select { padding: 8px 12px; border: 1px solid #e5e7eb; border-radius: 6px; font-size: 0.85rem; background: #fff; min-width: 90px; }
|
||||||
|
.api-url-input { flex: 1; padding: 8px 12px; border: 1px solid #e5e7eb; border-radius: 6px; font-size: 0.85rem; }
|
||||||
|
.api-endpoints { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
|
||||||
|
.endpoint-label { font-size: 0.8rem; color: #6b7280; }
|
||||||
|
.endpoint-chip { display: flex; align-items: center; gap: 4px; padding: 4px 10px; border: 1px solid #e5e7eb; border-radius: 16px; background: #fff; cursor: pointer; font-size: 0.78rem; transition: all 0.2s; }
|
||||||
|
.endpoint-chip:hover { border-color: #6366f1; background: #eef2ff; }
|
||||||
|
.chip-method { font-weight: 700; font-size: 0.7rem; padding: 1px 4px; border-radius: 3px; }
|
||||||
|
.chip-method.get { color: #10b981; } .chip-method.post { color: #6366f1; } .chip-method.put { color: #f59e0b; } .chip-method.delete { color: #ef4444; }
|
||||||
|
.api-body-section { margin-bottom: 12px; }
|
||||||
|
.body-label { font-size: 0.82rem; color: #6b7280; margin-bottom: 6px; font-weight: 500; }
|
||||||
|
.code-area { font-family: 'Fira Code', monospace; font-size: 0.82rem; }
|
||||||
|
.api-response-section { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; }
|
||||||
|
.response-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
|
||||||
|
.response-header h4 { font-size: 0.85rem; font-weight: 600; }
|
||||||
|
.status-badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
|
||||||
|
.status-badge.success { background: #d1fae5; color: #065f46; } .status-badge.error { background: #fee2e2; color: #991b1b; }
|
||||||
|
.response-pre { font-family: 'Fira Code', monospace; font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; max-height: 300px; overflow-y: auto; color: #374151; }
|
||||||
|
</style>
|
||||||
363
OnceLove/oncelove-graphrag/frontend/src/views/Login.vue
Normal file
363
OnceLove/oncelove-graphrag/frontend/src/views/Login.vue
Normal file
@@ -0,0 +1,363 @@
|
|||||||
|
<template>
|
||||||
|
<div class="login-page">
|
||||||
|
<div class="login-left">
|
||||||
|
<div class="brand-content">
|
||||||
|
<div class="brand-logo">
|
||||||
|
<svg width="48" height="48" viewBox="0 0 48 48" fill="none">
|
||||||
|
<circle cx="24" cy="24" r="20" stroke="#fff" stroke-width="2"/>
|
||||||
|
<circle cx="24" cy="24" r="8" fill="#fff"/>
|
||||||
|
<line x1="24" y1="4" x2="24" y2="16" stroke="#fff" stroke-width="2"/>
|
||||||
|
<line x1="24" y1="32" x2="24" y2="44" stroke="#fff" stroke-width="2"/>
|
||||||
|
<line x1="4" y1="24" x2="16" y2="24" stroke="#fff" stroke-width="2"/>
|
||||||
|
<line x1="32" y1="24" x2="44" y2="24" stroke="#fff" stroke-width="2"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<h1>OnceLove GraphRAG</h1>
|
||||||
|
<p class="brand-desc">智能知识图谱与时序检索管理平台</p>
|
||||||
|
<div class="feature-list">
|
||||||
|
<div class="feature-item">
|
||||||
|
<span class="feature-icon">◈</span>
|
||||||
|
<span>Neo4j 关系图谱</span>
|
||||||
|
</div>
|
||||||
|
<div class="feature-item">
|
||||||
|
<span class="feature-icon">◈</span>
|
||||||
|
<span>Qdrant 向量检索</span>
|
||||||
|
</div>
|
||||||
|
<div class="feature-item">
|
||||||
|
<span class="feature-icon">◈</span>
|
||||||
|
<span>时序事件分析</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="bg-decoration">
|
||||||
|
<div class="circle c1"></div>
|
||||||
|
<div class="circle c2"></div>
|
||||||
|
<div class="circle c3"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="login-right">
|
||||||
|
<div class="login-card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h2>管理员登录</h2>
|
||||||
|
<p>请输入访问密钥以继续</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form @submit.prevent="handleLogin" class="login-form">
|
||||||
|
<div class="form-item">
|
||||||
|
<label>访问密钥</label>
|
||||||
|
<div class="input-wrapper" :class="{ error: error, focus: isFocused }">
|
||||||
|
<svg class="input-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
||||||
|
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
|
||||||
|
</svg>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
v-model="password"
|
||||||
|
@focus="isFocused = true"
|
||||||
|
@blur="isFocused = false"
|
||||||
|
placeholder="请输入密钥"
|
||||||
|
:disabled="loading"
|
||||||
|
autocomplete="current-password"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-if="error" class="error-text">
|
||||||
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">
|
||||||
|
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
|
||||||
|
</svg>
|
||||||
|
{{ error }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<button type="submit" class="login-btn" :class="{ loading }" :disabled="loading || !password">
|
||||||
|
<span v-if="!loading">进入控制台</span>
|
||||||
|
<span v-else class="loading-dots">
|
||||||
|
<span></span><span></span><span></span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="card-footer">
|
||||||
|
<p>OnceLove GraphRAG © 2024</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const password = ref('')
|
||||||
|
const error = ref('')
|
||||||
|
const loading = ref(false)
|
||||||
|
const isFocused = ref(false)
|
||||||
|
|
||||||
|
const handleLogin = async () => {
|
||||||
|
if (!password.value) {
|
||||||
|
error.value = '请输入密钥'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loading.value = true
|
||||||
|
error.value = ''
|
||||||
|
try {
|
||||||
|
const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'
|
||||||
|
const res = await fetch(`${apiBase}/auth/verify`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ password: password.value })
|
||||||
|
})
|
||||||
|
const data = await res.json().catch(() => ({}))
|
||||||
|
if (!res.ok || !data?.ok) {
|
||||||
|
error.value = data?.message || '密钥错误'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
localStorage.setItem('auth_token', 'ok')
|
||||||
|
router.push('/')
|
||||||
|
} catch (e) {
|
||||||
|
error.value = '登录请求失败,请检查 API 地址或网络'
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.login-page {
|
||||||
|
display: flex;
|
||||||
|
min-height: 100vh;
|
||||||
|
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-left {
|
||||||
|
flex: 1;
|
||||||
|
background: linear-gradient(135deg, #0f0f0f 0%, #1a1a2e 100%);
|
||||||
|
color: white;
|
||||||
|
padding: 60px;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-content {
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-logo {
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-content h1 {
|
||||||
|
font-size: 2.5rem;
|
||||||
|
font-weight: 700;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-desc {
|
||||||
|
font-size: 1.1rem;
|
||||||
|
color: rgba(255,255,255,0.6);
|
||||||
|
margin-bottom: 48px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
font-size: 1rem;
|
||||||
|
color: rgba(255,255,255,0.85);
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-icon {
|
||||||
|
color: #6366f1;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bg-decoration {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.circle {
|
||||||
|
position: absolute;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: linear-gradient(135deg, rgba(99,102,241,0.3) 0%, rgba(99,102,241,0) 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.c1 { width: 400px; height: 400px; top: -100px; right: -100px; }
|
||||||
|
.c2 { width: 300px; height: 300px; bottom: -50px; left: -50px; }
|
||||||
|
.c3 { width: 200px; height: 200px; bottom: 20%; right: 10%; opacity: 0.5; }
|
||||||
|
|
||||||
|
.login-right {
|
||||||
|
width: 520px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 60px;
|
||||||
|
background: #fafafa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-card {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 380px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
margin-bottom: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header h2 {
|
||||||
|
font-size: 1.75rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #0f0f0f;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header p {
|
||||||
|
color: #666;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-item label {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #374151;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background: white;
|
||||||
|
border: 1.5px solid #e5e7eb;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 0 16px;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrapper.focus {
|
||||||
|
border-color: #6366f1;
|
||||||
|
box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrapper.error {
|
||||||
|
border-color: #ef4444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-icon {
|
||||||
|
color: #9ca3af;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrapper input {
|
||||||
|
flex: 1;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
padding: 14px 12px;
|
||||||
|
font-size: 1rem;
|
||||||
|
background: transparent;
|
||||||
|
color: #0f0f0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrapper input::placeholder {
|
||||||
|
color: #9ca3af;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrapper input:disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-text {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
color: #ef4444;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
margin-top: -8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-btn {
|
||||||
|
width: 100%;
|
||||||
|
padding: 14px 24px;
|
||||||
|
background: #0f0f0f;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 10px;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-btn:hover:not(:disabled) {
|
||||||
|
background: #1a1a1a;
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-btn:disabled {
|
||||||
|
background: #d1d5db;
|
||||||
|
cursor: not-allowed;
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-btn.loading {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-dots {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-dots span {
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
background: white;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: bounce 1.4s infinite ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
|
||||||
|
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
|
||||||
|
|
||||||
|
@keyframes bounce {
|
||||||
|
0%, 80%, 100% { transform: scale(0); }
|
||||||
|
40% { transform: scale(1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-footer {
|
||||||
|
margin-top: 48px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-footer p {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: #9ca3af;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.login-left { display: none; }
|
||||||
|
.login-right { width: 100%; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
7
OnceLove/oncelove-graphrag/frontend/vite.config.js
Normal file
7
OnceLove/oncelove-graphrag/frontend/vite.config.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
|
||||||
|
// https://vite.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [vue()],
|
||||||
|
})
|
||||||
1
OnceLove/oncelove-graphrag/test.json
Normal file
1
OnceLove/oncelove-graphrag/test.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"text":"我今天跟她吵架了,她说我前两天不给她买花,说我准备的求婚仪式太敷衍"}
|
||||||
2
OnceLove/oncelove-graphrag/test.ps1
Normal file
2
OnceLove/oncelove-graphrag/test.ps1
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
$body = Get-Content -Path test.json -Raw -Encoding UTF8
|
||||||
|
Invoke-RestMethod -Uri 'http://localhost:3000/analyze' -Method Post -ContentType 'application/json' -Body $body
|
||||||
3
OnceLove/oncelove-graphrag/test_analyze.json
Normal file
3
OnceLove/oncelove-graphrag/test_analyze.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"text": "我今天跟她吵架了,她说我前两天不给她买花,说我准备的求婚仪式太敷衍"
|
||||||
|
}
|
||||||
6
OnceLove/oncelove-graphrag/test_analyze.ps1
Normal file
6
OnceLove/oncelove-graphrag/test_analyze.ps1
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
$headers = @{"Content-Type" = "application/json"}
|
||||||
|
$body = @"
|
||||||
|
{"text":"昨天我给她准备了生日惊喜,她很开心,说这是她过得最难忘的一个生日"}
|
||||||
|
"@
|
||||||
|
$response = Invoke-RestMethod -Uri "http://localhost:3000/analyze" -Method Post -Headers $headers -Body $body
|
||||||
|
$response | ConvertTo-Json -Depth 10
|
||||||
1
OnceLove/oncelove-graphrag/test_input.json
Normal file
1
OnceLove/oncelove-graphrag/test_input.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"text":"昨天我给她准备了生日惊喜,她很开心"}
|
||||||
8
OnceLove/oncelove-graphrag/test_llm.ps1
Normal file
8
OnceLove/oncelove-graphrag/test_llm.ps1
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
$headers = @{"Authorization" = "Bearer sk-413a8289cada4695a18d8982e5f63f3c"; "Content-Type" = "application/json"}
|
||||||
|
$messages = @(
|
||||||
|
@{ role = "system"; content = "You are an entity relation expert. Extract persons, events, topics, relations from text. Return JSON only: {persons:[],events:[],topics:[],relations:[]}" }
|
||||||
|
@{ role = "user"; content = "I had a fight with her today. She said I did not buy her flowers the day before yesterday and said my marriage proposal was too casual" }
|
||||||
|
)
|
||||||
|
$body = @{ model = "qwen-plus"; messages = $messages; temperature = 0.7 } | ConvertTo-Json -Depth 10
|
||||||
|
$response = Invoke-RestMethod -Uri "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions" -Method Post -Headers $headers -Body $body
|
||||||
|
$response.choices[0].message.content
|
||||||
5
OnceLove/产品介绍.md
Normal file
5
OnceLove/产品介绍.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
OnceLove - AI恋爱实时分析辅助及多轮记忆推理决策系统
|
||||||
|
|
||||||
|
## 1. 背景与目标
|
||||||
|
|
||||||
|
OnceLove 面向恋爱沟通场景,提供“实时理解 + 多轮记忆 + 策略建议”的智能辅助能力,
|
||||||
Reference in New Issue
Block a user