Skip to content

Commit

Permalink
perf: prompt call
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Mar 23, 2024
1 parent e5899c5 commit 471db41
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
5 changes: 4 additions & 1 deletion packages/global/core/module/template/system/datasetSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import { Input_Template_Switch, Input_Template_UserChatInput } from '../input';
import { Output_Template_Finish, Output_Template_UserChatInput } from '../output';
import { DatasetSearchModeEnum } from '../../../dataset/constants';

export const Dataset_SEARCH_DESC =
'调用“语义检索”和“全文检索”能力,从数据库中查找“可能”与问题相关的内容';

export const DatasetSearchModule: FlowNodeTemplateType = {
id: FlowNodeTypeEnum.datasetSearchNode,
templateType: FlowNodeTemplateTypeEnum.functionCall,
flowType: FlowNodeTypeEnum.datasetSearchNode,
avatar: '/imgs/module/db.png',
name: '知识库搜索',
intro: '调用知识库搜索能力,查找“有可能”与问题相关的内容',
intro: Dataset_SEARCH_DESC,
showStatus: true,
isTool: true,
inputs: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
export const Prompt_Tool_Call = `<Instruction>
你是一个智能机器人,除了可以回答用户问题外,你还掌握工具的使用能力。有时候,你可以依赖工具的运行结果,来更准确的回答用户。
下面是你可以使用的工具,使用 JSON Schema 的格式声明,其中 toolId 是工具的 description 是工具的描述,parameters 是工具的参数,包括参数的类型和描述,required 是必填参数的列表。
"""
{{toolsPrompt}}
"""
工具使用了 JSON Schema 的格式声明,其中 toolId 是工具的 description 是工具的描述,parameters 是工具的参数,包括参数的类型和描述,required 是必填参数的列表。
接下来,请你根据工具描述,决定回答问题或是使用工具。在完成任务过程中,USER代表用户的输入,TOOL_RESPONSE代表工具运行结果。ASSISTANT 代表你的输出。
请你根据工具描述,决定回答问题或是使用工具。在完成任务过程中,USER代表用户的输入,TOOL_RESPONSE代表工具运行结果。ASSISTANT 代表你的输出。
你的每次输出都必须以0,1开头,代表是否需要调用工具:
0: 不使用工具,直接回答内容。
1: 使用工具,返回工具调用的参数。
Expand All @@ -29,7 +26,13 @@ TOOL_RESPONSE: """
ANSWER: 0: 今天杭州是晴天,适合去西湖、灵隐寺、千岛湖等地玩。
</Instruction>
现在,我们开始吧!
现在,我们开始吧!下面是你本次可以使用的工具:
"""
{{toolsPrompt}}
"""
下面是正式的对话内容:
USER: {{question}}
ANSWER:
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/web/common/api/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const streamFetch = ({
}

if (responseQueue.length > 0) {
const fetchCount = Math.max(1, Math.round(responseQueue.length / 10));
const fetchCount = Math.max(1, Math.round(responseQueue.length / 30));

for (let i = 0; i < fetchCount; i++) {
const item = responseQueue[i];
Expand Down
3 changes: 2 additions & 1 deletion projects/app/src/web/core/app/templates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AppItemType } from '@/types/app';
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { Dataset_SEARCH_DESC } from '@fastgpt/global/core/module/template/system/datasetSearch';

// template
export const appTemplates: (AppItemType & {
Expand Down Expand Up @@ -876,7 +877,7 @@ export const appTemplates: (AppItemType & {
{
moduleId: '0voh5n',
name: '知识库搜索',
intro: '调用知识库搜索能力,查找“有可能”与问题相关的内容',
intro: Dataset_SEARCH_DESC,
avatar: '/imgs/module/db.png',
flowType: 'datasetSearchNode',
showStatus: true,
Expand Down
7 changes: 5 additions & 2 deletions projects/app/src/web/core/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { FlowNodeInputTypeEnum, FlowNodeTypeEnum } from '@fastgpt/global/core/mo
import { ModuleIOValueTypeEnum, ModuleInputKeyEnum } from '@fastgpt/global/core/module/constants';
import { UserInputModule } from '@fastgpt/global/core/module/template/system/userInput';
import { ToolModule } from '@fastgpt/global/core/module/template/system/tools';
import { DatasetSearchModule } from '@fastgpt/global/core/module/template/system/datasetSearch';
import {
DatasetSearchModule,
Dataset_SEARCH_DESC
} from '@fastgpt/global/core/module/template/system/datasetSearch';
import { getNanoid } from '@fastgpt/global/common/string/tools';

export async function postForm2Modules(data: AppSimpleEditFormType) {
Expand Down Expand Up @@ -489,7 +492,7 @@ export async function postForm2Modules(data: AppSimpleEditFormType) {
{
moduleId: '0voh5n',
name: '知识库搜索',
intro: '调用知识库搜索能力,查找“有可能”与问题相关的内容',
intro: Dataset_SEARCH_DESC,
avatar: '/imgs/module/db.png',
flowType: 'datasetSearchNode',
showStatus: true,
Expand Down

0 comments on commit 471db41

Please sign in to comment.