# 上下文服务 **Repository Path**: y00854865/context_service ## Basic Information - **Project Name**: 上下文服务 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-15 - **Last Updated**: 2026-05-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 上下文服务 有个接口如下: ``` 请求body { "user_id": "", "sub_user_id": "", "session_id": "", "current_agent": "", "query_type": "qa", "limit_qa_rounds": 100, "max_qa_tokens": 2000, "query": "", } 响应body { "context": { "qa_list": [ { "context_id": "", "label": "xx", "owner_agent": "" "query": { "role": "user", "content": "xx" }, "answer": { "role": "assistant", "content": "xx" }, "re_write_query": "xx", "custom_summary": "", "date": "xxx" } ], "abstract_qa": [ { "context_id": "", "query": { "role": "user", "content": "xx" }, "answer": { "role": "assistant", "content": "xx" } } ] }, "context_msg": [ { "context_id": "", "query": { "role": "user", "content": "xx" }, "answer": { "role": "assistant", "content": "xx" } } ] }, "related_qa": [""], "long_memory": [""] } ``` 前提是abstract_qa、qa_list、related_qa、long_memory都有值,且格式如下:现在需要帮忙设计: rapidjson::Document doc(rapidjson::kObjectType); auto alloc = doc.GetAllocator(); doc.SetObject(); Value context(kObjectType); Value relatedQa(kArrayType); Value qaList(kArrayType); Value abstractQA(kArrayType); Value longMemory(kArrayType); Value rewriteQuery; rewriteQuery.SetString(rewriteQ.c_str(), rewriteQ.length(), alloc); 最终需要生成 // 生成3K上下文窗口限制的context_msg Value contextMsg(kArrayType); BuildContextMsgAdaptive(qaList, abstractQA, contextMsg, alloc, 3000); context.AddMember("context_msg", contextMsg, alloc); 在context_msg中添加(和abstract_qa、qa_list格式一致)上下文,但是要求要做一个窗口限制,即context_msg中最大支持3K上下文,设计一个算法实现这个窗口,context_msg中的值来源可以用qa_list(原始qa),abstract_qa(压缩之后的qa)获取,看如何分配qa_list和abstract_qa中的值,机能满足能够获取到更多上下文,同时还不超过3K #### 介绍 {**以下是 Gitee 平台说明,您可以替换此简介** Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} #### 软件架构 软件架构说明 #### 安装教程 1. xxxx 2. xxxx 3. xxxx #### 使用说明 1. xxxx 2. xxxx 3. xxxx #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)