Skip to content

Commit

Permalink
perf: some constants data
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Feb 4, 2024
1 parent 90c79c1 commit b628265
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 52 deletions.
7 changes: 5 additions & 2 deletions packages/service/core/ai/functions/queryExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ A: ${chatBg}
stream: false
});

const answer = result.choices?.[0]?.message?.content || '';

let answer = result.choices?.[0]?.message?.content || '';
if (!answer) {
return {
rawQuery: query,
Expand All @@ -152,8 +151,11 @@ A: ${chatBg}
};
}

answer = answer.replace(/\\"/g, '"');

try {
const queries = JSON.parse(answer) as string[];

return {
rawQuery: query,
extensionQueries: queries,
Expand All @@ -162,6 +164,7 @@ A: ${chatBg}
outputTokens: result.usage?.completion_tokens || 0
};
} catch (error) {
console.log(error);
return {
rawQuery: query,
extensionQueries: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const JSONEditor = ({ defaultValue, value, onChange, resize, variables, ...props
onChange={(e) => onChange?.(e || '')}
wrapperProps={{
onBlur: () => {
if (!value) return;
try {
JSON.parse(value as string);
} catch (error: any) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { NodeProps } from 'reactflow';
import NodeCard from '../render/NodeCard';
import { FlowModuleItemType } from '@fastgpt/global/core/module/type.d';
import Divider from '../modules/Divider';
import Container from '../modules/Container';
import RenderInput from '../render/RenderInput';
import RenderOutput from '../render/RenderOutput';

const NodeHttp = ({ data, selected }: NodeProps<FlowModuleItemType>) => {
const { moduleId, inputs, outputs } = data;

return (
<NodeCard minW={'350px'} selected={selected} {...data}>
<Divider text="Input" />
<Container>
<RenderInput moduleId={moduleId} flowInputList={inputs} />
</Container>
<Divider text="Output" />
<Container>
<RenderOutput moduleId={moduleId} flowOutputList={outputs} />
</Container>
</NodeCard>
);
};
export default React.memo(NodeHttp);
2 changes: 1 addition & 1 deletion projects/app/src/components/core/module/Flow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const nodeTypes: Record<`${FlowNodeTypeEnum}`, any> = {
[FlowNodeTypeEnum.answerNode]: dynamic(() => import('./components/nodes/NodeAnswer')),
[FlowNodeTypeEnum.classifyQuestion]: dynamic(() => import('./components/nodes/NodeCQNode')),
[FlowNodeTypeEnum.contentExtract]: dynamic(() => import('./components/nodes/NodeExtract')),
[FlowNodeTypeEnum.httpRequest]: NodeSimple,
[FlowNodeTypeEnum.httpRequest]: dynamic(() => import('./components/nodes/NodeHttp')),
[FlowNodeTypeEnum.runApp]: NodeSimple,
[FlowNodeTypeEnum.pluginInput]: dynamic(() => import('./components/nodes/NodePluginInput')),
[FlowNodeTypeEnum.pluginOutput]: dynamic(() => import('./components/nodes/NodePluginOutput')),
Expand Down
8 changes: 4 additions & 4 deletions projects/app/src/global/core/prompt/AIChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const Prompt_QuotePromptList: PromptTemplateItem[] = [
- 使用 Markdown 语法优化回答格式。
- 使用与问题相同的语言回答。
问题:"{{question}}"`
问题:"""{{question}}"""`
},
{
title: '问答模板',
Expand All @@ -73,7 +73,7 @@ export const Prompt_QuotePromptList: PromptTemplateItem[] = [
- 如果没有相关的问答对,你需要澄清。
- 避免提及你是从 QA 获取的知识,只需要回复答案。
问题:"{{question}}"`
问题:"""{{question}}"""`
},
{
title: '标准严格模板',
Expand All @@ -93,7 +93,7 @@ export const Prompt_QuotePromptList: PromptTemplateItem[] = [
- 使用 Markdown 语法优化回答格式。
- 使用与问题相同的语言回答。
问题:"{{question}}"`
问题:"""{{question}}"""`
},
{
title: '严格问答模板',
Expand All @@ -111,6 +111,6 @@ export const Prompt_QuotePromptList: PromptTemplateItem[] = [
最后,避免提及你是从 QA 获取的知识,只需要回复答案。
问题:"{{question}}"`
问题:"""{{question}}"""`
}
];
67 changes: 22 additions & 45 deletions projects/app/src/service/moduleDispatch/tools/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,72 +26,49 @@ export const dispatchHttpRequest = async (props: HttpRequestProps): Promise<Http
variables,
outputs,
params: {
system_httpMethod: httpMethod,
url: abandonUrl,
system_httpMethod: httpMethod = 'POST',
system_httpReqUrl: httpReqUrl,
system_httpHeader: httpHeader,
...body
}
} = props;

body = flatDynamicParams(body);
if (!httpReqUrl) {
return Promise.reject('Http url is empty');
}

const { requestMethod, requestUrl, requestHeader, requestBody, requestQuery } = await (() => {
// 2024-2-12 clear
if (abandonUrl) {
return {
requestMethod: 'POST',
requestUrl: abandonUrl,
requestHeader: httpHeader,
requestBody: {
...body,
appId,
chatId,
variables
},
requestQuery: {}
};
}
if (httpReqUrl) {
return {
requestMethod: httpMethod,
requestUrl: httpReqUrl,
requestHeader: httpHeader,
requestBody: {
appId,
chatId,
responseChatItemId,
variables,
data: body
},
requestQuery: {
appId,
chatId,
...variables,
...body
}
};
}
body = flatDynamicParams(body);

return Promise.reject('url is empty');
})();
const requestBody = {
appId,
chatId,
responseChatItemId,
variables,
data: body
};
const requestQuery = {
appId,
chatId,
...variables,
...body
};

const formatBody = transformFlatJson({ ...requestBody });

// parse header
const headers = await (() => {
try {
if (!requestHeader) return {};
return JSON.parse(requestHeader);
if (!httpHeader) return {};
return JSON.parse(httpHeader);
} catch (error) {
return Promise.reject('Header 为非法 JSON 格式');
}
})();

try {
const response = await fetchData({
method: requestMethod,
url: requestUrl,
method: httpMethod,
url: httpReqUrl,
headers,
body: formatBody,
query: requestQuery
Expand Down

0 comments on commit b628265

Please sign in to comment.