@lobehub/chat 0.4.1 → 0.4.3

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,57 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.4.3](https://github.com/lobehub/lobe-chat/compare/v0.4.2...v0.4.3)
6
+
7
+ <sup>Released on **2023-07-22**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: 优化 edit 代码结构.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: 优化 edit 代码结构 ([fdb3a3f](https://github.com/lobehub/lobe-chat/commit/fdb3a3f))
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.4.2](https://github.com/lobehub/lobe-chat/compare/v0.4.1...v0.4.2)
31
+
32
+ <sup>Released on **2023-07-22**</sup>
33
+
34
+ #### 💄 Styles
35
+
36
+ - **misc**: Fix input style, fix layout.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### Styles
44
+
45
+ - **misc**: Fix input style ([504bd64](https://github.com/lobehub/lobe-chat/commit/504bd64))
46
+ - **misc**: Fix layout ([2d83aff](https://github.com/lobehub/lobe-chat/commit/2d83aff))
47
+
48
+ </details>
49
+
50
+ <div align="right">
51
+
52
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
53
+
54
+ </div>
55
+
5
56
  ### [Version 0.4.1](https://github.com/lobehub/lobe-chat/compare/v0.4.0...v0.4.1)
6
57
 
7
58
  <sup>Released on **2023-07-22**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Lobe Chat is an open-source chatbot client using LangChain, Typescript and Next.js",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -12,8 +12,8 @@ import { useTranslation } from 'react-i18next';
12
12
  import { Flexbox } from 'react-layout-kit';
13
13
  import { shallow } from 'zustand/shallow';
14
14
 
15
+ import HeaderSpacing from '@/components/HeaderSpacing';
15
16
  import { CHAT_SIDEBAR_WIDTH } from '@/const/layoutTokens';
16
- import HeaderSpacing from '@/features/HeaderSpacing';
17
17
  import { useSessionStore } from '@/store/session';
18
18
 
19
19
  import ReadMode from './ReadMode';
@@ -1,14 +1,14 @@
1
1
  import { memo } from 'react';
2
2
  import { Flexbox } from 'react-layout-kit';
3
3
 
4
- import HeaderSpacing from '@/features/HeaderSpacing';
4
+ import HeaderSpacing from '@/components/HeaderSpacing';
5
5
  import ChatInput from '@/pages/chat/[id]/Conversation/Input';
6
6
 
7
7
  import ChatList from './ChatList';
8
8
 
9
9
  const Conversation = () => {
10
10
  return (
11
- <Flexbox flex={1}>
11
+ <Flexbox flex={1} style={{ position: 'relative' }}>
12
12
  <div style={{ flex: 1, overflowY: 'scroll' }}>
13
13
  <HeaderSpacing />
14
14
  <ChatList />
@@ -8,7 +8,7 @@ import { shallow } from 'zustand/shallow';
8
8
 
9
9
  import { agentSelectors, useSessionStore } from '@/store/session';
10
10
 
11
- import { FormItem } from './FormItem';
11
+ import { FormItem } from '../FormItem';
12
12
 
13
13
  export const useStyles = createStyles(({ css, token }) => ({
14
14
  input: css`
@@ -46,9 +46,10 @@ const Prompt = () => {
46
46
  updateAgentConfig({ systemRole: e });
47
47
  }}
48
48
  onEditingChange={setEditing}
49
+ showEditWhenEmpty
49
50
  value={systemRole}
50
51
  />
51
- {!editing && (
52
+ {!editing && !!systemRole && (
52
53
  <Flexbox direction={'horizontal-reverse'}>
53
54
  <Button
54
55
  onClick={() => {
@@ -7,9 +7,9 @@ import { shallow } from 'zustand/shallow';
7
7
  import { agentSelectors, useSessionStore } from '@/store/session';
8
8
  import { LanguageModel } from '@/types/llm';
9
9
 
10
- import { FormItem } from './FormItem';
10
+ import { FormItem } from '../FormItem';
11
+ import { useStyles } from '../style';
11
12
  import Prompt from './Prompt';
12
- import { useStyles } from './style';
13
13
 
14
14
  const AgentConfig = () => {
15
15
  const { t } = useTranslation('common');
@@ -8,8 +8,8 @@ import { shallow } from 'zustand/shallow';
8
8
 
9
9
  import { agentSelectors, useSessionStore } from '@/store/session';
10
10
 
11
- import { FormItem } from './FormItem';
12
- import { useStyles } from './style';
11
+ import { FormItem } from '../FormItem';
12
+ import { useStyles } from '../style';
13
13
 
14
14
  const AgentMeta = () => {
15
15
  const { t } = useTranslation('common');
@@ -7,7 +7,7 @@ import { memo } from 'react';
7
7
  import { useTranslation } from 'react-i18next';
8
8
  import { Flexbox } from 'react-layout-kit';
9
9
 
10
- import HeaderSpacing from '@/features/HeaderSpacing';
10
+ import HeaderSpacing from '@/components/HeaderSpacing';
11
11
 
12
12
  import ChatLayout from '../../layout';
13
13
  import AgentConfig from './AgentConfig';
@@ -23,9 +23,9 @@ const Chat = memo(() => {
23
23
  <Head>
24
24
  <title>{pageTitle}</title>
25
25
  </Head>
26
- <Flexbox id={'lobe-conversion-container'} style={{ height: '100vh', position: 'relative' }}>
26
+ <Flexbox id={'lobe-conversion-container'} style={{ height: '100vh' }}>
27
27
  <Header />
28
- <Flexbox flex={1} horizontal>
28
+ <Flexbox flex={1} height={'calc(100vh - 64px)'} horizontal>
29
29
  <Conversation />
30
30
  <Config />
31
31
  </Flexbox>
@@ -3,7 +3,7 @@ import { memo, useEffect } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { Flexbox } from 'react-layout-kit';
5
5
 
6
- import HeaderSpacing from '@/features/HeaderSpacing';
6
+ import HeaderSpacing from '@/components/HeaderSpacing';
7
7
  import { createI18nNext } from '@/locales/create';
8
8
  import ChatLayout from '@/pages/chat/layout';
9
9
 
@@ -7,11 +7,33 @@ import type { SidebarTabKey } from './initialState';
7
7
  import { DEFAULT_SETTINGS, GlobalSettingsState } from './initialState';
8
8
  import type { SettingsStore } from './store';
9
9
 
10
+ /**
11
+ * 设置操作
12
+ */
10
13
  export interface SettingsAction {
14
+ /**
15
+ * 重置设置
16
+ */
11
17
  resetSettings: () => void;
18
+ /**
19
+ * 设置全局设置
20
+ * @param settings - 全局设置
21
+ */
12
22
  setGlobalSettings: (settings: GlobalSettingsState) => void;
23
+ /**
24
+ * 设置部分配置设置
25
+ * @param settings - 部分配置设置
26
+ */
13
27
  setSettings: (settings: Partial<ConfigSettings>) => void;
28
+ /**
29
+ * 设置主题模式
30
+ * @param themeMode - 主题模式
31
+ */
14
32
  setThemeMode: (themeMode: ThemeMode) => void;
33
+ /**
34
+ * 切换侧边栏选项
35
+ * @param key - 选中的侧边栏选项
36
+ */
15
37
  switchSideBar: (key: SidebarTabKey) => void;
16
38
  }
17
39
 
@@ -1,6 +1,8 @@
1
1
  import type { ConfigSettings } from '@/types/exportConfig';
2
+ import { LanguageModel } from '@/types/llm';
2
3
 
3
4
  export type SidebarTabKey = 'chat' | 'market';
5
+
4
6
  export const DEFAULT_SETTINGS: ConfigSettings = {
5
7
  accessCode: '',
6
8
  avatar: '',
@@ -14,7 +16,7 @@ export const DEFAULT_SETTINGS: ConfigSettings = {
14
16
  historyCount: 24,
15
17
  language: 'zh-CN',
16
18
  maxTokens: 2000,
17
- model: 'gpt-3.5-turbo',
19
+ model: LanguageModel.GPT3_5,
18
20
  neutralColor: '',
19
21
  presencePenalty: 0,
20
22
  primaryColor: '',
@@ -1,6 +1,8 @@
1
1
  import type { NeutralColors, PrimaryColors } from '@lobehub/ui';
2
2
  import { ThemeMode } from 'antd-style';
3
3
 
4
+ import { LanguageModel } from '@/types/llm';
5
+
4
6
  import { Locales } from './locale';
5
7
 
6
8
  /**
@@ -19,7 +21,7 @@ export interface ConfigSettings {
19
21
  historyCount: number;
20
22
  language: Locales;
21
23
  maxTokens: number;
22
- model: string;
24
+ model: LanguageModel;
23
25
  neutralColor: NeutralColors | '';
24
26
  presencePenalty: number;
25
27
  primaryColor: PrimaryColors | '';
package/tsconfig.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "baseUrl": ".",
19
19
  "types": ["vitest/globals"],
20
20
  "paths": {
21
- "@/*": ["src/*"]
21
+ "@/*": ["./src/*"]
22
22
  }
23
23
  },
24
24
  "exclude": ["node_modules"],
@@ -1,36 +0,0 @@
1
- import { ChatMessage } from '@lobehub/ui';
2
-
3
- import { getInputVariablesFromMessages } from '@/helpers/prompt';
4
-
5
- describe('getInputVariablesFromMessages 方法', () => {
6
- it('应当在输入为空数组时返回空数组', () => {
7
- const result = getInputVariablesFromMessages([]);
8
- expect(result).toEqual([]);
9
- });
10
-
11
- it('应当在输入消息不包含变量时返回空数组', () => {
12
- const input: ChatMessage[] = [{ role: 'user', content: 'Hello, how are you?' }];
13
- const result = getInputVariablesFromMessages(input);
14
- expect(result).toEqual([]);
15
- });
16
-
17
- it('应当在输入消息包含变量时返回包含变量、模板和消息索引的对象数组', () => {
18
- const input: ChatMessage[] = [
19
- { role: 'user', content: 'Hello {name}, how are you?' },
20
- { role: 'user', content: 'My name is {name}' },
21
- ];
22
- const expectedOutput = ['name'];
23
- const result = getInputVariablesFromMessages(input);
24
- expect(result).toEqual(expectedOutput);
25
- });
26
-
27
- it('多个变量的情况', () => {
28
- const input: ChatMessage[] = [
29
- { role: 'user', content: 'Hello {name}, how are {you}?' },
30
- { role: 'user', content: 'My name is {name}' },
31
- ];
32
- const expectedOutput = ['name', 'you'];
33
- const result = getInputVariablesFromMessages(input);
34
- expect(result).toEqual(expectedOutput);
35
- });
36
- });
@@ -1,36 +0,0 @@
1
- import { ChatMessage } from '@lobehub/ui';
2
- import {
3
- AIMessagePromptTemplate,
4
- ChatPromptTemplate,
5
- HumanMessagePromptTemplate,
6
- SystemMessagePromptTemplate,
7
- } from 'langchain/prompts';
8
-
9
- export const getChatPromptTemplate = (chatMessages: ChatMessage[]) =>
10
- ChatPromptTemplate.fromPromptMessages(
11
- chatMessages.map((m) => {
12
- switch (m.role) {
13
- default:
14
- case 'user': {
15
- return HumanMessagePromptTemplate.fromTemplate(m.content);
16
- }
17
-
18
- case 'system': {
19
- return SystemMessagePromptTemplate.fromTemplate(m.content);
20
- }
21
-
22
- case 'assistant': {
23
- return AIMessagePromptTemplate.fromTemplate(m.content);
24
- }
25
- }
26
- }),
27
- );
28
- export const getInputVariablesFromMessages = (chatMessages: ChatMessage[]) => {
29
- let inputVariables: string[] = [];
30
- try {
31
- const chatPrompt = getChatPromptTemplate(chatMessages);
32
- inputVariables = chatPrompt.inputVariables;
33
- } catch {}
34
-
35
- return inputVariables;
36
- };