Context extract support value type (#1620)

* perf: chat box components

* perf: chatbox context

* feat: extract support value type

* workflow performance

* update doc

* feat: error response

* feat: error response

* oauth sort

* perf: logo

* fix: update laf account

* perf: team permission api

* update type
This commit is contained in:
Archer
2024-05-28 23:33:05 +08:00
committed by GitHub
parent 8ba8488086
commit 1e48922bc9
48 changed files with 232 additions and 178 deletions

View File

@@ -24,22 +24,26 @@ A2:
`
};
export const Prompt_ExtractJson = `你可以从 <对话记录></对话记录> 中提取指定 JSON 信息,你仅需返回 JSON 字符串,无需回答问题。
export const Prompt_ExtractJson = `你可以从 <对话记录></对话记录> 中提取指定 Json 信息,你仅需返回 Json 字符串,无需回答问题。
<提取要求>
{{description}}
</提取要求>
<字段说明>
1. 下面的 JSON 字符串均按照 JSON Schema 的规则描述
2. key 代表字段名description 代表字段的描述enum 是可选值,代表可选的 value。
3. 如果没有可提取的内容,忽略该字段。
4. 本次需提取的JSON Schema{{json}}
</字段说明>
<提取规则>
- 本次需提取的 json 字符串,需符合 JsonSchema 的规则。
- type 代表数据类型; key 代表字段名; description 代表字段的描述; enum 是枚举值,代表可选的 value。
- 如果没有可提取的内容,忽略该字段。
</提取规则>
<JsonSchema>
{{json}}
</JsonSchema>
<对话记录>
{{text}}
</对话记录>
`;
提取的 json 字符串:`;
export const Prompt_CQJson = `请帮我执行一个“问题分类”任务,将问题分类为以下几种类型之一:

View File

@@ -31,6 +31,7 @@ export type DispatchNodeResponseType = {
runningTime?: number;
query?: string;
textOutput?: string;
error?: Record<string, any>;
customInputs?: Record<string, any>;
customOutputs?: Record<string, any>;

View File

@@ -56,7 +56,7 @@ export const ContextExtractModule: FlowNodeTemplateType = {
label: '',
valueType: WorkflowIOValueTypeEnum.any,
description: "由 '描述' 和 'key' 组成一个目标字段,可提取多个目标字段",
value: [] // {desc: string; key: string; required: boolean; enum: string[]}[]
value: [] // {valueType: string; desc: string; key: string; required: boolean; enum: string[]}[]
}
],
outputs: [

View File

@@ -115,6 +115,7 @@ export type ClassifyQuestionAgentItemType = {
key: string;
};
export type ContextExtractAgentItemType = {
valueType: 'string' | 'number' | 'boolean';
desc: string;
key: string;
required: boolean;

View File

@@ -14,7 +14,6 @@ export type CreateTeamProps = {
lafAccount?: LafAccountType;
};
export type UpdateTeamProps = {
teamId: string;
name?: string;
avatar?: string;
teamDomain?: string;

View File

@@ -11,6 +11,7 @@ export type BillSchemaType = {
status: 'SUCCESS' | 'REFUND' | 'NOTPAY' | 'CLOSED';
type: `${BillTypeEnum}`;
price: number;
hasInvoice: boolean;
metadata: {
payWay: `${BillPayWayEnum}`;
subMode?: `${SubModeEnum}`;
@@ -20,7 +21,6 @@ export type BillSchemaType = {
extraPoints?: number;
invoice: boolean;
};
username: string;
};
export type ChatNodeUsageType = {

View File

@@ -183,7 +183,7 @@ ${description ? `- ${description}` : ''}
> = {};
extractKeys.forEach((item) => {
properties[item.key] = {
type: 'string',
type: item.valueType || 'string',
description: item.desc,
...(item.enum ? { enum: item.enum.split('\n') } : {})
};
@@ -198,7 +198,7 @@ ${description ? `- ${description}` : ''}
required: []
}
};
console.log(properties);
return {
filterMessages,
agentFunction
@@ -319,12 +319,16 @@ const completions = async ({
content: replaceVariable(extractModel.customExtractPrompt || Prompt_ExtractJson, {
description,
json: extractKeys
.map(
(item) =>
`{"key":"${item.key}", "description":"${item.desc}"${
item.enum ? `, "enum":"[${item.enum.split('\n')}]"` : ''
}}`
)
.map((item) => {
const valueType = item.valueType || 'string';
if (valueType !== 'string' && valueType !== 'number') {
item.enum = undefined;
}
return `{"type":${item.valueType || 'string'}, "key":"${item.key}", "description":"${item.desc}" ${
item.enum ? `, "enum":"[${item.enum.split('\n')}]"` : ''
}}`;
})
.join('\n'),
text: `${histories.map((item) => `${item.obj}:${chatValue2RuntimePrompt(item.value).text}`).join('\n')}
Human: ${content}`
@@ -365,6 +369,7 @@ Human: ${content}`
arg: json5.parse(jsonStr) as Record<string, any>
};
} catch (error) {
console.log('Extract error, ai answer:', answer);
console.log(error);
return {
rawResponse: answer,

View File

@@ -45,7 +45,11 @@ export const dispatchRunCode = async (props: RunCodeType): Promise<RunCodeRespon
}
} catch (error) {
return {
[NodeOutputKeyEnum.error]: formatHttpError(error)
[NodeOutputKeyEnum.error]: formatHttpError(error),
[DispatchNodeResponseKeyEnum.nodeResponse]: {
customInputs: customVariables,
error: formatHttpError(error)
}
};
}
};

View File

@@ -5,6 +5,7 @@ import { TeamMemberRoleEnum } from '@fastgpt/global/support/user/team/constant';
import { parseHeaderCert } from '../controller';
import { getTmbInfoByTmbId } from '../../user/team/controller';
import { UserErrEnum } from '../../../../global/common/error/code/user';
import { TeamErrEnum } from '@fastgpt/global/common/error/code/team';
export async function authUserNotVisitor(props: AuthModeType): Promise<
AuthResponseType & {
@@ -47,3 +48,19 @@ export async function authUserRole(props: AuthModeType): Promise<
canWrite
};
}
/* auth teamMember in team role */
export async function authTeamOwner(props: AuthModeType): Promise<
AuthResponseType & {
role: `${TeamMemberRoleEnum}`;
teamOwner: boolean;
}
> {
const authRes = await authUserRole(props);
if (authRes.role !== TeamMemberRoleEnum.owner) {
return Promise.reject(TeamErrEnum.unAuthTeam);
}
return authRes;
}

View File

@@ -7,6 +7,7 @@ import {
} from '@fastgpt/global/support/user/team/constant';
import { MongoTeamMember } from './teamMemberSchema';
import { MongoTeam } from './teamSchema';
import { UpdateTeamProps } from '@fastgpt/global/support/user/team/controller';
async function getTeamMember(match: Record<string, any>): Promise<TeamItemType> {
const tmb = (await MongoTeamMember.findOne(match).populate('teamId')) as TeamMemberWithTeamSchema;
@@ -108,3 +109,18 @@ export async function createDefaultTeam({
});
}
}
export async function updateTeam({
teamId,
name,
avatar,
teamDomain,
lafAccount
}: UpdateTeamProps & { teamId: string }) {
await MongoTeam.findByIdAndUpdate(teamId, {
name,
avatar,
teamDomain,
lafAccount
});
}

View File

@@ -44,18 +44,17 @@ export const useConfirm = (props?: {
const confirmCb = useRef<Function>();
const cancelCb = useRef<any>();
const openConfirm = (
confirm?: Function,
cancel?: any,
customContent?: string | React.ReactNode
) => {
confirmCb.current = confirm;
cancelCb.current = cancel;
const openConfirm = useCallback(
(confirm?: Function, cancel?: any, customContent?: string | React.ReactNode) => {
confirmCb.current = confirm;
cancelCb.current = cancel;
customContent && setCustomContent(customContent);
customContent && setCustomContent(customContent);
return onOpen;
};
return onOpen;
},
[]
);
const ConfirmModal = useCallback(
({