@lobehub/chat 0.90.1 → 0.90.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,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.90.3](https://github.com/lobehub/lobe-chat/compare/v0.90.2...v0.90.3)
6
+
7
+ <sup>Released on **2023-10-17**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Fix ActionBar props and regenerate btn with error message.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Fix ActionBar props and regenerate btn with error message, closes [#337](https://github.com/lobehub/lobe-chat/issues/337) ([246e8fd](https://github.com/lobehub/lobe-chat/commit/246e8fd))
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.90.2](https://github.com/lobehub/lobe-chat/compare/v0.90.1...v0.90.2)
31
+
32
+ <sup>Released on **2023-10-17**</sup>
33
+
34
+ #### ♻ Code Refactoring
35
+
36
+ - **misc**: Refactor OpenAIStreamPayload with chat name.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### Code refactoring
44
+
45
+ - **misc**: Refactor OpenAIStreamPayload with chat name ([a799530](https://github.com/lobehub/lobe-chat/commit/a799530))
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.90.1](https://github.com/lobehub/lobe-chat/compare/v0.90.0...v0.90.1)
6
56
 
7
57
  <sup>Released on **2023-10-17**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.90.1",
3
+ "version": "0.90.3",
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",
@@ -3,11 +3,11 @@ import OpenAI from 'openai';
3
3
 
4
4
  import { createErrorResponse } from '@/app/api/openai/errorResponse';
5
5
  import { ChatErrorType } from '@/types/fetch';
6
- import { OpenAIStreamPayload } from '@/types/openai';
6
+ import { OpenAIChatStreamPayload } from '@/types/openai/chat';
7
7
 
8
8
  interface CreateChatCompletionOptions {
9
9
  openai: OpenAI;
10
- payload: OpenAIStreamPayload;
10
+ payload: OpenAIChatStreamPayload;
11
11
  }
12
12
 
13
13
  export const createChatCompletion = async ({ payload, openai }: CreateChatCompletionOptions) => {
@@ -3,18 +3,18 @@ import OpenAI from 'openai';
3
3
  import { getServerConfig } from '@/config/server';
4
4
  import { getOpenAIAuthFromRequest } from '@/const/fetch';
5
5
  import { ChatErrorType, ErrorType } from '@/types/fetch';
6
- import { OpenAIStreamPayload } from '@/types/openai';
6
+ import { OpenAIChatStreamPayload } from '@/types/openai/chat';
7
7
 
8
8
  import { checkAuth } from '../../auth';
9
9
  import { createAzureOpenai } from '../createAzureOpenai';
10
- import { createChatCompletion } from '../createChatCompletion';
11
10
  import { createOpenai } from '../createOpenai';
12
11
  import { createErrorResponse } from '../errorResponse';
12
+ import { createChatCompletion } from './createChatCompletion';
13
13
 
14
14
  export const runtime = 'edge';
15
15
 
16
16
  export const POST = async (req: Request) => {
17
- const payload = (await req.json()) as OpenAIStreamPayload;
17
+ const payload = (await req.json()) as OpenAIChatStreamPayload;
18
18
 
19
19
  const { apiKey, accessCode, endpoint, useAzure, apiVersion } = getOpenAIAuthFromRequest(req);
20
20
 
@@ -13,12 +13,11 @@ import { Flexbox } from 'react-layout-kit';
13
13
 
14
14
  import { useSessionStore } from '@/store/session';
15
15
  import { agentSelectors } from '@/store/session/slices/agentConfig';
16
- import { currentFunctionCallProps } from '@/store/session/slices/chat/selectors/chat';
16
+ import { chatSelectors } from '@/store/session/slices/chat/selectors';
17
17
  import { isFunctionMessage } from '@/utils/message';
18
18
 
19
19
  import FunctionCall from '../Plugins/FunctionCall';
20
20
  import { DefautMessage } from './Default';
21
- import { SystemActionsBar } from './System';
22
21
 
23
22
  const useStyles = createStyles(({ css }) => ({
24
23
  container: css`
@@ -34,7 +33,7 @@ const useStyles = createStyles(({ css }) => ({
34
33
 
35
34
  export const AssistantMessage: RenderMessage = memo(
36
35
  ({ id, plugin, function_call, content, ...props }) => {
37
- const genFunctionCallProps = useSessionStore(currentFunctionCallProps);
36
+ const genFunctionCallProps = useSessionStore(chatSelectors.currentFunctionCallProps);
38
37
 
39
38
  if (!isFunctionMessage(content)) return <DefautMessage content={content} id={id} {...props} />;
40
39
 
@@ -65,16 +64,15 @@ export const AssistantMessageExtra: RenderMessageExtra = memo(({ extra, function
65
64
  );
66
65
  });
67
66
 
68
- export const AssistantActionsBar: RenderAction = memo(({ text, error, id, ...props }) => {
67
+ export const AssistantActionsBar: RenderAction = memo(({ text, error, id, onActionClick }) => {
69
68
  const { regenerate, edit, copy, divider, del } = useChatListActionsBar(text);
70
69
  if (id === 'default') return;
71
- if (error) return <SystemActionsBar id={id} text={text} {...props} />;
72
70
  return (
73
71
  <ActionIconGroup
74
- dropdownMenu={[edit, copy, regenerate, divider, del]}
75
- items={[regenerate, copy]}
72
+ dropdownMenu={error ? [regenerate, divider, del] : [edit, copy, regenerate, divider, del]}
73
+ items={[regenerate]}
74
+ onActionClick={onActionClick}
76
75
  type="ghost"
77
- {...props}
78
76
  />
79
77
  );
80
78
  });
@@ -3,14 +3,14 @@ import { memo } from 'react';
3
3
  import { Flexbox } from 'react-layout-kit';
4
4
 
5
5
  import { useSessionStore } from '@/store/session';
6
- import { currentFunctionCallProps } from '@/store/session/slices/chat/selectors/chat';
6
+ import { chatSelectors } from '@/store/session/selectors';
7
7
 
8
8
  import FunctionCall from '../Plugins/FunctionCall';
9
9
  import PluginMessage from '../Plugins/PluginMessage';
10
10
 
11
11
  export const FunctionMessage: RenderMessage = memo(
12
12
  ({ id, content, plugin, function_call, ...props }) => {
13
- const genFunctionCallProps = useSessionStore(currentFunctionCallProps);
13
+ const genFunctionCallProps = useSessionStore(chatSelectors.currentFunctionCallProps);
14
14
  const fcProps = genFunctionCallProps({ content, function_call, id, plugin });
15
15
 
16
16
  return (
@@ -29,14 +29,14 @@ export const FunctionMessage: RenderMessage = memo(
29
29
  },
30
30
  );
31
31
 
32
- export const FunctionActionsBar: RenderAction = memo(({ text, ...props }) => {
32
+ export const FunctionActionsBar: RenderAction = memo(({ text, onActionClick }) => {
33
33
  const { regenerate, divider, del } = useChatListActionsBar(text);
34
34
  return (
35
35
  <ActionIconGroup
36
36
  dropdownMenu={[regenerate, divider, del]}
37
37
  items={[regenerate]}
38
+ onActionClick={onActionClick}
38
39
  type="ghost"
39
- {...props}
40
40
  />
41
41
  );
42
42
  });
@@ -1,7 +1,9 @@
1
1
  import { ActionIconGroup, RenderAction, useChatListActionsBar } from '@lobehub/ui';
2
2
  import { memo } from 'react';
3
3
 
4
- export const SystemActionsBar: RenderAction = memo(({ text, ...props }) => {
4
+ export const SystemActionsBar: RenderAction = memo(({ text, onActionClick }) => {
5
5
  const { del } = useChatListActionsBar(text);
6
- return <ActionIconGroup dropdownMenu={[del]} items={[]} type="ghost" {...props} />;
6
+ return (
7
+ <ActionIconGroup dropdownMenu={[del]} items={[]} onActionClick={onActionClick} type="ghost" />
8
+ );
7
9
  });
@@ -1,14 +1,14 @@
1
1
  import { ActionIconGroup, RenderAction, useChatListActionsBar } from '@lobehub/ui';
2
2
  import { memo } from 'react';
3
3
 
4
- export const UserActionsBar: RenderAction = memo(({ text, ...props }) => {
4
+ export const UserActionsBar: RenderAction = memo(({ text, onActionClick }) => {
5
5
  const { regenerate, edit, copy, divider, del } = useChatListActionsBar(text);
6
6
  return (
7
7
  <ActionIconGroup
8
8
  dropdownMenu={[edit, copy, regenerate, divider, del]}
9
9
  items={[regenerate, edit]}
10
+ onActionClick={onActionClick}
10
11
  type="ghost"
11
- {...props}
12
12
  />
13
13
  );
14
14
  });
@@ -1,7 +1,7 @@
1
- import { OpenAIStreamPayload } from '@/types/openai';
1
+ import { OpenAIChatStreamPayload } from '@/types/openai/chat';
2
2
 
3
3
  // 自动起名
4
- export const promptSummaryAgentName = (content: string): Partial<OpenAIStreamPayload> => ({
4
+ export const promptSummaryAgentName = (content: string): Partial<OpenAIChatStreamPayload> => ({
5
5
  messages: [
6
6
  {
7
7
  content: `你是一名擅长起名的起名大师,你需要将用户的描述总结为 20 个字以内的角色,格式要求如下:
@@ -32,7 +32,7 @@ export const promptSummaryAgentName = (content: string): Partial<OpenAIStreamPay
32
32
  });
33
33
 
34
34
  // 自动挑选 emoji 和背景色
35
- export const promptPickEmoji = (content: string): Partial<OpenAIStreamPayload> => ({
35
+ export const promptPickEmoji = (content: string): Partial<OpenAIChatStreamPayload> => ({
36
36
  messages: [
37
37
  {
38
38
  content: '你是一名非常懂设计与时尚的设计师,你需要从用户的描述中匹配一个合适的 emoji。',
@@ -61,7 +61,7 @@ export const promptPickEmoji = (content: string): Partial<OpenAIStreamPayload> =
61
61
  ],
62
62
  });
63
63
 
64
- export const promptSummaryDescription = (content: string): Partial<OpenAIStreamPayload> => ({
64
+ export const promptSummaryDescription = (content: string): Partial<OpenAIChatStreamPayload> => ({
65
65
  messages: [
66
66
  {
67
67
  content:
@@ -1,10 +1,10 @@
1
1
  import { chatHelpers } from '@/store/session/helpers';
2
2
  import { LanguageModel } from '@/types/llm';
3
- import { OpenAIChatMessage, OpenAIStreamPayload } from '@/types/openai';
3
+ import { OpenAIChatMessage, OpenAIChatStreamPayload } from '@/types/openai/chat';
4
4
 
5
5
  export const promptSummaryTitle = async (
6
6
  messages: OpenAIChatMessage[],
7
- ): Promise<Partial<OpenAIStreamPayload>> => {
7
+ ): Promise<Partial<OpenAIChatStreamPayload>> => {
8
8
  const finalMessages: OpenAIChatMessage[] = [
9
9
  {
10
10
  content:
@@ -2,7 +2,7 @@ import { merge } from 'lodash-es';
2
2
 
3
3
  import { pluginSelectors, usePluginStore } from '@/store/plugin';
4
4
  import { initialLobeAgentConfig } from '@/store/session/initialState';
5
- import type { ChatCompletionFunctions, OpenAIStreamPayload } from '@/types/openai';
5
+ import type { ChatCompletionFunctions, OpenAIChatStreamPayload } from '@/types/openai/chat';
6
6
 
7
7
  import { createHeaderWithOpenAI } from './_header';
8
8
  import { OPENAI_URLS } from './_url';
@@ -15,7 +15,7 @@ interface FetchChatModelOptions {
15
15
  * 专门用于对话的 fetch
16
16
  */
17
17
  export const fetchChatModel = (
18
- { plugins: enabledPlugins, ...params }: Partial<OpenAIStreamPayload>,
18
+ { plugins: enabledPlugins, ...params }: Partial<OpenAIChatStreamPayload>,
19
19
  options?: FetchChatModelOptions,
20
20
  ) => {
21
21
  const payload = merge(
@@ -2,7 +2,7 @@ import { uniqBy } from 'lodash-es';
2
2
 
3
3
  import { PLUGIN_SCHEMA_SEPARATOR } from '@/const/plugin';
4
4
  import { pluginHelpers } from '@/store/plugin/helpers';
5
- import { ChatCompletionFunctions } from '@/types/openai';
5
+ import { ChatCompletionFunctions } from '@/types/openai/chat';
6
6
 
7
7
  import { PluginStoreState } from './initialState';
8
8
 
@@ -1,4 +1,4 @@
1
- import { OpenAIChatMessage } from '@/types/openai';
1
+ import { OpenAIChatMessage } from '@/types/openai/chat';
2
2
  import { encodeAsync } from '@/utils/tokenizer';
3
3
 
4
4
  export const getMessagesTokenCount = async (messages: OpenAIChatMessage[]) =>
@@ -3,6 +3,7 @@ import {
3
3
  currentChats,
4
4
  currentChatsWithGuideMessage,
5
5
  currentChatsWithHistoryConfig,
6
+ currentFunctionCallProps,
6
7
  getChatsById,
7
8
  } from './chat';
8
9
  import { currentTopics, getTopicMessages } from './topic';
@@ -12,6 +13,7 @@ export const chatSelectors = {
12
13
  currentChats,
13
14
  currentChatsWithGuideMessage,
14
15
  currentChatsWithHistoryConfig,
16
+ currentFunctionCallProps,
15
17
  getChatsById,
16
18
  };
17
19
 
@@ -20,7 +20,7 @@ export interface OpenAIChatMessage {
20
20
  /**
21
21
  * @title OpenAI Stream Payload
22
22
  */
23
- export interface OpenAIStreamPayload {
23
+ export interface OpenAIChatStreamPayload {
24
24
  /**
25
25
  * @title 控制生成文本中的惩罚系数,用于减少重复性
26
26
  * @default 0