图片OCR结果自动隐藏格式化后再展示
This commit is contained in:
+15
-12
@@ -25,6 +25,11 @@ const MAX_IMAGE_CLIENT_BYTES = 6 * 1024 * 1024
|
||||
// 微信相册/相机原图常有好几兆,超过这个体积先压一档再转 base64
|
||||
const IMAGE_COMPRESS_THRESHOLD = 2 * 1024 * 1024
|
||||
|
||||
// OCR 只负责把图片转成文字:拿到原文后再让 agent 做一次纯格式化,
|
||||
// 这样聊天里展示的是排版好的 markdown,而不是一大段无结构的识别结果。
|
||||
// 这条指令只作为请求内容发给服务端,不进入本地 messages / 聊天记录。
|
||||
const OCR_FORMAT_PROMPT = '把以下内容整理成markdown格式方便显示,不要解读,只格式化,直接输出整理后的内容,不要添加解释或前后说明。\n\n'
|
||||
|
||||
Page({
|
||||
data: {
|
||||
messages: [],
|
||||
@@ -1117,7 +1122,9 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
// 识别成功:文本作为 AI 消息落在图片下方;图片提问不走 WS,这里直接收尾本轮
|
||||
// 识别成功:不直接展示 OCR 原文,而是自动发一条隐藏的「只做 markdown 格式化」
|
||||
// 指令,由 agent 返回排版结果后作为 AI 消息落在图片下方。
|
||||
// 隐藏指令不进 messages / 本地聊天记录,聊天里只看到图片气泡和最终回复。
|
||||
handleImageReply(reply) {
|
||||
if (!reply || reply.code !== 0) {
|
||||
// request 层已尝试静默重登,仍回 401 说明本地 token 确实失效:
|
||||
@@ -1137,18 +1144,14 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
const messages = this.data.messages.slice()
|
||||
messages.push({
|
||||
id: this.createMessageId(),
|
||||
type: 'ai',
|
||||
contentType: 'text',
|
||||
content: text,
|
||||
time: this.formatTime(new Date())
|
||||
})
|
||||
this.resetActiveRequest()
|
||||
this.setData({ messages, isTyping: false, isRecognizing: false })
|
||||
this.flushChatHistory()
|
||||
// OCR 已完成,接下来的格式化交给聊天 WS;activeRequestType 切回 chat,
|
||||
// 连接失败才会走 handleAIError,而不是被图片链路直接吞掉。
|
||||
const imageMessageId = this.activeUserMessageId
|
||||
const requestId = this.createMessageId('req')
|
||||
this.beginRequest(requestId, imageMessageId, 'chat')
|
||||
this.setData({ isRecognizing: false, isTyping: true })
|
||||
this.scrollToBottom()
|
||||
this.sendToAI(`${OCR_FORMAT_PROMPT}${text}`, 'chat', requestId)
|
||||
},
|
||||
|
||||
// 失败复用聊天失败态:标记挂在图片气泡上,点「重试」重走识别
|
||||
|
||||
Reference in New Issue
Block a user