diff --git a/client/src/constants/flow/ModuleTemplate.ts b/client/src/constants/flow/ModuleTemplate.ts index 0c42940ff..09f0341f6 100644 --- a/client/src/constants/flow/ModuleTemplate.ts +++ b/client/src/constants/flow/ModuleTemplate.ts @@ -278,7 +278,6 @@ export const AnswerModule: FlowModuleTemplateType = { Input_Template_TFSwitch, { key: SpecialInputKeyEnum.answerText, - value: '', type: FlowInputItemTypeEnum.textarea, valueType: FlowValueTypeEnum.string, label: '回复的内容', @@ -331,8 +330,7 @@ export const ClassifyQuestionModule: FlowModuleTemplateType = { label: '系统提示词', description: '你可以添加一些特定内容的介绍,从而更好的识别用户的问题类型。这个内容通常是给模型介绍一个它不知道的内容。', - placeholder: '例如: \n1. Laf 是一个云函数开发平台……\n2. Sealos 是一个集群操作系统', - value: '' + placeholder: '例如: \n1. Laf 是一个云函数开发平台……\n2. Sealos 是一个集群操作系统' }, Input_Template_History, Input_Template_UserChatInput, @@ -393,9 +391,7 @@ export const ContextExtractModule: FlowModuleTemplateType = { label: '提取要求描述', description: '写一段提取要求,告诉 AI 需要提取哪些内容', required: true, - placeholder: - '例如: \n1. 你是一个实验室预约助手。根据用户问题,提取出姓名、实验室号和预约时间', - value: '' + placeholder: '例如: \n1. 你是一个实验室预约助手。根据用户问题,提取出姓名、实验室号和预约时间' }, Input_Template_History, { diff --git a/docSite/docs/flow-modules/examples/imgs/google_search_1.png b/docSite/docs/flow-modules/examples/imgs/google_search_1.png new file mode 100644 index 000000000..0401da342 Binary files /dev/null and b/docSite/docs/flow-modules/examples/imgs/google_search_1.png differ diff --git a/docSite/docs/flow-modules/examples/imgs/google_search_2.png b/docSite/docs/flow-modules/examples/imgs/google_search_2.png new file mode 100644 index 000000000..7b7e3432a Binary files /dev/null and b/docSite/docs/flow-modules/examples/imgs/google_search_2.png differ diff --git a/docSite/docs/flow-modules/examples/index.md b/docSite/docs/flow-modules/examples/index.md deleted file mode 100644 index 329adf8d9..000000000 --- a/docSite/docs/flow-modules/examples/index.md +++ /dev/null @@ -1 +0,0 @@ -# Wait for completion diff --git a/docSite/docs/flow-modules/examples/lab_assistant.md b/docSite/docs/flow-modules/examples/lab_assistant.md new file mode 100644 index 000000000..5dfb41ad2 --- /dev/null +++ b/docSite/docs/flow-modules/examples/lab_assistant.md @@ -0,0 +1 @@ +# 实验室助手 diff --git a/docSite/docs/flow-modules/examples/web_search_google.md b/docSite/docs/flow-modules/examples/web_search_google.md new file mode 100644 index 000000000..ec25aff4c --- /dev/null +++ b/docSite/docs/flow-modules/examples/web_search_google.md @@ -0,0 +1,70 @@ +# Google Search + +![](./imgs/google_search_1.png) +![](./imgs/google_search_2.png) + +As shown in the above images, with the help of the HTTP module, you can easily integrate a search engine. Here, we take calling the Google Search API as an example. + +## Register Google Search API + +[Refer to this article to register the Google Search API](https://zhuanlan.zhihu.com/p/174666017) + +## Create a Google Search interface + +[Here, we use laf to quickly implement an interface, which can be written and published without deployment. Click to open laf cloud](https://laf.dev/), make sure to open the POST request method. + +```ts +import cloud from '@lafjs/cloud'; +const googleSearchKey = ''; +const googleCxId = ''; +const baseurl = 'https://www.googleapis.com/customsearch/v1'; +export default async function (ctx: FunctionContext) { + const { searchKey } = ctx.body; + if (!searchKey) { + return { + prompt: '' + }; + } + try { + const { data } = await cloud.fetch.get(baseurl, { + params: { + q: searchKey, + cx: googleCxId, + key: googleSearchKey, + c2coff: 1, + start: 1, + num: 5, + dateRestrict: 'm[1]' + } + }); + const result = data.items.map((item) => item.snippet).join('\n'); + return { + prompt: `Here are the search results from Google: ${result}`, + searchKey: `\nSearch term: ${searchKey}` + }; + } catch (err) { + console.log(err); + return { + prompt: '' + }; + } +} +``` + +## Workflow + +Drag out a FastGPT workflow as shown in the image, where the request URL of the HTTP module is the interface address, and the input and output parameters are as follows: +**Input** + +``` +searchKey: Search Key Word +``` + +**Output** + +``` +prompt: Search Result +``` + +- The HTTP module will send the searchKey to laf, and laf will perform a Google search based on the received input. It will then return the search results through the prompt parameter. +- After receiving the response, the HTTP module connects to the prompt of the "AI Dialogue" to guide the model in providing an answer. diff --git a/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/imgs/google_search_1.png b/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/imgs/google_search_1.png new file mode 100644 index 000000000..0401da342 Binary files /dev/null and b/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/imgs/google_search_1.png differ diff --git a/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/imgs/google_search_2.png b/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/imgs/google_search_2.png new file mode 100644 index 000000000..7b7e3432a Binary files /dev/null and b/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/imgs/google_search_2.png differ diff --git a/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/index.md b/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/index.md deleted file mode 100644 index b6d2f5223..000000000 --- a/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/index.md +++ /dev/null @@ -1 +0,0 @@ -# 待补充 diff --git a/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/lab_assistant.md b/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/lab_assistant.md new file mode 100644 index 000000000..5dfb41ad2 --- /dev/null +++ b/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/lab_assistant.md @@ -0,0 +1 @@ +# 实验室助手 diff --git a/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/web_search_google.md b/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/web_search_google.md new file mode 100644 index 000000000..3db921802 --- /dev/null +++ b/docSite/i18n/zh-Hans/docusaurus-plugin-content-docs/current/flow-modules/examples/web_search_google.md @@ -0,0 +1,73 @@ +# 谷歌搜索 + +![](./imgs/google_search_1.png) + +![](./imgs/google_search_2.png) + +如上图,利用 HTTP 模块,你可以轻松的外接一个搜索引擎。这里以调用 google search api 为例。 + +## 注册 google search api + +[参考这篇文章,注册 google search api](https://zhuanlan.zhihu.com/p/174666017) + +## 写一个 google search 接口 + +[这里用 laf 快速实现一个接口,即写即发布,无需部署。点击打开 laf cloud](https://laf.dev/),务必打开 POST 请求方式。 + +```ts +import cloud from '@lafjs/cloud'; + +const googleSearchKey = ''; +const googleCxId = ''; +const baseurl = 'https://www.googleapis.com/customsearch/v1'; + +export default async function (ctx: FunctionContext) { + const { searchKey } = ctx.body; + + if (!searchKey) { + return { + prompt: '' + }; + } + + try { + const { data } = await cloud.fetch.get(baseurl, { + params: { + q: searchKey, + cx: googleCxId, + key: googleSearchKey, + c2coff: 1, + start: 1, + num: 5, + dateRestrict: 'm[1]' + } + }); + const result = data.items.map((item) => item.snippet).join('\n'); + return { prompt: `这是 google 搜索的结果: ${result}`, searchKey: `\n搜索词为: ${searchKey}` }; + } catch (err) { + console.log(err); + return { + prompt: '' + }; + } +} +``` + +## 编排 + +按上图拖出一个 FastGPT 编排组合,其中 HTTP 模块的请求地址为接口地址,出入参如下: + +**入参** + +``` +searchKey: 搜索词 +``` + +**出参** + +``` +prompt: 搜索结果 +``` + +- HTTP 模块会将 searchKey 发送到 laf,laf 接收后去进行谷歌搜索,并将搜索的结果通过 prompt 参数返回。 +- 返回后,HTTP 模块连接到【AI 对话】的提示词,引导模型进行回答。