Private/fix 2336 log request response#2376
Draft
ljluestc wants to merge 2 commits into
Draft
Conversation
Store truncated user request and model response content in consume logs and display them in logs table.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
close #2336
功能说明
本 PR 实现了 issue #2336 请求的功能:在调用日志中增加用户问题和大模型回复的历史记录。
变更内容
1. 数据模型 (
model/log.go)Log结构体新增两个字段:RequestContent(text):存储用户输入的问题/提示词ResponseContent(text):存储大模型的回复内容RecordConsumeLog函数签名,支持写入请求和响应内容2. 控制器 (
controller/relay-text.go)buildRequestContentSummary()函数:从各类请求中提取有意义的摘要[role] contentextractResponseContentSummary()函数:从响应中提取回复内容3. 工具函数 (
common/utils.go)TruncateStringByRune()函数:按 rune 截断字符串,避免中文被截断成乱码4. 常量配置 (
common/constants.go)ConsumeLogRequestMaxLength = 4000ConsumeLogResponseMaxLength = 40005. 前端 (
web/src/components/LogsTable.js)功能特性
数据库迁移
新字段使用 GORM 的 AutoMigrate,现有数据库会在下次启动时自动添加新列,无需手动迁移。
本地测试方法
1. 后端测试
2. 启动服务测试
3. 验证日志记录
4. 前端测试
访问日志页面,确认新增的「用户问题」和「模型回复」列正常显示。
测试结果
后端测试
API 测试
前端测试
截图
日志列表新增列

长文本截断效果

兼容性
使用场景
按 issue #2336 要求,用户现在可以: