@lobehub/chat 0.103.0 → 0.104.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,8 +59,8 @@ jobs:
59
59
  comment: |
60
60
  ❤️ Great PR @${{ github.event.pull_request.user.login }} ❤️
61
61
 
62
- The growth of project is inseparable from user feedback and contribution, thanks for your contribution!\
63
- 项目的成长离不开用户反馈和贡献,感谢您的贡献!
62
+ The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our [discord](https://discord.com/invite/AYFPHvv2jT) and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.\
63
+ 项目的成长离不开用户反馈和贡献,感谢您的贡献! 如果您对 LobeHub 开发者社区感兴趣,请加入我们的 [discord](https://discord.com/invite/AYFPHvv2jT),然后私信 @arvinxx 或 @canisminor1990。他们会邀请您加入我们的私密开发者频道。我们将会讨论关于 Lobe Chat 的开发,分享和讨论全球范围内的 AI 消息。
64
64
  emoji: 'hooray'
65
65
  pr-emoji: '+1, heart'
66
66
  - name: Remove inactive
package/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 0.104.0](https://github.com/lobehub/lobe-chat/compare/v0.103.1...v0.104.0)
6
+
7
+ <sup>Released on **2023-11-21**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Support using env variable to set regions for OpenAI Edge Functions..
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Support using env variable to set regions for OpenAI Edge Functions., closes [#473](https://github.com/lobehub/lobe-chat/issues/473) ([de6b79e](https://github.com/lobehub/lobe-chat/commit/de6b79e))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
30
+ ### [Version 0.103.1](https://github.com/lobehub/lobe-chat/compare/v0.103.0...v0.103.1)
31
+
32
+ <sup>Released on **2023-11-21**</sup>
33
+
34
+ #### 🐛 Bug Fixes
35
+
36
+ - **misc**: Image optimization in docker standalone build.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **misc**: Image optimization in docker standalone build, closes [#494](https://github.com/lobehub/lobe-chat/issues/494) ([d2bcac3](https://github.com/lobehub/lobe-chat/commit/d2bcac3))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ## [Version 0.103.0](https://github.com/lobehub/lobe-chat/compare/v0.102.4...v0.103.0)
6
56
 
7
57
  <sup>Released on **2023-11-20**</sup>
package/README.md CHANGED
@@ -390,11 +390,12 @@ $ docker run -d -p 3210:3210 \
390
390
 
391
391
  This project provides some additional configuration items set with environment variables:
392
392
 
393
- | Environment Variable | Required | Description | Example |
394
- | -------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
395
- | `OPENAI_API_KEY` | Yes | This is the API key you apply on the OpenAI account page | `sk-xxxxxx...xxxxxx` |
396
- | `OPENAI_PROXY_URL` | No | If you manually configure the OpenAI interface proxy, you can use this configuration item to override the default OpenAI API request base URL | `https://api.chatanywhere.cn/v1`<br/>The default value is<br/>`https://api.openai.com/v1` |
397
- | `ACCESS_CODE` | No | Add a password to access this service; the password should be a 6-digit number or letter | `awCT74` or `e3@09!` |
393
+ | Environment Variable | Required | Description | Example |
394
+ | ------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
395
+ | `OPENAI_API_KEY` | Yes | This is the API key you apply on the OpenAI account page | `sk-xxxxxx...xxxxxx` |
396
+ | `OPENAI_PROXY_URL` | No | If you manually configure the OpenAI interface proxy, you can use this configuration item to override the default OpenAI API request base URL | `https://api.chatanywhere.cn/v1`<br/>The default value is<br/>`https://api.openai.com/v1` |
397
+ | `OPENAI_FUNCTION_REGIONS` | No | When you deploy Lobe-Chat using Vercel and need to specify the region for the Edge Function that handles requests to the OpenAI API, you can use this configuration. The value should be a comma-separated array of strings. | `iad1,sfo1` |
398
+ | `ACCESS_CODE` | No | Add a password to access this service; the password should be a 6-digit number or letter | `awCT74` or `e3@09!` |
398
399
 
399
400
  > \[!NOTE]
400
401
  >
package/README.zh-CN.md CHANGED
@@ -364,11 +364,12 @@ $ docker run -d -p 3210:3210 \
364
364
 
365
365
  本项目提供了一些额外的配置项,使用环境变量进行设置:
366
366
 
367
- | 环境变量 | 类型 | 描述 | 示例 |
368
- | ------------------ | ---- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
369
- | `OPENAI_API_KEY` | 必选 | 这是你在 OpenAI 账户页面申请的 API 密钥 | `sk-xxxxxx...xxxxxx` |
370
- | `OPENAI_PROXY_URL` | 可选 | 如果你手动配置了 OpenAI 接口代理,可以使用此配置项来覆盖默认的 OpenAI API 请求基础 URL | `https://api.chatanywhere.cn/v1`<br/>默认值:<br/>`https://api.openai.com/v1` |
371
- | `ACCESS_CODE` | 可选 | 添加访问此服务的密码,密码应为 6 位数字或字母 | `awCT74` 或 `e3@09!` |
367
+ | 环境变量 | 类型 | 描述 | 示例 |
368
+ | ------------------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
369
+ | `OPENAI_API_KEY` | 必选 | 这是你在 OpenAI 账户页面申请的 API 密钥 | `sk-xxxxxx...xxxxxx` |
370
+ | `OPENAI_PROXY_URL` | 可选 | 如果你手动配置了 OpenAI 接口代理,可以使用此配置项来覆盖默认的 OpenAI API 请求基础 URL | `https://api.chatanywhere.cn/v1`<br/>默认值:<br/>`https://api.openai.com/v1` |
371
+ | `OPENAI_FUNCTION_REGIONS` | 可选 | 当你使用 Vercel 部署 Lobe-Chat,而且有需求指定响应调用 OpenAI 接口的请求的 Edge Function 的 Region 时,可以使用该配置进行配置,该值的类型为逗号分隔的字符串数组 | `iad1,sfo1` |
372
+ | `ACCESS_CODE` | 可选 | 添加访问此服务的密码,密码应为 6 位数字或字母 | `awCT74` 或 `e3@09!` |
372
373
 
373
374
  > \[!NOTE]
374
375
  >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.103.0",
3
+ "version": "0.104.0",
4
4
  "description": "An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -111,6 +111,7 @@
111
111
  "remark-gfm": "^3",
112
112
  "remark-html": "^15",
113
113
  "semver": "^7",
114
+ "sharp": "^0.32.6",
114
115
  "swr": "^2",
115
116
  "systemjs": "^6",
116
117
  "ts-md5": "^1",
@@ -0,0 +1,38 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ import { getPreferredRegion } from './config';
4
+
5
+ // Stub the global process object to safely mock environment variables
6
+ vi.stubGlobal('process', {
7
+ ...process, // Preserve the original process object
8
+ env: { ...process.env }, // Clone the environment variables object for modification
9
+ });
10
+
11
+ describe('getPreferredRegion', () => {
12
+ beforeEach(() => {
13
+ // Reset environment variables before each test case
14
+ vi.restoreAllMocks();
15
+ });
16
+
17
+ it('returns default value when get config error', () => {
18
+ const originalProcess = global.process;
19
+ // @ts-ignore
20
+ global.process = undefined;
21
+ const preferredRegion = getPreferredRegion();
22
+ expect(preferredRegion).toBe('auto');
23
+
24
+ global.process = originalProcess;
25
+ });
26
+
27
+ it('return default value when preferredRegion is empty', () => {
28
+ process.env.OPENAI_FUNCTION_REGIONS = '';
29
+ const preferredRegion = getPreferredRegion();
30
+ expect(preferredRegion).toBe('auto');
31
+ });
32
+
33
+ it('return correct list values when preferredRegion is correctly passed', () => {
34
+ process.env.OPENAI_FUNCTION_REGIONS = 'ida1,sfo1';
35
+ const preferredRegion = getPreferredRegion();
36
+ expect(preferredRegion).toStrictEqual(['ida1', 'sfo1']);
37
+ });
38
+ });
@@ -0,0 +1,15 @@
1
+ import { getServerConfig } from '@/config/server';
2
+
3
+ export const getPreferredRegion = () => {
4
+ try {
5
+ const cfg = getServerConfig();
6
+ if (cfg.OPENAI_FUNCTION_REGIONS.length <= 0) {
7
+ return 'auto';
8
+ }
9
+
10
+ return cfg.OPENAI_FUNCTION_REGIONS;
11
+ } catch (error) {
12
+ console.error('get server config failed, error:', error);
13
+ return 'auto';
14
+ }
15
+ };
@@ -1,9 +1,11 @@
1
1
  import { OpenAIChatStreamPayload } from '@/types/openai/chat';
2
2
 
3
+ import { getPreferredRegion } from '../../config';
3
4
  import { createBizOpenAI } from '../createBizOpenAI';
4
5
  import { createChatCompletion } from './createChatCompletion';
5
6
 
6
7
  export const runtime = 'edge';
8
+ export const preferredRegion = getPreferredRegion();
7
9
 
8
10
  export const POST = async (req: Request) => {
9
11
  const payload = (await req.json()) as OpenAIChatStreamPayload;
@@ -1,9 +1,11 @@
1
1
  import { OpenAISTTPayload } from '@lobehub/tts';
2
2
  import { createOpenaiAudioTranscriptions } from '@lobehub/tts/server';
3
3
 
4
+ import { getPreferredRegion } from '../../config';
4
5
  import { createBizOpenAI } from '../createBizOpenAI';
5
6
 
6
7
  export const runtime = 'edge';
8
+ export const preferredRegion = getPreferredRegion();
7
9
 
8
10
  export const POST = async (req: Request) => {
9
11
  const formData = await req.formData();
@@ -1,9 +1,11 @@
1
1
  import { OpenAITTSPayload } from '@lobehub/tts';
2
2
  import { createOpenaiAudioSpeech } from '@lobehub/tts/server';
3
3
 
4
+ import { getPreferredRegion } from '../../config';
4
5
  import { createBizOpenAI } from '../createBizOpenAI';
5
6
 
6
7
  export const runtime = 'edge';
8
+ export const preferredRegion = getPreferredRegion();
7
9
 
8
10
  export const POST = async (req: Request) => {
9
11
  const payload = (await req.json()) as OpenAITTSPayload;
@@ -39,6 +39,12 @@ describe('getServerConfig', () => {
39
39
  expect(config.USE_AZURE_OPENAI).toBe(false);
40
40
  });
41
41
 
42
+ it('correctly handles values for OPENAI_FUNCTION_REGIONS', () => {
43
+ process.env.OPENAI_FUNCTION_REGIONS = 'iad1,sfo1';
44
+ const config = getServerConfig();
45
+ expect(config.OPENAI_FUNCTION_REGIONS).toStrictEqual(['iad1', 'sfo1']);
46
+ });
47
+
42
48
  it('returns default IMGUR_CLIENT_ID when no environment variable is set', () => {
43
49
  const config = getServerConfig();
44
50
  expect(config.IMGUR_CLIENT_ID).toBe('e415f320d6e24f9');
@@ -27,11 +27,18 @@ export const getServerConfig = () => {
27
27
  throw new Error('[Server Config] you are importing a nodejs-only module outside of nodejs');
28
28
  }
29
29
 
30
+ // region format: iad1,sfo1
31
+ let regions: string[] = [];
32
+ if (process.env.OPENAI_FUNCTION_REGIONS) {
33
+ regions = process.env.OPENAI_FUNCTION_REGIONS.split(',');
34
+ }
35
+
30
36
  return {
31
37
  ACCESS_CODE: process.env.ACCESS_CODE,
32
38
 
33
39
  OPENAI_API_KEY: process.env.OPENAI_API_KEY,
34
40
  OPENAI_PROXY_URL: process.env.OPENAI_PROXY_URL,
41
+ OPENAI_FUNCTION_REGIONS: regions,
35
42
 
36
43
  AZURE_API_KEY: process.env.AZURE_API_KEY,
37
44
  AZURE_API_VERSION: process.env.AZURE_API_VERSION,