refactor: improved type safety and consistency for file handling
This commit is contained in:
parent
247d1a1846
commit
66bc9cb3f9
@ -123,7 +123,7 @@ export default class OpenAIProvider extends BaseProvider {
|
|||||||
|
|
||||||
//QwenLM上传图片
|
//QwenLM上传图片
|
||||||
if (this.provider.id === 'qwenlm') {
|
if (this.provider.id === 'qwenlm') {
|
||||||
let qwenlm_image_url: { type: string; image: string }[] = []
|
const qwenlm_image_url: { type: string; image: string }[] = []
|
||||||
|
|
||||||
for (const file of message.files || []) {
|
for (const file of message.files || []) {
|
||||||
if (file.type === FileTypes.IMAGE && isVision) {
|
if (file.type === FileTypes.IMAGE && isVision) {
|
||||||
@ -147,22 +147,22 @@ export default class OpenAIProvider extends BaseProvider {
|
|||||||
role: message.role,
|
role: message.role,
|
||||||
content: [...parts, ...qwenlm_image_url]
|
content: [...parts, ...qwenlm_image_url]
|
||||||
} as ChatCompletionMessageParam
|
} as ChatCompletionMessageParam
|
||||||
} else {
|
}
|
||||||
for (const file of message.files || []) {
|
|
||||||
if (file.type === FileTypes.IMAGE && isVision) {
|
for (const file of message.files || []) {
|
||||||
const image = await window.api.file.base64Image(file.id + file.ext)
|
if (file.type === FileTypes.IMAGE && isVision) {
|
||||||
parts.push({
|
const image = await window.api.file.base64Image(file.id + file.ext)
|
||||||
type: 'image_url',
|
parts.push({
|
||||||
image_url: { url: image.data }
|
type: 'image_url',
|
||||||
})
|
image_url: { url: image.data }
|
||||||
}
|
})
|
||||||
if ([FileTypes.TEXT, FileTypes.DOCUMENT].includes(file.type)) {
|
}
|
||||||
const fileContent = await (await window.api.file.read(file.id + file.ext)).trim()
|
if ([FileTypes.TEXT, FileTypes.DOCUMENT].includes(file.type)) {
|
||||||
parts.push({
|
const fileContent = await (await window.api.file.read(file.id + file.ext)).trim()
|
||||||
type: 'text',
|
parts.push({
|
||||||
text: file.origin_name + '\n' + fileContent
|
type: 'text',
|
||||||
})
|
text: file.origin_name + '\n' + fileContent
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user