Skip to content

Commit d6f8d1a

Browse files
authored
perf: ai proxy log remove retry log;perf: workflow type auto parse;add chunk spliter test (#4296)
* sync collection * remove lock * perf: workflow type auto parse * add chunk spliter test * perf: ai proxy log remove retry log * udpate ai proxy field
1 parent 5fecbaf commit d6f8d1a

File tree

12 files changed

+475
-18
lines changed

12 files changed

+475
-18
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ weight: 799
2626
3. 无 SSL 证书时复制失败,会提示弹窗用于手动复制。
2727
4. FastGPT 未内置 ai proxy 渠道时,也能正常展示其名称。
2828
5. 升级 nextjs 版本至 14.2.25。
29+
6. 工作流节点数组字符串类型,自动适配 string 输入。
30+
7. 工作流节点数组类型,自动进行 JSON parse 解析 string 输入。
31+
8. AI proxy 日志优化,去除重试失败的日志,仅保留最后一份错误日志。
2932

3033
## 🐛 修复
3134

packages/global/core/workflow/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export enum WorkflowIOValueTypeEnum {
2020
number = 'number',
2121
boolean = 'boolean',
2222
object = 'object',
23+
2324
arrayString = 'arrayString',
2425
arrayNumber = 'arrayNumber',
2526
arrayBoolean = 'arrayBoolean',

packages/global/core/workflow/template/input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const Input_Template_Text_Quote: FlowNodeInputItemType = {
7878

7979
export const Input_Template_File_Link: FlowNodeInputItemType = {
8080
key: NodeInputKeyEnum.fileUrlList,
81-
renderTypeList: [FlowNodeInputTypeEnum.reference],
81+
renderTypeList: [FlowNodeInputTypeEnum.reference, FlowNodeInputTypeEnum.input],
8282
label: i18nT('app:workflow.user_file_input'),
8383
debugLabel: i18nT('app:workflow.user_file_input'),
8484
description: i18nT('app:workflow.user_file_input_desc'),

packages/service/core/workflow/dispatch/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,22 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
117117
return Boolean(value);
118118
}
119119
try {
120+
if (WorkflowIOValueTypeEnum.arrayString && typeof value === 'string') {
121+
return [value];
122+
}
120123
if (
121124
type &&
122125
[
123126
WorkflowIOValueTypeEnum.object,
124127
WorkflowIOValueTypeEnum.chatHistory,
125128
WorkflowIOValueTypeEnum.datasetQuote,
126129
WorkflowIOValueTypeEnum.selectApp,
127-
WorkflowIOValueTypeEnum.selectDataset
130+
WorkflowIOValueTypeEnum.selectDataset,
131+
WorkflowIOValueTypeEnum.arrayString,
132+
WorkflowIOValueTypeEnum.arrayNumber,
133+
WorkflowIOValueTypeEnum.arrayBoolean,
134+
WorkflowIOValueTypeEnum.arrayObject,
135+
WorkflowIOValueTypeEnum.arrayAny
128136
].includes(type) &&
129137
typeof value !== 'object'
130138
) {

packages/web/i18n/en/account_model.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"model_tokens": "Input/Output tokens",
3838
"request_at": "Request time",
3939
"request_duration": "Request duration: {{duration}}s",
40+
"retry_times": "Number of retry times",
4041
"running_test": "In testing",
4142
"search_model": "Search for models",
4243
"select_channel": "Select a channel name",

packages/web/i18n/zh-CN/account_model.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"model_tokens": "输入/输出 Tokens",
3838
"request_at": "请求时间",
3939
"request_duration": "请求时长: {{duration}}s",
40+
"retry_times": "重试次数",
4041
"running_test": "测试中",
4142
"search_model": "搜索模型",
4243
"select_channel": "选择渠道名",

packages/web/i18n/zh-Hant/account_model.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"model_tokens": "輸入/輸出 Tokens",
3636
"request_at": "請求時間",
3737
"request_duration": "請求時長: {{duration}}s",
38+
"retry_times": "重試次數",
3839
"running_test": "測試中",
3940
"search_model": "搜索模型",
4041
"select_channel": "選擇渠道名",

projects/app/src/global/aiproxy/type.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export type CreateChannelProps = {
3030
};
3131

3232
// Log
33+
export type ChannelLogUsageType = {
34+
cache_creation_tokens?: number;
35+
cached_tokens?: number;
36+
input_tokens?: number;
37+
output_tokens?: number;
38+
total_tokens?: number;
39+
};
3340
export type ChannelLogListItemType = {
3441
token_name: string;
3542
model: string;
@@ -40,8 +47,8 @@ export type ChannelLogListItemType = {
4047
created_at: number;
4148
request_at: number;
4249
code: number;
43-
prompt_tokens: number;
44-
completion_tokens: number;
50+
usage?: ChannelLogUsageType;
4551
endpoint: string;
4652
content?: string;
53+
retry_times?: number;
4754
};

projects/app/src/pageComponents/account/model/Log/index.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { formatTime2YMDHMS } from '@fastgpt/global/common/string/time';
3333
import MyModal from '@fastgpt/web/components/common/MyModal';
3434
import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip';
3535
import SearchInput from '@fastgpt/web/components/common/Input/SearchInput';
36+
import { ChannelLogUsageType } from '@/global/aiproxy/type';
3637

3738
type LogDetailType = {
3839
id: number;
@@ -42,10 +43,10 @@ type LogDetailType = {
4243
duration: number;
4344
request_at: string;
4445
code: number;
45-
prompt_tokens: number;
46-
completion_tokens: number;
46+
usage?: ChannelLogUsageType;
4747
endpoint: string;
4848

49+
retry_times?: number;
4950
content?: string;
5051
request_body?: string;
5152
response_body?: string;
@@ -159,8 +160,7 @@ const ChannelLog = ({ Tab }: { Tab: React.ReactNode }) => {
159160
duration: durationSecond,
160161
request_at: formatTime2YMDHMS(item.request_at),
161162
code: item.code,
162-
prompt_tokens: item.prompt_tokens,
163-
completion_tokens: item.completion_tokens,
163+
usage: item.usage,
164164
request_id: item.request_id,
165165
endpoint: item.endpoint,
166166
content: item.content
@@ -260,7 +260,7 @@ const ChannelLog = ({ Tab }: { Tab: React.ReactNode }) => {
260260
<Td>{item.channelName}</Td>
261261
<Td>{item.model}</Td>
262262
<Td>
263-
{item.prompt_tokens} / {item.completion_tokens}
263+
{item.usage?.input_tokens} / {item.usage?.output_tokens}
264264
</Td>
265265
<Td color={item.duration > 10 ? 'red.600' : ''}>{item.duration.toFixed(2)}s</Td>
266266
<Td color={item.code === 200 ? 'green.600' : 'red.600'}>
@@ -297,6 +297,7 @@ const LogDetail = ({ data, onClose }: { data: LogDetailType; onClose: () => void
297297
const { t } = useTranslation();
298298
const { data: detailData } = useRequest2(
299299
async () => {
300+
console.log(data);
300301
if (data.code === 200) return data;
301302
try {
302303
const res = await getLogDetail(data.id);
@@ -363,7 +364,7 @@ const LogDetail = ({ data, onClose }: { data: LogDetailType; onClose: () => void
363364
<Title>RequestID</Title>
364365
<Container>{detailData?.request_id}</Container>
365366
</GridItem>
366-
<GridItem display={'flex'} borderBottomWidth="1px" borderRightWidth="1px">
367+
<GridItem display={'flex'} borderBottomWidth="1px">
367368
<Title>{t('account_model:channel_status')}</Title>
368369
<Container color={detailData.code === 200 ? 'green.600' : 'red.600'}>
369370
{detailData?.code}
@@ -373,36 +374,42 @@ const LogDetail = ({ data, onClose }: { data: LogDetailType; onClose: () => void
373374
<Title>Endpoint</Title>
374375
<Container>{detailData?.endpoint}</Container>
375376
</GridItem>
376-
<GridItem display={'flex'} borderBottomWidth="1px" borderRightWidth="1px">
377+
<GridItem display={'flex'} borderBottomWidth="1px">
377378
<Title>{t('account_model:channel_name')}</Title>
378379
<Container>{detailData?.channelName}</Container>
379380
</GridItem>
380381
<GridItem display={'flex'} borderBottomWidth="1px" borderRightWidth="1px">
381382
<Title>{t('account_model:request_at')}</Title>
382383
<Container>{detailData?.request_at}</Container>
383384
</GridItem>
384-
<GridItem display={'flex'} borderBottomWidth="1px" borderRightWidth="1px">
385+
<GridItem display={'flex'} borderBottomWidth="1px">
385386
<Title>{t('account_model:duration')}</Title>
386387
<Container>{detailData?.duration.toFixed(2)}s</Container>
387388
</GridItem>
388389
<GridItem display={'flex'} borderBottomWidth="1px" borderRightWidth="1px">
389390
<Title>{t('account_model:model')}</Title>
390391
<Container>{detailData?.model}</Container>
391392
</GridItem>
392-
<GridItem display={'flex'} borderBottomWidth="1px" borderRightWidth="1px">
393+
<GridItem display={'flex'} borderBottomWidth="1px">
393394
<Title flex={'0 0 150px'}>{t('account_model:model_tokens')}</Title>
394395
<Container>
395-
{detailData?.prompt_tokens} / {detailData?.completion_tokens}
396+
{detailData?.usage?.input_tokens} / {detailData?.usage?.output_tokens}
396397
</Container>
397398
</GridItem>
399+
{detailData?.retry_times !== undefined && (
400+
<GridItem display={'flex'} borderBottomWidth="1px" colSpan={2}>
401+
<Title>{t('account_model:retry_times')}</Title>
402+
<Container>{detailData?.retry_times}</Container>
403+
</GridItem>
404+
)}
398405
{detailData?.content && (
399-
<GridItem display={'flex'} borderBottomWidth="1px" borderRightWidth="1px" colSpan={2}>
406+
<GridItem display={'flex'} borderBottomWidth="1px" colSpan={2}>
400407
<Title>Content</Title>
401408
<Container>{detailData?.content}</Container>
402409
</GridItem>
403410
)}
404411
{detailData?.request_body && (
405-
<GridItem display={'flex'} borderBottomWidth="1px" borderRightWidth="1px" colSpan={2}>
412+
<GridItem display={'flex'} borderBottomWidth="1px" colSpan={2}>
406413
<Title>Request Body</Title>
407414
<Container userSelect={'all'}>{detailData?.request_body}</Container>
408415
</GridItem>

projects/app/src/pageComponents/app/detail/WorkflowComponents/Flow/nodes/render/RenderInput/templates/Reference.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ const MultipleReferenceSelector = ({
247247

248248
// Get valid item and remove invalid item
249249
const formatList = useMemo(() => {
250-
if (!value) return [];
250+
if (!value || !Array.isArray(value)) return [];
251251

252-
return value?.map((item) => {
252+
return value.map((item) => {
253253
const [nodeName, outputName] = getSelectValue(item);
254254
return {
255255
rawValue: item,

0 commit comments

Comments
 (0)