Skip to content

Commit 1e21674

Browse files
authored
feat: update chat model and support DISCORD_IMAGE_PROXY (#82)
1 parent 650d300 commit 1e21674

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ All deployment configurations could be configured in the `.env` file or in **Env
103103
| OPENAI_API_BASE_URL | api.openai.com | The default address of the requested api |
104104
| DISCORD_SERVER_ID | - | Discord server id |
105105
| DISCORD_CHANNEL_ID | - | Discord channel id |
106-
| DISCORD_TOKEN | - | Discord token |
106+
| DISCORD_TOKEN | - | Discord token |
107+
| DISCORD_IMAGE_PROXY | - | Discord image proxy url |
107108

108109

109110
### Global Configurations

README.zh-CN.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@
114114
| OPENAI_API_BASE_URL | api.openai.com | 请求 api 的默认地址 |
115115
| DISCORD_SERVER_ID | - | Discord 服务器 id |
116116
| DISCORD_CHANNEL_ID | - | Discord 频道 id |
117-
| DISCORD_TOKEN | - | Discord token |
117+
| DISCORD_TOKEN | - | Discord token |
118+
| DISCORD_IMAGE_PROXY | - | Discord 返回图片代理地址 |
118119

119120

120121
### 全局配置

src/configs/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ export const localConversationKey = 'LOCAL_CONVERSATION';
66
// From https://platform.openai.com/docs/models/model-endpoint-compatibility
77
export const supportedModels = [
88
'gpt-4',
9-
'gpt-4-0314',
9+
'gpt-4-0613',
1010
'gpt-4-32k',
11-
'gpt-4-32k-0314',
11+
'gpt-4-32k-0613',
1212
'gpt-3.5-turbo',
13-
'gpt-3.5-turbo-0301',
13+
'gpt-3.5-turbo-0613',
14+
'gpt-3.5-turbo-16k',
15+
'gpt-3.5-turbo-16k-0613',
1416
] as const;
1517

1618
export type SupportedModel = (typeof supportedModels)[number];

src/configs/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ export const serverGlobalConfigs: { polling: number } = {
22
// load balancer polling step
33
polling: 0,
44
};
5+
6+
export const discordImageCdn = 'cdn.discordapp.com';

src/pages/api/images.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type MessageType,
99
type MessageTypeProps,
1010
} from 'midjourney-fetch';
11+
import { discordImageCdn } from '@configs/server';
1112
import {
1213
apiKeyStrategy,
1314
apiKeys,
@@ -17,6 +18,7 @@ import {
1718
dicordServerId,
1819
discordChannelId,
1920
discordToken,
21+
discordImageProxy,
2022
} from '.';
2123

2224
export { config };
@@ -88,7 +90,23 @@ export const get: APIRoute = async ({ request }) => {
8890
const message = await midjourney.getMessage(prompt, options);
8991

9092
if (message) {
91-
return new Response(JSON.stringify(message), { status: 200 });
93+
return new Response(
94+
JSON.stringify(
95+
discordImageProxy
96+
? {
97+
...message,
98+
attachments: message.attachments.map((attachment) => ({
99+
...attachment,
100+
url: attachment.url.replace(
101+
discordImageCdn,
102+
discordImageProxy
103+
),
104+
})),
105+
}
106+
: message
107+
),
108+
{ status: 200 }
109+
);
92110
}
93111

94112
return new Response(JSON.stringify({ msg: 'No content found' }), {

src/pages/api/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export const discordChannelId =
3838
export const discordToken =
3939
import.meta.env.DISCORD_TOKEN || process.env.DISCORD_TOKEN;
4040

41+
export const discordImageProxy = (
42+
import.meta.env.DISCORD_IMAGE_PROXY || process.env.DISCORD_IMAGE_PROXY
43+
)?.replace(/^https?:\/\//i, '');
44+
4145
/**
4246
* https://vercel.com/docs/concepts/edge-network/regions#region-list
4347
* disable hkg1 HongKong

0 commit comments

Comments
 (0)