# aiwork **Repository Path**: wangplain/aiwork ## Basic Information - **Project Name**: aiwork - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-13 - **Last Updated**: 2025-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 遥感智能解译平台 ## 项目概述 遥感智能解译平台是一个集成了地理信息定位、数据查询、深度学习处理与知识问答的智能系统。该平台能够处理用户的自然语言查询,识别用户意图,自动构建工作流,并通过调用相应的工具服务来完成用户需求。 ## 用户意图识别 系统能够识别用户输入中的意图,并执行相应的操作。目前支持以下意图类型: | 意图ID | 意图类型 | 描述 | 示例查询 | |-------|---------|------|----------| | 1 | 定位与介绍 | 在地图上定位特定地点并提供相关介绍 | "珠穆朗玛峰在哪里?" | | 2 | 图层查询加载展示 | 查询并展示指定的遥感数据 | "查询上海市2024年高分数据" | | 3 | 产品生成 | 使用深度学习算法生成遥感分析产品 | "进行2024年上海市土地利用分类" | | 4 | 知识问答 | 回答用户关于遥感或地理知识的问题 | "什么是NDVI指数?" | | 5 | 结果分析 | 分析已生成的遥感处理结果 | "分析上海市近五年来的城市扩张情况" | | 6 | 查询所有数据 | 用户希望查询所有数据 | "查询所有数据"、"展示所有卫星图像" | | 0 | 普通聊天 | 与用户进行一般性对话 | "你好,今天天气怎么样?" | ## 工具库 遥感智能解译平台提供以下核心工具服务,用于地理信息展示、数据查询和算法处理: | 工具名称 | 描述 | 端点 | 操作类型 | |---------|------|------|---------| | geo_location | 地理定位服务 | queryLocation | locate | | layer_render | 图层渲染服务 | findLayer | layer_render | | data_query | 统一数据获取(按条件组合检索) | queryData | query_data | | data_query_all | 查询所有数据 | queryAllData | query_all_data | | algorithm_call | 算法调用服务 | AlgorithmCall | algorithm_call/param_algorithm_call | ## 详细说明 ### 1. geo_location 地理定位服务,按照地点名称查询位置并在地图上显示。 **参数:** - `location`: 字符串,地点名称 **返回值:** 无 **示例:** ```json { "tool": "geo_location", "endpoint": "queryLocation", "action_type": "locate", "params": { "location": "北京" } } ``` ### 2. layer_render 图层渲染服务,按照图层文件名查询图层并在地图上显示,支持shapefile和tif格式。 **参数:** - `name`: 字符串,图层文件名 - `cascade`: 布尔值,是否级联查询子目录(可选) **返回值:** 无 **示例:** ```json { "tool": "layer_render", "endpoint": "findLayer", "action_type": "layer_render", "params": { "name": "北洪港.tif", "cascade": false } } ``` ### 3. data_query 统一数据获取服务。尽可能从用户问题中识别以下参数,不存在则置为 null;无需提供 wkt,提供 location(地名,后端将自动解析为 wkt;地名需从省/市/区逐级到具体位置)。 **参数:** - `sensor`: 字符串或 null,例如 `GF-1/6` - `resolution`: 字符串或 null,例如 `2m` - `bands`: 整数或 null,例如 `4` - `time`: 字符串或 null,时间或时间范围,格式 `YYYY-MM-DD`(例如 `2025-01`) - `location`: 字符串或 null,地名(省/市/区/具体地点) **返回值:** 列表,数据列表 **示例:** ```json { "tool": "data_query", "endpoint": "queryData", "action_type": "query_data", "params": { "sensor": "GF-1/6", "resolution": "2m", "bands": 4, "time": "2025-01", "location": "陕西省榆林市" } } ``` ### 4. data_query_all 数据查询服务,查询所有数据信息。 **参数:** 无 **返回值:** 列表,包含所有数据信息 **示例:** ```json { "tool": "data_query_all", "endpoint": "queryAllData", "action_type": "query_all_data", "params": {} } ``` ### 5. algorithm_call 算法调用服务,调用指定深度学习算法(如路网提取,风机监测等)进行数据处理,并将结果显示在地图上。 **参数:** - `algorithm`: 字符串,算法名称 **返回值:** 无 **示例:** ```json { "tool": "algorithm_call", "endpoint": "AlgorithmCall", "action_type": "algorithm_call", "params": { "algorithm": "路网提取" } } ``` ## 工作流示例 根据不同的用户意图,系统会自动构建相应的工作流: ### 定位与介绍工作流 ```json { "workflow_name": "地点定位与介绍", "description": "定位用户请求的地点并提供相关介绍", "intent_type": 1, "steps": [ { "tool": "geo_location", "endpoint": "queryLocation", "action_type": "locate", "params": { "location": "珠穆朗玛峰" } } ] } ``` ### 数据查询与展示工作流 ```json { "workflow_name": "数据查询与展示", "description": "查询并展示用户请求的遥感数据", "intent_type": 2, "steps": [ { "tool": "data_query", "endpoint": "queryData", "action_type": "query_data", "params": { "sensor": "{sensor}", "resolution": "{resolution}", "bands": "{bands}", "time": "{time}", "location": "{location}" } } ] } ``` ### 产品生成工作流 ```json { "workflow_name": "土地利用分类", "description": "使用深度学习算法进行土地利用分类", "intent_type": 3, "steps": [ { "tool": "data_query", "endpoint": "queryData", "action_type": "query_data", "params": { "sensor": "{sensor}", "resolution": "{resolution}", "bands": "{bands}", "time": "{time}", "location": "{location}" } }, { "tool": "algorithm_call", "endpoint": "AlgorithmCall", "action_type": "algorithm_call", "params": { "algorithm": "土地利用分类" } } } ``` ### 知识问答工作流 ```json { "workflow_name": "知识问答", "description": "回答用户关于遥感或地理知识的问题", "intent_type": 4, "question": "什么是NDVI指数?", "answer_context": "根据上下文回答用户问题", "steps": [] } ``` ### 结果分析工作流 ```json { "workflow_name": "结果分析", "description": "分析用户指定的遥感处理结果", "intent_type": 5, "steps": [ { "tool": "layer_render", "endpoint": "findLayer", "action_type": "layer_render", "params": { "name": "上海市城市扩张分析结果.tif", "cascade": true } } ] } ``` ## 接口列表 ### 查询处理 1. **处理用户查询** - POST `/api/v1/query` 2. **获取会话历史** - GET `/api/v1/get_history` 3. **清除会话历史** - POST `/api/v1/clear_session` ### LLM Key 管理 1. **获取当前 Key 信息** - GET `/api/v1/llm/key/info` 2. **切换激活 Key** - POST `/api/v1/llm/key/switch` ### 工作流执行(动态调整) 1. **创建并初始化工作流** - POST `/api/v1/workflows` 2. **获取工作流状态** - GET `/api/v1/workflows/{workflow_id}/status` 3. **步骤开始上报** - POST `/api/v1/workflows/{workflow_id}/steps/{step_id}/start` 4. **步骤成功上报** - POST `/api/v1/workflows/{workflow_id}/steps/{step_id}/success` 5. **步骤失败上报(自动调整)** - POST `/api/v1/workflows/{workflow_id}/steps/{step_id}/failure` 6. **手动提交调整后的工作流** - POST `/api/v1/workflows/{workflow_id}/adjust` ### 相似度计算 1. **查找最相似查询** - POST `/api/v1/find_similar` 2. **查找N个最相似查询** - POST `/api/v1/find_top_similar` ### 缓存管理 1. **清除所有缓存** - POST `/api/v1/clear_cache` 2. **添加查询到缓存** - POST `/api/v1/add_to_cache` 3. **批量添加到缓存** - POST `/api/v1/batch_add_to_cache` 4. **从文件加载缓存** - POST `/api/v1/load_cache_from_file` 5. **导出缓存到文件** - POST `/api/v1/export_cache_to_file` 6. **设置相似度阈值** - POST `/api/v1/set_threshold` ## 接口详情 ### 处理用户查询 **请求**:POST `/api/v1/query` ```json { "query": "上海市在哪里?它有多大?", // 用户查询内容 "session_id": "default", // 会话ID,可选 "use_cache": true, // 是否使用缓存,可选 "topic": "agent" // MQTT主题,可选 } ``` **响应**: ```json { "code": 200, "data": { "response": "上海市位于中国东部...", "intent": 1, "workflow": {...}, "session_id": "default", "cache_used": true }, "message": "查询处理成功" } ``` ### 查找最相似查询 **请求**:POST `/api/v1/find_similar` ```json { "query": "如何提取遥感影像中的水体", // 输入查询 "queryList": [ // 候选查询列表 "遥感影像中水体提取方法", "如何从遥感影像中检测水体", "水体提取的遥感影像处理方法" ] } ``` **响应**: ```json { "code": 200, "data": { "query": "如何提取遥感影像中的水体", "mostSimilar": "遥感影像中水体提取方法", "similarity": 0.92 }, "message": "查询成功" } ``` ### 查找N个最相似查询 **请求**:POST `/api/v1/find_top_similar` ```json { "query": "如何提取遥感影像中的水体", // 输入查询 "queryList": [ // 候选查询列表 "遥感影像中水体提取方法", "如何从遥感影像中检测水体", "水体提取的遥感影像处理方法", "遥感影像水体检测步骤" ], "topN": 3 // 返回结果数量,可选 } ``` ### LLM Key 管理 #### 获取当前 Key 信息 - GET `/api/v1/llm/key/info` 响应示例: ```json { "code": 200, "data": { "active_key": "cheap", "masked_key": "sk-hC...9b39", "available_keys": ["cheap", "stable"] }, "message": "获取当前 Key 信息成功" } ``` #### 切换激活 Key - POST `/api/v1/llm/key/switch` 请求: ```json { "profile": "stable" } // cheap/dev 或 stable/prod ``` 响应: ```json { "code": 200, "data": { "active_key": "stable", "masked_key": "sk-...", "available_keys": ["cheap","stable"] }, "message": "已切换为 stable Key" } ``` ### 工作流执行(动态调整) #### 创建并初始化工作流 - POST `/api/v1/workflows` 请求: ```json { "query": "请查询2025年1月陕西榆林市GF-1/6 2m 四波段影像并展示", "session_id": "default", "use_cache": true, "topic": "agent" } ``` 响应: ```json { "code": 200, "data": { "workflow_id": "wf-xxxxxx", "version": 1, "ready_steps": ["step-..."], "initial_workflow": {"workflow_name": "...", "steps": [...]}, "intent": 2, "cache_used": false, "response": "..." }, "message": "创建并初始化工作流成功" } ``` #### 步骤开始/成功/失败上报 - POST `/api/v1/workflows/{workflow_id}/steps/{step_id}/start` - POST `/api/v1/workflows/{workflow_id}/steps/{step_id}/success` 成功上报请求示例: ```json { "outputs": { "location_bbox": "...", "asset_ids": ["..."] } } ``` 成功上报响应示例: ```json { "code": 200, "data": { "ok": true, "ready_steps": ["step-..."] }, "message": "步骤成功已记录" } ``` - POST `/api/v1/workflows/{workflow_id}/steps/{step_id}/failure` 失败上报请求示例: ```json { "error": { "message": "KB timeout", "code": "KB_TIMEOUT" } } ``` 失败上报响应(自动调整后): ```json { "code": 200, "data": { "failed": { "failed_step_id": "step-x", "completed_step_ids": ["step-a"], "context_keys": ["location_bbox"] }, "adjusted": { "version": 2, "resume_plan": ["step-y"], "changed_step_ids": ["step-y"], "skipped_step_ids": ["step-a"] }, "new_workflow": { "workflow_name": "...", "steps": [...] } }, "message": "步骤失败已记录并已自动调整工作流" } ``` #### 手动提交调整后的工作流 - POST `/api/v1/workflows/{workflow_id}/adjust` 请求: ```json { "new_workflow": { "workflow_name": "...", "steps": [...] } } ``` 响应: ```json { "code": 200, "data": { "version": 2, "resume_plan": ["step-y"] }, "message": "工作流已调整并可继续执行" } ``` **响应**: ```json { "code": 200, "data": { "query": "如何提取遥感影像中的水体", "topResults": [ { "result": "遥感影像中水体提取方法", "similarity": 0.92 }, { "result": "如何从遥感影像中检测水体", "similarity": 0.89 }, { "result": "水体提取的遥感影像处理方法", "similarity": 0.85 } ], "count": 3 }, "message": "查询成功" } ``` ### 设置相似度阈值 **请求**:POST `/api/v1/set_threshold` ```json { "threshold": 0.75 // 相似度阈值,0-1之间 } ``` **响应**: ```json { "code": 200, "data": {}, "message": "相似度阈值已设置为 0.75" } ``` ### 批量添加到缓存 **请求**:POST `/api/v1/batch_add_to_cache` ```json [ { "query": "上海市在哪里?", "answer": { "response": "上海市位于中国东部...", "intent": 1, "workflow": {} } }, { "query": "北京市在哪里?", "answer": { "response": "北京市位于中国北部...", "intent": 1, "workflow": {} } } ] ``` **响应**: ```json { "code": 200, "data": { "success_count": 2, "failed_count": 0, "failed_items": [] }, "message": "批量添加到缓存完成" } ``` ### 结果分析接口 **请求**:POST `/api/v1/result_analysis` **请求示例**: ```json { "algorithm_name": "中文名称", "description": "不连沟-生态要素分类模型解译结果-要素提取", "data_type": "shp", //tif|shp "result": { "shape_type": "polygon", //line| polygon "count": 3, "total_area":"2300000", //总面积 "avg_score":"0.8653", //平均分 "data_description":"整体描述,什么方向、地方数据多,集中,什么地方稀疏,分布较少", "data_list": [ { "id": 0, //id "title": "", "color": "red", "sum_area": "30000", //面积 "lang_description": "", //语言描述 "properties": [ //这里的properties对应shape的属性值,每个shape属性值会不相同 { "name": "collapse" }, { "score": 0.72833 } ] }, { "id": 1, "title": "", "color": "red", "sum_area": "20000", "lang_description": "", "properties": [ { "name": "collapse" }, { "score": 0.89581 } ] }, { "id": 2, "title": "", "color": "red", "sum_area": "10000", "lang_description": "", "properties": [ { "name": "collapse" }, { "score": 0.38588 } ] } ] } } ``` **响应示例**: ```json { "code": 200, "data": { "analysis_result": "文本内容", "confidence": 0.92, "keywords": ["积极", "满意"], "analysis_time": "2024-02-20T15:30:45Z" }, "message": "结果分析成功" } ```