Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Dec 24, 2024
1 parent d15ab98 commit fcc2d0a
Show file tree
Hide file tree
Showing 33 changed files with 148 additions and 353 deletions.
19 changes: 5 additions & 14 deletions packages/global/core/workflow/runtime/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,20 @@ import { ReadFileNodeResponse } from '../template/system/readFiles/type';
import { UserSelectOptionType } from '../template/system/userSelect/type';
import { WorkflowResponseType } from '../../../../service/core/workflow/dispatch/type';
import { AiChatQuoteRoleType } from '../template/system/aiChat/type';
import {
ExternalWorkflowVariableType,
LafAccountType,
OpenaiAccountType
} from '../../../support/user/team/type';
import { LafAccountType, OpenaiAccountType } from '../../../support/user/team/type';

export type UserExternalProviderConfigType = {
timezone: string;
};

export type TeamExternalProviderConfigType = {
lafAccount?: LafAccountType;
export type ExternalProviderType = {
openaiAccount?: OpenaiAccountType;
externalWorkflowVariables?: ExternalWorkflowVariableType[];
externalWorkflowVariables?: Record<string, string>;
};

/* workflow props */
export type ChatDispatchProps = {
res?: NextApiResponse;
requestOrigin?: string;
mode: 'test' | 'chat' | 'debug';
user: UserExternalProviderConfigType;
team: TeamExternalProviderConfigType;
timezone: string;
externalProvider: ExternalProviderType;

runningAppInfo: {
id: string; // May be the id of the system plug-in (cannot be used directly to look up the table)
Expand Down
9 changes: 2 additions & 7 deletions packages/global/support/user/team/controller.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { PermissionValueType } from '../../permission/type';
import { TeamMemberRoleEnum } from './constant';
import {
ExternalWorkflowVariableType,
LafAccountType,
TeamMemberSchema,
WorkflowVariableType
} from './type';
import { LafAccountType, TeamMemberSchema } from './type';

export type AuthTeamRoleProps = {
teamId: string;
Expand All @@ -25,7 +20,7 @@ export type UpdateTeamProps = {
teamDomain?: string;
lafAccount?: LafAccountType;
openaiAccount?: OpenaiAccountType;
externalWorkflowVariables?: ExternalWorkflowVariableType[];
externalWorkflowVariable?: Record<string, string>;
};

/* ------------- member ----------- */
Expand Down
9 changes: 2 additions & 7 deletions packages/global/support/user/team/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type TeamSchema = {
};
lafAccount?: LafAccountType;
openaiAccount?: OpenaiAccountType;
externalWorkflowVariables?: ExternalWorkflowVariableType[];
externalWorkflowVariables?: Record<string, string>;
notificationAccount?: string;
};

Expand Down Expand Up @@ -70,7 +70,7 @@ export type TeamTmbItemType = {
status: `${TeamMemberStatusEnum}`;
lafAccount?: LafAccountType;
openaiAccount?: OpenaiAccountType;
externalWorkflowVariables?: ExternalWorkflowVariableType[];
externalWorkflowVariables?: Record<string, string>;
notificationAccount?: string;
permission: TeamPermission;
};
Expand Down Expand Up @@ -102,11 +102,6 @@ export type OpenaiAccountType = {
baseUrl: string;
};

export type ExternalWorkflowVariableType = {
key: string;
value: string;
};

export type TeamInvoiceHeaderType = {
teamName: string;
unifiedCreditCode: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ActionProps = Props & { cqModel: LLMModelItemType };
/* request openai chat */
export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse> => {
const {
team,
externalProvider,
node: { nodeId, name },
histories,
params: { model, history = 6, agents, userChatInput }
Expand Down Expand Up @@ -69,7 +69,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse
.filter((item) => item.key !== result.key)
.map((item) => getHandleId(nodeId, 'source', item.key)),
[DispatchNodeResponseKeyEnum.nodeResponse]: {
totalPoints: team.openaiAccount?.key ? 0 : totalPoints,
totalPoints: externalProvider.openaiAccount?.key ? 0 : totalPoints,
model: modelName,
query: userChatInput,
tokens,
Expand All @@ -80,7 +80,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse
[DispatchNodeResponseKeyEnum.nodeDispatchUsages]: [
{
moduleName: name,
totalPoints: team.openaiAccount?.key ? 0 : totalPoints,
totalPoints: externalProvider.openaiAccount?.key ? 0 : totalPoints,
model: modelName,
tokens
}
Expand All @@ -90,7 +90,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse

const completions = async ({
cqModel,
team,
externalProvider,
histories,
params: { agents, systemPrompt = '', userChatInput }
}: ActionProps) => {
Expand Down Expand Up @@ -131,7 +131,7 @@ const completions = async ({
},
cqModel
),
userKey: team.openaiAccount
userKey: externalProvider.openaiAccount
});
const answer = data.choices?.[0].message?.content || '';

Expand Down
18 changes: 9 additions & 9 deletions packages/service/core/workflow/dispatch/agent/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const agentFunName = 'request_function';

export async function dispatchContentExtract(props: Props): Promise<Response> {
const {
team,
externalProvider,
node: { name },
histories,
params: { content, history = 6, model, description, extractKeys }
Expand Down Expand Up @@ -123,7 +123,7 @@ export async function dispatchContentExtract(props: Props): Promise<Response> {
[NodeOutputKeyEnum.contextExtractFields]: JSON.stringify(arg),
...arg,
[DispatchNodeResponseKeyEnum.nodeResponse]: {
totalPoints: team.openaiAccount?.key ? 0 : totalPoints,
totalPoints: externalProvider.openaiAccount?.key ? 0 : totalPoints,
model: modelName,
query: content,
tokens,
Expand All @@ -134,7 +134,7 @@ export async function dispatchContentExtract(props: Props): Promise<Response> {
[DispatchNodeResponseKeyEnum.nodeDispatchUsages]: [
{
moduleName: name,
totalPoints: team.openaiAccount?.key ? 0 : totalPoints,
totalPoints: externalProvider.openaiAccount?.key ? 0 : totalPoints,
model: modelName,
tokens
}
Expand Down Expand Up @@ -211,7 +211,7 @@ ${description ? `- ${description}` : ''}
};

const toolChoice = async (props: ActionProps) => {
const { team, extractModel } = props;
const { externalProvider, extractModel } = props;

const { filterMessages, agentFunction } = await getFunctionCallSchema(props);

Expand All @@ -233,7 +233,7 @@ const toolChoice = async (props: ActionProps) => {
},
extractModel
),
userKey: team.openaiAccount
userKey: externalProvider.openaiAccount
});

const arg: Record<string, any> = (() => {
Expand Down Expand Up @@ -263,7 +263,7 @@ const toolChoice = async (props: ActionProps) => {
};

const functionCall = async (props: ActionProps) => {
const { team, extractModel } = props;
const { externalProvider, extractModel } = props;

const { agentFunction, filterMessages } = await getFunctionCallSchema(props);
const functions: ChatCompletionCreateParams.Function[] = [agentFunction];
Expand All @@ -281,7 +281,7 @@ const functionCall = async (props: ActionProps) => {
},
extractModel
),
userKey: team.openaiAccount
userKey: externalProvider.openaiAccount
});

try {
Expand Down Expand Up @@ -312,7 +312,7 @@ const functionCall = async (props: ActionProps) => {

const completions = async ({
extractModel,
team,
externalProvider,
histories,
params: { content, extractKeys, description = 'No special requirements' }
}: ActionProps) => {
Expand Down Expand Up @@ -360,7 +360,7 @@ Human: ${content}`
},
extractModel
),
userKey: team.openaiAccount
userKey: externalProvider.openaiAccount
});
const answer = data.choices?.[0].message?.content || '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const runToolWithFunctionCall = async (
requestOrigin,
runtimeNodes,
runtimeEdges,
team,
externalProvider,
stream,
workflowStreamResponse,
params: { temperature = 0, maxToken = 4000, aiChatVision }
Expand Down Expand Up @@ -221,7 +221,7 @@ export const runToolWithFunctionCall = async (
getEmptyResponseTip
} = await createChatCompletion({
body: requestBody,
userKey: team.openaiAccount,
userKey: externalProvider.openaiAccount,
options: {
headers: {
Accept: 'application/json, text/plain, */*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise<
requestOrigin,
chatConfig,
runningAppInfo: { teamId },
team,
externalProvider,
params: {
model,
systemPrompt,
Expand Down Expand Up @@ -153,7 +153,7 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise<
})();

// censor model and system key
if (toolModel.censor && !team.openaiAccount?.key) {
if (toolModel.censor && !externalProvider.openaiAccount?.key) {
await postTextCensor({
text: `${systemPrompt}
${userChatInput}
Expand Down Expand Up @@ -228,7 +228,7 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise<
tokens: toolNodeTokens,
modelType: ModelTypeEnum.llm
});
const toolAIUsage = team.openaiAccount?.key ? 0 : totalPoints;
const toolAIUsage = externalProvider.openaiAccount?.key ? 0 : totalPoints;

// flat child tool response
const childToolResponse = dispatchFlowResponse.map((item) => item.flowResponses).flat();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const runToolWithPromptCall = async (
requestOrigin,
runtimeNodes,
runtimeEdges,
team,
externalProvider,
stream,
workflowStreamResponse,
params: { temperature = 0, maxToken = 4000, aiChatVision }
Expand Down Expand Up @@ -230,7 +230,7 @@ export const runToolWithPromptCall = async (
getEmptyResponseTip
} = await createChatCompletion({
body: requestBody,
userKey: team.openaiAccount,
userKey: externalProvider.openaiAccount,
options: {
headers: {
Accept: 'application/json, text/plain, */*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import { AIChatItemType } from '@fastgpt/global/core/chat/type';
import { formatToolResponse, initToolCallEdges, initToolNodes } from './utils';
import { computedMaxToken, llmCompletionsBodyFormat } from '../../../../ai/utils';
import { getNanoid, sliceStrStartEnd } from '@fastgpt/global/common/string/tools';
import { addLog } from '../../../../../common/system/log';
import { toolValueTypeList } from '@fastgpt/global/core/workflow/constants';
import { WorkflowInteractiveResponseType } from '@fastgpt/global/core/workflow/template/system/interactive/type';
import { ChatItemValueTypeEnum } from '@fastgpt/global/core/chat/constants';
import { i18nT } from '../../../../../../web/i18n/utils';

type ToolRunResponseType = {
toolRunResponse: DispatchFlowResponse;
Expand Down Expand Up @@ -92,7 +90,7 @@ export const runToolWithToolChoice = async (
runtimeNodes,
runtimeEdges,
stream,
team,
externalProvider,
workflowStreamResponse,
params: { temperature = 0, maxToken = 4000, aiChatVision }
} = workflowProps;
Expand Down Expand Up @@ -278,7 +276,7 @@ export const runToolWithToolChoice = async (
getEmptyResponseTip
} = await createChatCompletion({
body: requestBody,
userKey: team.openaiAccount,
userKey: externalProvider.openaiAccount,
options: {
headers: {
Accept: 'application/json, text/plain, */*'
Expand Down
10 changes: 5 additions & 5 deletions packages/service/core/workflow/dispatch/chat/oneapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
res,
requestOrigin,
stream = false,
team,
externalProvider,
histories,
node: { name },
query,
Expand Down Expand Up @@ -134,7 +134,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
}),
(() => {
// censor model and system key
if (modelConstantsData.censor && !team.openaiAccount?.key) {
if (modelConstantsData.censor && !externalProvider.openaiAccount?.key) {
return postTextCensor({
text: `${systemPrompt}
${userChatInput}
Expand Down Expand Up @@ -170,7 +170,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
// console.log(JSON.stringify(requestBody, null, 2), '===');
const { response, isStreamResponse, getEmptyResponseTip } = await createChatCompletion({
body: requestBody,
userKey: team.openaiAccount,
userKey: externalProvider.openaiAccount,
options: {
headers: {
Accept: 'application/json, text/plain, */*'
Expand Down Expand Up @@ -230,7 +230,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
return {
answerText,
[DispatchNodeResponseKeyEnum.nodeResponse]: {
totalPoints: team.openaiAccount?.key ? 0 : totalPoints,
totalPoints: externalProvider.openaiAccount?.key ? 0 : totalPoints,
model: modelName,
tokens,
query: `${userChatInput}`,
Expand All @@ -245,7 +245,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
[DispatchNodeResponseKeyEnum.nodeDispatchUsages]: [
{
moduleName: name,
totalPoints: team.openaiAccount?.key ? 0 : totalPoints,
totalPoints: externalProvider.openaiAccount?.key ? 0 : totalPoints,
model: modelName,
tokens
}
Expand Down
Loading

0 comments on commit fcc2d0a

Please sign in to comment.