Skip to content

Commit

Permalink
fix: base64 image undefined (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimsky authored Apr 17, 2024
1 parent 3d04697 commit 78d50e1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/service/core/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
} from '@fastgpt/global/core/ai/type.d';
import axios from 'axios';
import { ChatCompletionRequestMessageRoleEnum } from '@fastgpt/global/core/ai/constants';
import { guessBase64ImageType } from '../../common/file/utils';

/* slice chat context by tokens */
const filterEmptyMessages = (messages: ChatCompletionMessageParam[]) => {
Expand Down Expand Up @@ -242,7 +243,11 @@ export const loadChatImgToBase64 = async (content: string | ChatCompletionConten
responseType: 'arraybuffer'
});
const base64 = Buffer.from(response.data).toString('base64');
item.image_url.url = `data:${response.headers['content-type']};base64,${base64}`;
let imageType = response.headers['content-type'];
if (imageType === undefined) {
imageType = guessBase64ImageType(base64);
}
item.image_url.url = `data:${imageType};base64,${base64}`;
return item;
})
);
Expand Down

0 comments on commit 78d50e1

Please sign in to comment.