@lobehub/chat 0.150.0 → 0.150.2

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.150.2](https://github.com/lobehub/lobe-chat/compare/v0.150.1...v0.150.2)
6
+
7
+ <sup>Released on **2024-04-27**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Fix display error when using `DEFAULT_AGENT_CONFIG` env.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Fix display error when using `DEFAULT_AGENT_CONFIG` env, closes [#2231](https://github.com/lobehub/lobe-chat/issues/2231) ([42bc734](https://github.com/lobehub/lobe-chat/commit/42bc734))
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.150.1](https://github.com/lobehub/lobe-chat/compare/v0.150.0...v0.150.1)
31
+
32
+ <sup>Released on **2024-04-27**</sup>
33
+
34
+ #### 🐛 Bug Fixes
35
+
36
+ - **misc**: Fix display error when using DEFAULT_AGENT_CONFIG env.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **misc**: Fix display error when using DEFAULT_AGENT_CONFIG env ([e46215c](https://github.com/lobehub/lobe-chat/commit/e46215c))
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.150.0](https://github.com/lobehub/lobe-chat/compare/v0.149.6...v0.150.0)
6
56
 
7
57
  <sup>Released on **2024-04-26**</sup>
package/README.md CHANGED
@@ -262,12 +262,12 @@ Our marketplace is not just a showcase platform but also a collaborative space.
262
262
 
263
263
  | Recent Submits | Description |
264
264
  | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
265
+ | [Jailbreak Assistant DAN](https://chat-preview.lobehub.com/market?agent=gpt-4-dan-assistant)<br/><sup>By **[MapleEve](https://github.com/MapleEve)** on **2024-04-26**</sup> | Bypass OpenAI review mechanism, ChatGPT after jailbreak<br/>`creative` `artificial-intelligence` `conversation` `jailbreak` |
266
+ | [TailwindHelper](https://chat-preview.lobehub.com/market?agent=tailwind-helper)<br/><sup>By **[aototo](https://github.com/aototo)** on **2024-04-26**</sup> | TailwindHelper is a professional frontend designer with a solid foundation in design theory and rich practical experience. Created by a leading software development company, it aims to help developers and designers accelerate the development process of web interfaces. TailwindHelper is proficient in the Tailwind CSS framework and can translate complex design requirements into efficient and responsive CSS class names.<br/>`tailwindcss` `css` `tailwind-helper` |
265
267
  | [yapi JSON-SCHEMA to Typescript](https://chat-preview.lobehub.com/market?agent=yapi-ts-helper)<br/><sup>By **[zcf0508](https://github.com/zcf0508)** on **2024-04-26**</sup> | Specializes in converting JSON schema to TypeScript types.<br/>`typescript` `development` |
266
268
  | [Chinese Academic Paper Editor](https://chat-preview.lobehub.com/market?agent=chinese-paper-polishing)<br/><sup>By **[y22emc2](https://github.com/y22emc2)** on **2024-04-15**</sup> | As an assistant for improving Chinese academic paper writing, your task is to enhance the provided text in terms of spelling, grammar, clarity, conciseness, and overall readability, to improve the text's academic standards and literary quality. This includes breaking down long sentences, reducing repetition, and providing improvement suggestions. Please provide the corrected version of the text first, then list the modifications in the markdown table below, along with the reasons for the changes.<br/>`academic-paper-writing` `proofreading` `text-editing` |
267
- | [Biology Professor](https://chat-preview.lobehub.com/market?agent=bio-professor)<br/><sup>By **[luxiangze](https://github.com/luxiangze)** on **2024-04-13**</sup> | As a biology professor, you will receive questions and concepts about biology. Please explain these questions and concepts in specific and concise language, and try to use practical examples to illustrate them to help your audience better understand. Please ensure that your explanations are accurate and clear, and try to encourage creative and flexible answers. Respond in Chinese.<br/>`biology` |
268
- | [Master of Fortune Telling](https://chat-preview.lobehub.com/market?agent=fortune-teller)<br/><sup>By **[kamilkenrich](https://github.com/kamilkenrich)** on **2024-04-13**</sup> | Specializes in numerology, divination, astrology, and blood type analysis<br/>`numerology` `divination` `astrology` `psychology` `blood-type` `constellation` |
269
269
 
270
- > 📊 Total agents: [<kbd>**241**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
270
+ > 📊 Total agents: [<kbd>**243**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
271
271
 
272
272
  <!-- AGENT LIST -->
273
273
 
package/README.zh-CN.md CHANGED
@@ -248,14 +248,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
248
248
 
249
249
  <!-- AGENT LIST -->
250
250
 
251
- | 最近新增 | 助手说明 |
252
- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
253
- | [yapi JSON-SCHEMA to Typescript](https://chat-preview.lobehub.com/market?agent=yapi-ts-helper)<br/><sup>By **[zcf0508](https://github.com/zcf0508)** on **2024-04-26**</sup> | 擅长将 JSON schema 转换为 TypeScript 类型。<br/>`typescript` `开发` |
254
- | [中文论文编辑师](https://chat-preview.lobehub.com/market?agent=chinese-paper-polishing)<br/><sup>By **[y22emc2](https://github.com/y22emc2)** on **2024-04-15**</sup> | 作为一名中文学术论文写作改进助理,你的任务是改进所提供文本的拼写、语法、清晰、简洁和整体可读性,提高文本的学术规范性、文学性,同时分解长句,减少重复,并提供改进建议。请先提供文本的更正版本,然后在 markdown 表格中列出修改的内容,并给出修改的理由。<br/>`学术论文写作` `校对` `文本编辑` |
255
- | [生物学教授](https://chat-preview.lobehub.com/market?agent=bio-professor)<br/><sup>By **[luxiangze](https://github.com/luxiangze)** on **2024-04-13**</sup> | 作为一位生物学教授,您将收到关于生物学的问题和概念,请用具体而简明的语言解释这些问题和概念,并尽量使用实际例子进行说明,以帮助您的听众更好地理解。请确保您的解释准确而清晰,并试图鼓励创造性和灵活性的答案。用中文回答<br/>`生物` |
256
- | [命理大师](https://chat-preview.lobehub.com/market?agent=fortune-teller)<br/><sup>By **[kamilkenrich](https://github.com/kamilkenrich)** on **2024-04-13**</sup> | 擅长命理学、占卜预测、占星术和血型学分析<br/>`命理学、占卜、占星学、心理学、血型、星座` |
257
-
258
- > 📊 Total agents: [<kbd>**241**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
251
+ | 最近新增 | 助手说明 |
252
+ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
253
+ | [越狱助手 DAN](https://chat-preview.lobehub.com/market?agent=gpt-4-dan-assistant)<br/><sup>By **[MapleEve](https://github.com/MapleEve)** on **2024-04-26**</sup> | 突破 OpenAI 审核机制,越狱之后的 ChatGPT<br/>`创意` `人工智能` `对话` `越狱` |
254
+ | [TailwindHelper](https://chat-preview.lobehub.com/market?agent=tailwind-helper)<br/><sup>By **[aototo](https://github.com/aototo)** on **2024-04-26**</sup> | TailwindHelper 是一位专业的前端设计师,拥有深厚的设计理论基础和丰富的实践经验。它由一家领先的软件开发公司创建,旨在帮助开发者和设计师加速 Web 界面的开发过程。TailwindHelper 精通 Tailwind CSS 框架,并能够理解复杂的设计要求,转化为高效且响应式的 CSS 类名。<br/>`tailwindcss` `css` `tailwind-helper` |
255
+ | [yapi JSON-SCHEMA to Typescript](https://chat-preview.lobehub.com/market?agent=yapi-ts-helper)<br/><sup>By **[zcf0508](https://github.com/zcf0508)** on **2024-04-26**</sup> | 擅长将 JSON schema 转换为 TypeScript 类型。<br/>`typescript` `开发` |
256
+ | [中文论文编辑师](https://chat-preview.lobehub.com/market?agent=chinese-paper-polishing)<br/><sup>By **[y22emc2](https://github.com/y22emc2)** on **2024-04-15**</sup> | 作为一名中文学术论文写作改进助理,你的任务是改进所提供文本的拼写、语法、清晰、简洁和整体可读性,提高文本的学术规范性、文学性,同时分解长句,减少重复,并提供改进建议。请先提供文本的更正版本,然后在 markdown 表格中列出修改的内容,并给出修改的理由。<br/>`学术论文写作` `校对` `文本编辑` |
257
+
258
+ > 📊 Total agents: [<kbd>**243**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
259
259
 
260
260
  <!-- AGENT LIST -->
261
261
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.150.0",
3
+ "version": "0.150.2",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -82,7 +82,6 @@
82
82
  "dependencies": {
83
83
  "@ant-design/icons": "^5.3.6",
84
84
  "@anthropic-ai/sdk": "^0.18.0",
85
- "@auth/core": "0.28.0",
86
85
  "@aws-sdk/client-bedrock-runtime": "^3.556.0",
87
86
  "@azure/openai": "^1.0.0-beta.12",
88
87
  "@cfworker/json-schema": "^1.12.8",
@@ -96,6 +95,9 @@
96
95
  "@next/third-parties": "^14.2.2",
97
96
  "@sentry/nextjs": "^7.111.0",
98
97
  "@t3-oss/env-nextjs": "^0.10.1",
98
+ "@trpc/client": "next",
99
+ "@trpc/next": "next",
100
+ "@trpc/server": "next",
99
101
  "@vercel/analytics": "^1.2.2",
100
102
  "@vercel/speed-insights": "^1.0.10",
101
103
  "ahooks": "^3.7.11",
@@ -129,6 +131,7 @@
129
131
  "nuqs": "^1.17.1",
130
132
  "ollama": "^0.5.0",
131
133
  "openai": "^4.38.2",
134
+ "pino": "^8.20.0",
132
135
  "polished": "^4.3.1",
133
136
  "posthog-js": "^1.128.1",
134
137
  "query-string": "^9.0.0",
@@ -147,6 +150,7 @@
147
150
  "rtl-detect": "^1.1.2",
148
151
  "semver": "^7.6.0",
149
152
  "sharp": "^0.33.3",
153
+ "superjson": "^2.2.1",
150
154
  "swr": "^2.2.5",
151
155
  "systemjs": "^6.14.3",
152
156
  "ts-md5": "^1.3.1",
@@ -0,0 +1,28 @@
1
+ import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
2
+ import type { NextRequest } from 'next/server';
3
+
4
+ import { pino } from '@/libs/logger';
5
+ import { createContext } from '@/server/context';
6
+ import { appRouter } from '@/server/routers';
7
+
8
+ export const runtime = 'edge';
9
+
10
+ const handler = (req: NextRequest) =>
11
+ fetchRequestHandler({
12
+ /**
13
+ * @link https://trpc.io/docs/v11/context
14
+ */
15
+ createContext: () => createContext(req),
16
+
17
+ endpoint: '/trpc',
18
+
19
+ onError: ({ error, path }) => {
20
+ pino.info(`Error in tRPC handler (edge) on path: ${path}`);
21
+ pino.error(error);
22
+ },
23
+
24
+ req,
25
+ router: appRouter,
26
+ });
27
+
28
+ export { handler as GET, handler as POST };
@@ -6,6 +6,7 @@ import { createStoreUpdater } from 'zustand-utils';
6
6
 
7
7
  import { useIsMobile } from '@/hooks/useIsMobile';
8
8
  import { useEnabledDataSync } from '@/hooks/useSyncData';
9
+ import { useAgentStore } from '@/store/agent';
9
10
  import { useGlobalStore } from '@/store/global';
10
11
 
11
12
  const StoreInitialization = memo(() => {
@@ -14,8 +15,10 @@ const StoreInitialization = memo(() => {
14
15
  s.useFetchUserConfig,
15
16
  s.useInitPreference,
16
17
  ]);
18
+ const useFetchDefaultAgentConfig = useAgentStore((s) => s.useFetchDefaultAgentConfig);
17
19
  // init the system preference
18
20
  useInitPreference();
21
+ useFetchDefaultAgentConfig();
19
22
 
20
23
  const { isLoading } = useFetchServerConfig();
21
24
  useFetchUserConfig(!isLoading);
@@ -0,0 +1,5 @@
1
+ import Pino from 'pino';
2
+
3
+ export const pino = Pino({
4
+ level: process.env.LOG_LEVEL ? process.env.LOG_LEVEL : 'info',
5
+ });
@@ -0,0 +1,13 @@
1
+ import { createTRPCClient, httpBatchLink } from '@trpc/client';
2
+ import superjson from 'superjson';
3
+
4
+ import type { AppRouter } from '@/server/routers';
5
+
6
+ export const trpcClient = createTRPCClient<AppRouter>({
7
+ links: [
8
+ httpBatchLink({
9
+ transformer: superjson,
10
+ url: '/trpc',
11
+ }),
12
+ ],
13
+ });
@@ -0,0 +1,66 @@
1
+ /**
2
+ * This is your entry point to setup the root configuration for tRPC on the server.
3
+ * - `initTRPC` should only be used once per app.
4
+ * - We export only the functionality that we use so we can enforce which base procedures should be used
5
+ *
6
+ * Learn how to create protected base procedures and other things below:
7
+ * @link https://trpc.io/docs/v11/router
8
+ * @link https://trpc.io/docs/v11/procedures
9
+ */
10
+ import { TRPCError, initTRPC } from '@trpc/server';
11
+ import superjson from 'superjson';
12
+
13
+ import type { Context } from '@/server/context';
14
+
15
+ const t = initTRPC.context<Context>().create({
16
+ /**
17
+ * @link https://trpc.io/docs/v11/error-formatting
18
+ */
19
+ errorFormatter({ shape }) {
20
+ return shape;
21
+ },
22
+ /**
23
+ * @link https://trpc.io/docs/v11/data-transformers
24
+ */
25
+ transformer: superjson,
26
+ });
27
+
28
+ /**
29
+ * Create a router
30
+ * @link https://trpc.io/docs/v11/router
31
+ */
32
+ export const router = t.router;
33
+
34
+ /**
35
+ * Create an unprotected procedure
36
+ * @link https://trpc.io/docs/v11/procedures
37
+ **/
38
+ export const publicProcedure = t.procedure;
39
+
40
+ // procedure that asserts that the user is logged in
41
+ export const authedProcedure = t.procedure.use(async (opts) => {
42
+ const { ctx } = opts;
43
+ // `ctx.user` is nullable
44
+ if (!ctx.userId) {
45
+ throw new TRPCError({ code: 'UNAUTHORIZED' });
46
+ }
47
+
48
+ return opts.next({
49
+ ctx: {
50
+ // ✅ user value is known to be non-null now
51
+ userId: ctx.userId,
52
+ },
53
+ });
54
+ });
55
+
56
+ /**
57
+ * Merge multiple routers together
58
+ * @link https://trpc.io/docs/v11/merging-routers
59
+ */
60
+ export const mergeRouters = t.mergeRouters;
61
+
62
+ /**
63
+ * Create a server-side caller
64
+ * @link https://trpc.io/docs/v11/server/server-side-calls
65
+ */
66
+ export const createCallerFactory = t.createCallerFactory;
@@ -0,0 +1,26 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import { NextRequest } from 'next/server';
3
+
4
+ export interface AuthContext {
5
+ userId?: string | null;
6
+ }
7
+
8
+ /**
9
+ * Inner function for `createContext` where we create the context.
10
+ * This is useful for testing when we don't want to mock Next.js' request/response
11
+ */
12
+ export const createContextInner = async (): Promise<AuthContext> => ({
13
+ userId: null,
14
+ });
15
+
16
+ export type Context = Awaited<ReturnType<typeof createContextInner>>;
17
+
18
+ /**
19
+ * Creates context for an incoming request
20
+ * @link https://trpc.io/docs/v11/context
21
+ */
22
+ export const createContext = async (request: NextRequest): Promise<Context> => {
23
+ // for API-response caching see https://trpc.io/docs/v11/caching
24
+
25
+ return createContextInner();
26
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This file contains the root router of your tRPC-backend
3
+ */
4
+ import { createCallerFactory } from '@/libs/trpc';
5
+
6
+ import { appRouter } from './routers';
7
+
8
+ export const createCaller = createCallerFactory(appRouter);
@@ -1,6 +1,6 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
- exports[`GET /api/config > Model Provider env > CUSTOM_MODELS > custom deletion, addition, and renaming of models 1`] = `
3
+ exports[`configRouter > getGlobalConfig > Model Provider env > CUSTOM_MODELS > custom deletion, addition, and renaming of models 1`] = `
4
4
  [
5
5
  {
6
6
  "displayName": "llama",
@@ -22,7 +22,7 @@ exports[`GET /api/config > Model Provider env > CUSTOM_MODELS > custom deletion,
22
22
  ]
23
23
  `;
24
24
 
25
- exports[`GET /api/config > Model Provider env > OPENAI_MODEL_LIST > custom deletion, addition, and renaming of models 1`] = `
25
+ exports[`configRouter > getGlobalConfig > Model Provider env > OPENAI_MODEL_LIST > custom deletion, addition, and renaming of models 1`] = `
26
26
  {
27
27
  "enabledModels": [
28
28
  "llama",
@@ -51,7 +51,7 @@ exports[`GET /api/config > Model Provider env > OPENAI_MODEL_LIST > custom delet
51
51
  }
52
52
  `;
53
53
 
54
- exports[`GET /api/config > Model Provider env > OPENAI_MODEL_LIST > should work correct with gpt-4 1`] = `
54
+ exports[`configRouter > getGlobalConfig > Model Provider env > OPENAI_MODEL_LIST > should work correct with gpt-4 1`] = `
55
55
  [
56
56
  {
57
57
  "displayName": "GPT-3.5 Turbo (1106)",
@@ -106,7 +106,7 @@ exports[`GET /api/config > Model Provider env > OPENAI_MODEL_LIST > should work
106
106
  ]
107
107
  `;
108
108
 
109
- exports[`GET /api/config > Model Provider env > OPENROUTER_MODEL_LIST > custom deletion, addition, and renaming of models 1`] = `
109
+ exports[`configRouter > getGlobalConfig > Model Provider env > OPENROUTER_MODEL_LIST > custom deletion, addition, and renaming of models 1`] = `
110
110
  {
111
111
  "enabled": false,
112
112
  "enabledModels": [
@@ -0,0 +1,194 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ /**
4
+ * This file contains the root router of your tRPC-backend
5
+ */
6
+ import { createCallerFactory } from '@/libs/trpc';
7
+ import { AuthContext, createContextInner } from '@/server/context';
8
+ import { GlobalServerConfig } from '@/types/serverConfig';
9
+
10
+ import { configRouter } from './index';
11
+
12
+ const createCaller = createCallerFactory(configRouter);
13
+ let ctx: AuthContext;
14
+ let router: ReturnType<typeof createCaller>;
15
+
16
+ beforeEach(async () => {
17
+ vi.resetAllMocks();
18
+ ctx = await createContextInner();
19
+ router = createCaller(ctx);
20
+ });
21
+
22
+ describe('configRouter', () => {
23
+ describe('getGlobalConfig', () => {
24
+ describe('Model Provider env', () => {
25
+ describe('OPENAI_MODEL_LIST', () => {
26
+ it('custom deletion, addition, and renaming of models', async () => {
27
+ process.env.OPENAI_MODEL_LIST =
28
+ '-all,+llama,+claude-2,-gpt-3.5-turbo,gpt-4-0125-preview=gpt-4-turbo,gpt-4-0125-preview=gpt-4-32k';
29
+
30
+ const response = await router.getGlobalConfig();
31
+
32
+ // Assert
33
+ const result = response.languageModel?.openai;
34
+
35
+ expect(result).toMatchSnapshot();
36
+ process.env.OPENAI_MODEL_LIST = '';
37
+ });
38
+
39
+ it('should work correct with gpt-4', async () => {
40
+ process.env.OPENAI_MODEL_LIST =
41
+ '-all,+gpt-3.5-turbo-1106,+gpt-3.5-turbo,+gpt-3.5-turbo-16k,+gpt-4,+gpt-4-32k,+gpt-4-1106-preview,+gpt-4-vision-preview';
42
+
43
+ const response = await router.getGlobalConfig();
44
+
45
+ const result = response.languageModel?.openai?.serverModelCards;
46
+
47
+ expect(result).toMatchSnapshot();
48
+
49
+ process.env.OPENAI_MODEL_LIST = '';
50
+ });
51
+
52
+ it('duplicate naming model', async () => {
53
+ process.env.OPENAI_MODEL_LIST =
54
+ 'gpt-4-0125-preview=gpt-4-turbo,gpt-4-0125-preview=gpt-4-32k';
55
+
56
+ const response = await router.getGlobalConfig();
57
+
58
+ const result = response.languageModel?.openai?.serverModelCards;
59
+
60
+ expect(result?.find((s) => s.id === 'gpt-4-0125-preview')?.displayName).toEqual(
61
+ 'gpt-4-32k',
62
+ );
63
+
64
+ process.env.OPENAI_MODEL_LIST = '';
65
+ });
66
+
67
+ it('should delete model', async () => {
68
+ process.env.OPENAI_MODEL_LIST = '-gpt-4';
69
+
70
+ const response = await router.getGlobalConfig();
71
+
72
+ const result = response.languageModel?.openai?.serverModelCards;
73
+
74
+ expect(result?.find((r) => r.id === 'gpt-4')).toBeUndefined();
75
+
76
+ process.env.OPENAI_MODEL_LIST = '';
77
+ });
78
+
79
+ it('show the hidden model', async () => {
80
+ process.env.OPENAI_MODEL_LIST = '+gpt-4-1106-preview';
81
+
82
+ const response = await router.getGlobalConfig();
83
+
84
+ const result = response.languageModel?.openai?.serverModelCards;
85
+
86
+ expect(result?.find((o) => o.id === 'gpt-4-1106-preview')).toEqual({
87
+ displayName: 'GPT-4 Turbo Preview (1106)',
88
+ functionCall: true,
89
+ enabled: true,
90
+ id: 'gpt-4-1106-preview',
91
+ tokens: 128000,
92
+ });
93
+
94
+ process.env.OPENAI_MODEL_LIST = '';
95
+ });
96
+
97
+ it('only add the model', async () => {
98
+ process.env.OPENAI_MODEL_LIST = 'model1,model2,model3,model4';
99
+
100
+ const response = await router.getGlobalConfig();
101
+
102
+ const result = response.languageModel?.openai?.serverModelCards;
103
+
104
+ expect(result).toContainEqual({
105
+ displayName: 'model1',
106
+ id: 'model1',
107
+ enabled: true,
108
+ });
109
+ expect(result).toContainEqual({
110
+ displayName: 'model2',
111
+ enabled: true,
112
+ id: 'model2',
113
+ });
114
+ expect(result).toContainEqual({
115
+ displayName: 'model3',
116
+ enabled: true,
117
+ id: 'model3',
118
+ });
119
+ expect(result).toContainEqual({
120
+ displayName: 'model4',
121
+ enabled: true,
122
+ id: 'model4',
123
+ });
124
+
125
+ process.env.OPENAI_MODEL_LIST = '';
126
+ });
127
+ });
128
+
129
+ describe('CUSTOM_MODELS', () => {
130
+ it('custom deletion, addition, and renaming of models', async () => {
131
+ process.env.CUSTOM_MODELS =
132
+ '-all,+llama,+claude-2,-gpt-3.5-turbo,gpt-4-0125-preview=gpt-4-turbo,gpt-4-0125-preview=gpt-4-32k';
133
+
134
+ const response = await router.getGlobalConfig();
135
+
136
+ // Assert
137
+ const result = response.languageModel?.openai?.serverModelCards;
138
+
139
+ expect(result).toMatchSnapshot();
140
+ });
141
+ });
142
+
143
+ describe('OPENROUTER_MODEL_LIST', () => {
144
+ it('custom deletion, addition, and renaming of models', async () => {
145
+ process.env.OPENROUTER_MODEL_LIST =
146
+ '-all,+google/gemma-7b-it,+mistralai/mistral-7b-instruct=Mistral-7B-Instruct';
147
+
148
+ const response = await router.getGlobalConfig();
149
+
150
+ // Assert
151
+ const result = response.languageModel?.openrouter;
152
+
153
+ expect(result).toMatchSnapshot();
154
+
155
+ process.env.OPENROUTER_MODEL_LIST = '';
156
+ });
157
+ });
158
+ });
159
+ });
160
+
161
+ describe('getDefaultAgentConfig', () => {
162
+ it('should return the default agent config', async () => {
163
+ process.env.DEFAULT_AGENT_CONFIG =
164
+ 'plugins=search-engine,lobe-image-designer;enableAutoCreateTopic=true;model=gemini-pro;provider=google;';
165
+
166
+ const response = await router.getDefaultAgentConfig();
167
+
168
+ expect(response).toEqual({
169
+ enableAutoCreateTopic: true,
170
+ model: 'gemini-pro',
171
+ plugins: ['search-engine', 'lobe-image-designer'],
172
+ provider: 'google',
173
+ });
174
+
175
+ process.env.DEFAULT_AGENT_CONFIG = '';
176
+ });
177
+
178
+ it('should return another config', async () => {
179
+ process.env.DEFAULT_AGENT_CONFIG =
180
+ 'model=meta-11ama/11ama-3-70b-instruct:nitro;provider=openrouter;enableAutoCreateTopic=true;params.max_tokens=700';
181
+
182
+ const response = await router.getDefaultAgentConfig();
183
+
184
+ expect(response).toEqual({
185
+ enableAutoCreateTopic: true,
186
+ model: 'meta-11ama/11ama-3-70b-instruct:nitro',
187
+ params: { max_tokens: 700 },
188
+ provider: 'openrouter',
189
+ });
190
+
191
+ process.env.DEFAULT_AGENT_CONFIG = '';
192
+ });
193
+ });
194
+ });