mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 19:30:17 +08:00
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:
parent
11b130736c
commit
b1e843973c
@ -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' })
|
||||
|
||||
Loading…
Reference in New Issue
Block a user