diff --git a/README.md b/README.md index 50e08ef9..235776c3 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,8 @@ All deployment configurations could be configured in the `.env` file or in **Env | OPENAI_API_BASE_URL | api.openai.com | The default address of the requested api | | DISCORD_SERVER_ID | - | Discord server id | | DISCORD_CHANNEL_ID | - | Discord channel id | -| DISCORD_TOKEN | - | Discord token | +| DISCORD_TOKEN | - | Discord token | +| DISCORD_IMAGE_PROXY | - | Discord image proxy url | ### Global Configurations diff --git a/README.zh-CN.md b/README.zh-CN.md index b489356e..95563c3b 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -114,7 +114,8 @@ | OPENAI_API_BASE_URL | api.openai.com | 请求 api 的默认地址 | | DISCORD_SERVER_ID | - | Discord 服务器 id | | DISCORD_CHANNEL_ID | - | Discord 频道 id | -| DISCORD_TOKEN | - | Discord token | +| DISCORD_TOKEN | - | Discord token | +| DISCORD_IMAGE_PROXY | - | Discord 返回图片代理地址 | ### 全局配置 diff --git a/src/configs/index.ts b/src/configs/index.ts index f0e68b6d..1615a84d 100644 --- a/src/configs/index.ts +++ b/src/configs/index.ts @@ -6,11 +6,13 @@ export const localConversationKey = 'LOCAL_CONVERSATION'; // From https://platform.openai.com/docs/models/model-endpoint-compatibility export const supportedModels = [ 'gpt-4', - 'gpt-4-0314', + 'gpt-4-0613', 'gpt-4-32k', - 'gpt-4-32k-0314', + 'gpt-4-32k-0613', 'gpt-3.5-turbo', - 'gpt-3.5-turbo-0301', + 'gpt-3.5-turbo-0613', + 'gpt-3.5-turbo-16k', + 'gpt-3.5-turbo-16k-0613', ] as const; export type SupportedModel = (typeof supportedModels)[number]; diff --git a/src/configs/server.ts b/src/configs/server.ts index b47a8131..70ba6356 100644 --- a/src/configs/server.ts +++ b/src/configs/server.ts @@ -2,3 +2,5 @@ export const serverGlobalConfigs: { polling: number } = { // load balancer polling step polling: 0, }; + +export const discordImageCdn = 'cdn.discordapp.com'; diff --git a/src/pages/api/images.ts b/src/pages/api/images.ts index 170e609f..05f2b8a4 100644 --- a/src/pages/api/images.ts +++ b/src/pages/api/images.ts @@ -8,6 +8,7 @@ import { type MessageType, type MessageTypeProps, } from 'midjourney-fetch'; +import { discordImageCdn } from '@configs/server'; import { apiKeyStrategy, apiKeys, @@ -17,6 +18,7 @@ import { dicordServerId, discordChannelId, discordToken, + discordImageProxy, } from '.'; export { config }; @@ -88,7 +90,23 @@ export const get: APIRoute = async ({ request }) => { const message = await midjourney.getMessage(prompt, options); if (message) { - return new Response(JSON.stringify(message), { status: 200 }); + return new Response( + JSON.stringify( + discordImageProxy + ? { + ...message, + attachments: message.attachments.map((attachment) => ({ + ...attachment, + url: attachment.url.replace( + discordImageCdn, + discordImageProxy + ), + })), + } + : message + ), + { status: 200 } + ); } return new Response(JSON.stringify({ msg: 'No content found' }), { diff --git a/src/pages/api/index.ts b/src/pages/api/index.ts index 5457cdc9..9d67547f 100644 --- a/src/pages/api/index.ts +++ b/src/pages/api/index.ts @@ -38,6 +38,10 @@ export const discordChannelId = export const discordToken = import.meta.env.DISCORD_TOKEN || process.env.DISCORD_TOKEN; +export const discordImageProxy = ( + import.meta.env.DISCORD_IMAGE_PROXY || process.env.DISCORD_IMAGE_PROXY +)?.replace(/^https?:\/\//i, ''); + /** * https://vercel.com/docs/concepts/edge-network/regions#region-list * disable hkg1 HongKong