Skip to content

Commit

Permalink
fix: 修复openai base64图片格式错误, 更新 Telegram 图片传输模式为 base64
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Dec 12, 2024
1 parent 84e3212 commit 7060d00
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/buildinfo.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/lib/core/src/agent/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
LLMChatParams,
} from './types';
import { ENV } from '#/config';
import { imageToBase64String } from '#/utils/image';
import { imageToBase64String, renderBase64DataURI } from '#/utils/image';
import { requestChatCompletions } from './request';
import { convertStringToResponseMessages, extractImageContent, loadModelsList } from './utils';

Expand All @@ -29,8 +29,8 @@ async function renderOpenAIMessage(item: HistoryItem, supportImage?: boolean): P
const data = extractImageContent(content.image);
if (data.url) {
if (ENV.TELEGRAM_IMAGE_TRANSFER_MODE === 'base64') {
contents.push(await imageToBase64String(data.url).then(({ data }) => {
return { type: 'image_url', image_url: { url: data } };
contents.push(await imageToBase64String(data.url).then((data) => {
return { type: 'image_url', image_url: { url: renderBase64DataURI(data) } };
}));
} else {
contents.push({ type: 'image_url', image_url: { url: data.url } });
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class EnvironmentConfig {
// 默认选择次低质量的图片
TELEGRAM_PHOTO_SIZE_OFFSET = 1;
// 向LLM优先传递图片方式:url, base64
TELEGRAM_IMAGE_TRANSFER_MODE = 'url';
TELEGRAM_IMAGE_TRANSFER_MODE = 'base64';
// 模型列表列数
MODEL_LIST_COLUMNS = 1;

Expand Down
4 changes: 2 additions & 2 deletions packages/lib/core/src/config/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const BUILD_TIMESTAMP = 1732966958;
export const BUILD_VERSION = '239539c';
export const BUILD_TIMESTAMP = 1733984023;
export const BUILD_VERSION = '84e3212';
2 changes: 0 additions & 2 deletions packages/lib/core/src/utils/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ function getImageFormatFromBase64(base64String: string): string {
return 'jpeg';
case 'i':
return 'png';
case 'R':
return 'gif';
case 'U':
return 'webp';
default:
Expand Down

0 comments on commit 7060d00

Please sign in to comment.