Fix AWS Bedrock models not receiving uploaded document content (#9337)

* Initial plan

* Add file content processing to AWS Bedrock client convertMessageToSdkParam method

Co-authored-by: caozhiyuan <3415285+caozhiyuan@users.noreply.github.com>

* Fix file content format to match other AI clients and update tests

Co-authored-by: caozhiyuan <3415285+caozhiyuan@users.noreply.github.com>

* Update src/renderer/src/aiCore/clients/aws/AwsBedrockAPIClient.ts

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: caozhiyuan <3415285+caozhiyuan@users.noreply.github.com>
Co-authored-by: Phantom <59059173+EurFelux@users.noreply.github.com>
This commit is contained in:
caozhiyuan 2025-08-20 18:26:38 +08:00 committed by GitHub
parent 11b130736c
commit b1e843973c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,6 +19,7 @@ import { estimateTextTokens } from '@renderer/services/TokenService'
import {
Assistant,
EFFORT_RATIO,
FileTypes,
GenerateImageParams,
MCPCallToolResponse,
MCPTool,
@ -53,7 +54,7 @@ import {
mcpToolCallResponseToAwsBedrockMessage,
mcpToolsToAwsBedrockTools
} from '@renderer/utils/mcp-tools'
import { findImageBlocks } from '@renderer/utils/messageUtils/find'
import { findImageBlocks, findFileBlocks } from '@renderer/utils/messageUtils/find'
import { t } from 'i18next'
import { BaseApiClient } from '../BaseApiClient'
@ -683,6 +684,30 @@ export class AwsBedrockAPIClient extends BaseApiClient<
}
}
// 处理文件内容
const fileBlocks = findFileBlocks(message)
for (const fileBlock of fileBlocks) {
const file = fileBlock.file
if (!file) {
logger.warn(`No file in the file block. Passed.`, { fileBlock })
continue
}
if ([FileTypes.TEXT, FileTypes.DOCUMENT].includes(file.type)) {
try {
const fileContent = (await window.api.file.read(file.id + file.ext, true)).trim()
if (fileContent) {
parts.push({
text: `${file.origin_name}\n${fileContent}`
})
}
} catch (error) {
logger.error('Error reading file content:', error as Error)
parts.push({ text: `[File: ${file.origin_name} - Failed to read content]` })
}
}
}
// 如果没有任何内容,添加默认文本而不是空文本
if (parts.length === 0) {
parts.push({ text: 'No content provided' })