Skip to content

Commit 81a0671

Browse files
authored
feat: ai proxy v1 (#3898)
* feat: ai proxy v1 * perf: ai proxy channel crud * feat: ai proxy logs * feat: channel test * doc * update lock
1 parent 3c382d1 commit 81a0671

File tree

40 files changed

+2869
-746
lines changed

40 files changed

+2869
-746
lines changed

docSite/content/zh-cn/docs/development/upgrading/4823.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ weight: 802
1111
## 🚀 新增内容
1212

1313
1. 增加默认“知识库文本理解模型”配置
14+
2. AI proxy V1版,可替换 OneAPI使用,同时提供完整模型调用日志,便于排查问题。
1415

1516
## ⚙️ 优化
1617

1718
1. 模型配置表单,增加必填项校验。
1819
2. 集合列表数据统计方式,提高大数据量统计性能。
1920
3. 优化数学公式,转义 Latex 格式成 Markdown 格式。
2021
4. 解析文档图片,图片太大时,自动忽略。
22+
5. 时间选择器,当天开始时间自动设0,结束设置设 23:59:59,避免 UI 与实际逻辑偏差。
23+
6. 升级 mongoose 库版本依赖。
2124

2225
## 🐛 修复
2326

2427
1. 标签过滤时,子文件夹未成功过滤。
25-
2. 暂时移除 md 阅读优化,避免链接分割错误。
28+
2. 暂时移除 md 阅读优化,避免链接分割错误。
29+
3. 离开团队时,未刷新成员列表。

packages/global/common/string/time.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import { i18nT } from '../../../web/i18n/utils';
77
dayjs.extend(utc);
88
dayjs.extend(timezone);
99

10-
export const formatTime2YMDHMW = (time?: Date) => dayjs(time).format('YYYY-MM-DD HH:mm:ss dddd');
11-
export const formatTime2YMDHMS = (time?: Date) =>
10+
export const formatTime2YMDHMW = (time?: Date | number) =>
11+
dayjs(time).format('YYYY-MM-DD HH:mm:ss dddd');
12+
export const formatTime2YMDHMS = (time?: Date | number) =>
1213
time ? dayjs(time).format('YYYY-MM-DD HH:mm:ss') : '';
13-
export const formatTime2YMDHM = (time?: Date) =>
14+
export const formatTime2YMDHM = (time?: Date | number) =>
1415
time ? dayjs(time).format('YYYY-MM-DD HH:mm') : '';
15-
export const formatTime2YMD = (time?: Date) => (time ? dayjs(time).format('YYYY-MM-DD') : '');
16+
export const formatTime2YMD = (time?: Date | number) =>
17+
time ? dayjs(time).format('YYYY-MM-DD') : '';
1618
export const formatTime2HM = (time: Date = new Date()) => dayjs(time).format('HH:mm');
1719

1820
/**

packages/global/common/system/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type FastGPTFeConfigsType = {
5454
show_promotion?: boolean;
5555
show_team_chat?: boolean;
5656
show_compliance_copywriting?: boolean;
57+
show_aiproxy?: boolean;
5758
concatMd?: string;
5859

5960
docUrl?: string;

packages/service/core/ai/config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ import { i18nT } from '../../../web/i18n/utils';
1111
import { OpenaiAccountType } from '@fastgpt/global/support/user/team/type';
1212
import { getLLMModel } from './model';
1313

14-
export const openaiBaseUrl = process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1';
14+
const aiProxyBaseUrl = process.env.AIPROXY_API_ENDPOINT
15+
? `${process.env.AIPROXY_API_ENDPOINT}/v1`
16+
: undefined;
17+
const openaiBaseUrl = aiProxyBaseUrl || process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1';
18+
const openaiBaseKey = process.env.AIPROXY_API_TOKEN || process.env.CHAT_API_KEY || '';
1519

1620
export const getAIApi = (props?: { userKey?: OpenaiAccountType; timeout?: number }) => {
1721
const { userKey, timeout } = props || {};
1822

1923
const baseUrl = userKey?.baseUrl || global?.systemEnv?.oneapiUrl || openaiBaseUrl;
20-
const apiKey = userKey?.key || global?.systemEnv?.chatApiKey || process.env.CHAT_API_KEY || '';
21-
24+
const apiKey = userKey?.key || global?.systemEnv?.chatApiKey || openaiBaseKey;
2225
return new OpenAI({
2326
baseURL: baseUrl,
2427
apiKey,
@@ -72,6 +75,7 @@ export const createChatCompletion = async ({
7275
userKey,
7376
timeout: formatTimeout
7477
});
78+
7579
const response = await ai.chat.completions.create(body, {
7680
...options,
7781
...(modelConstantsData.requestUrl ? { path: modelConstantsData.requestUrl } : {}),

packages/service/support/user/team/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { TeamDefaultPermissionVal } from '@fastgpt/global/support/permission/use
1515
import { MongoMemberGroupModel } from '../../permission/memberGroup/memberGroupSchema';
1616
import { mongoSessionRun } from '../../../common/mongo/sessionRun';
1717
import { DefaultGroupName } from '@fastgpt/global/support/user/team/group/constant';
18-
import { getAIApi, openaiBaseUrl } from '../../../core/ai/config';
18+
import { getAIApi } from '../../../core/ai/config';
1919
import { createRootOrg } from '../../permission/org/controllers';
2020
import { refreshSourceAvatar } from '../../../common/file/image/controller';
2121

@@ -152,7 +152,7 @@ export async function updateTeam({
152152
// auth openai key
153153
if (openaiAccount?.key) {
154154
console.log('auth user openai key', openaiAccount?.key);
155-
const baseUrl = openaiAccount?.baseUrl || openaiBaseUrl;
155+
const baseUrl = openaiAccount?.baseUrl || 'https://api.openai.com/v1';
156156
openaiAccount.baseUrl = baseUrl;
157157

158158
const ai = getAIApi({

packages/web/components/common/DateRangePicker/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ const DateRangePicker = ({
100100
if (date?.to === undefined) {
101101
date.to = date.from;
102102
}
103+
104+
if (date?.from) {
105+
date.from = new Date(date.from.setHours(0, 0, 0, 0));
106+
}
107+
if (date?.to) {
108+
date.to = new Date(date.to.setHours(23, 59, 59, 999));
109+
}
103110
setRange(date);
104111
onChange?.(date);
105112
}}

packages/web/components/common/Icon/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @ts-nocheck
2+
23
export const iconPaths = {
34
book: () => import('./icons/book.svg'),
45
change: () => import('./icons/change.svg'),
@@ -32,8 +33,10 @@ export const iconPaths = {
3233
'common/customTitleLight': () => import('./icons/common/customTitleLight.svg'),
3334
'common/data': () => import('./icons/common/data.svg'),
3435
'common/dingtalkFill': () => import('./icons/common/dingtalkFill.svg'),
36+
'common/disable': () => import('./icons/common/disable.svg'),
3537
'common/downArrowFill': () => import('./icons/common/downArrowFill.svg'),
3638
'common/editor/resizer': () => import('./icons/common/editor/resizer.svg'),
39+
'common/enable': () => import('./icons/common/enable.svg'),
3740
'common/errorFill': () => import('./icons/common/errorFill.svg'),
3841
'common/file/move': () => import('./icons/common/file/move.svg'),
3942
'common/folderFill': () => import('./icons/common/folderFill.svg'),
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

packages/web/components/common/Input/NumberInput/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,31 @@ import React from 'react';
1010
import MyIcon from '../../Icon';
1111
import { UseFormRegister } from 'react-hook-form';
1212

13-
type Props = Omit<NumberInputProps, 'onChange'> & {
13+
type Props = Omit<NumberInputProps, 'onChange' | 'onBlur'> & {
1414
onChange?: (e?: number) => any;
15+
onBlur?: (e?: number) => any;
1516
placeholder?: string;
1617
register?: UseFormRegister<any>;
1718
name?: string;
1819
bg?: string;
1920
};
2021

2122
const MyNumberInput = (props: Props) => {
22-
const { register, name, onChange, placeholder, bg, ...restProps } = props;
23+
const { register, name, onChange, onBlur, placeholder, bg, ...restProps } = props;
2324

2425
return (
2526
<NumberInput
2627
{...restProps}
28+
onBlur={(e) => {
29+
if (!onBlur) return;
30+
const numE = Number(e.target.value);
31+
if (isNaN(numE)) {
32+
// @ts-ignore
33+
onBlur('');
34+
} else {
35+
onBlur(numE);
36+
}
37+
}}
2738
onChange={(e) => {
2839
if (!onChange) return;
2940
const numE = Number(e);
@@ -38,6 +49,8 @@ const MyNumberInput = (props: Props) => {
3849
<NumberInputField
3950
bg={bg}
4051
placeholder={placeholder}
52+
h={restProps.h}
53+
defaultValue={restProps.defaultValue}
4154
{...(register && name
4255
? register(name, {
4356
required: props.isRequired,

0 commit comments

Comments
 (0)