balibabu commited on
Commit
1a0fce6
·
1 Parent(s): 73099c4

feat: support GPT-4o #771 and hide the add button when the folder is a knowledge base (#775)

Browse files

### What problem does this PR solve?

feat: support GPT-4o #771

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

web/.umirc.ts CHANGED
@@ -30,8 +30,10 @@ export default defineConfig({
30
  copy: ['src/conf.json'],
31
  proxy: {
32
  '/v1': {
33
- target: 'http://123.60.95.134:9380/',
34
  changeOrigin: true,
 
 
35
  // pathRewrite: { '^/v1': '/v1' },
36
  },
37
  },
 
30
  copy: ['src/conf.json'],
31
  proxy: {
32
  '/v1': {
33
+ target: '',
34
  changeOrigin: true,
35
+ ws: true,
36
+ logger: console,
37
  // pathRewrite: { '^/v1': '/v1' },
38
  },
39
  },
web/package-lock.json CHANGED
The diff for this file is too large to render. See raw diff
 
web/package.json CHANGED
@@ -3,7 +3,7 @@
3
  "author": "zhaofengchao <[email protected]>",
4
  "scripts": {
5
  "build": "umi build",
6
- "dev": "cross-env PORT=9200 umi dev",
7
  "postinstall": "umi setup",
8
  "lint": "umi lint --eslint-only",
9
  "setup": "umi setup",
 
3
  "author": "zhaofengchao <[email protected]>",
4
  "scripts": {
5
  "build": "umi build",
6
+ "dev": "cross-env PORT=9200 UMI_DEV_SERVER_COMPRESS=none umi dev",
7
  "postinstall": "umi setup",
8
  "lint": "umi lint --eslint-only",
9
  "setup": "umi setup",
web/src/hooks/llmHooks.ts CHANGED
@@ -67,13 +67,15 @@ export const useSelectLlmOptionsByModelType = () => {
67
  const groupOptionsByModelType = (modelType: LlmModelType) => {
68
  return Object.entries(llmInfo)
69
  .filter(([, value]) =>
70
- modelType ? value.some((x) => x.model_type === modelType) : true,
71
  )
72
  .map(([key, value]) => {
73
  return {
74
  label: key,
75
  options: value
76
- .filter((x) => (modelType ? x.model_type === modelType : true))
 
 
77
  .map((x) => ({
78
  label: x.llm_name,
79
  value: x.llm_name,
 
67
  const groupOptionsByModelType = (modelType: LlmModelType) => {
68
  return Object.entries(llmInfo)
69
  .filter(([, value]) =>
70
+ modelType ? value.some((x) => x.model_type.includes(modelType)) : true,
71
  )
72
  .map(([key, value]) => {
73
  return {
74
  label: key,
75
  options: value
76
+ .filter((x) =>
77
+ modelType ? x.model_type.includes(modelType) : true,
78
+ )
79
  .map((x) => ({
80
  label: x.llm_name,
81
  value: x.llm_name,
web/src/hooks/logicHooks.ts CHANGED
@@ -1,7 +1,11 @@
 
1
  import { LanguageTranslationMap } from '@/constants/common';
2
  import { Pagination } from '@/interfaces/common';
3
  import { IKnowledgeFile } from '@/interfaces/database/knowledge';
4
  import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
 
 
 
5
  import { PaginationProps } from 'antd';
6
  import axios from 'axios';
7
  import { useCallback, useEffect, useMemo, useState } from 'react';
@@ -133,3 +137,63 @@ export const useFetchAppConf = () => {
133
 
134
  return appConf;
135
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Authorization } from '@/constants/authorization';
2
  import { LanguageTranslationMap } from '@/constants/common';
3
  import { Pagination } from '@/interfaces/common';
4
  import { IKnowledgeFile } from '@/interfaces/database/knowledge';
5
  import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
6
+ import api from '@/utils/api';
7
+ import authorizationUtil from '@/utils/authorizationUtil';
8
+ import { getSearchValue } from '@/utils/commonUtil';
9
  import { PaginationProps } from 'antd';
10
  import axios from 'axios';
11
  import { useCallback, useEffect, useMemo, useState } from 'react';
 
137
 
138
  return appConf;
139
  };
140
+
141
+ export const useConnectWithSse = (url: string) => {
142
+ const [content, setContent] = useState<string>('');
143
+
144
+ const connect = useCallback(() => {
145
+ const source = new EventSource(
146
+ url || '/sse/createSseEmitter?clientId=123456',
147
+ );
148
+
149
+ source.onopen = function () {
150
+ console.log('Connection to the server was opened.');
151
+ };
152
+
153
+ source.onmessage = function (event: any) {
154
+ setContent(event.data);
155
+ };
156
+
157
+ source.onerror = function (error) {
158
+ console.error('Error occurred:', error);
159
+ };
160
+ }, [url]);
161
+
162
+ return { connect, content };
163
+ };
164
+
165
+ export const useConnectWithSseNext = () => {
166
+ const [content, setContent] = useState<string>('');
167
+ const sharedId = getSearchValue('shared_id');
168
+ const authorization = sharedId
169
+ ? 'Bearer ' + sharedId
170
+ : authorizationUtil.getAuthorization();
171
+ const send = useCallback(
172
+ async (body: any) => {
173
+ const response = await fetch(api.completeConversation, {
174
+ method: 'POST',
175
+ headers: {
176
+ [Authorization]: authorization,
177
+ 'Content-Type': 'application/json',
178
+ },
179
+ body: JSON.stringify(body),
180
+ });
181
+ const reader = response?.body
182
+ ?.pipeThrough(new TextDecoderStream())
183
+ .getReader();
184
+
185
+ // const reader = response.body.getReader();
186
+
187
+ while (true) {
188
+ const { value, done } = await reader?.read();
189
+ console.log('Received', value);
190
+ setContent(value);
191
+ if (done) break;
192
+ }
193
+ return response;
194
+ },
195
+ [authorization],
196
+ );
197
+
198
+ return { send, content };
199
+ };
web/src/pages/chat/hooks.ts CHANGED
@@ -518,6 +518,7 @@ export const useSendMessage = (
518
  const completeConversation = useCompleteConversation();
519
 
520
  const { handleClickConversation } = useClickConversationCard();
 
521
 
522
  const sendMessage = useCallback(
523
  async (message: string, id?: string) => {
 
518
  const completeConversation = useCompleteConversation();
519
 
520
  const { handleClickConversation } = useClickConversationCard();
521
+ // const { send } = useConnectWithSseNext();
522
 
523
  const sendMessage = useCallback(
524
  async (message: string, id?: string) => {