Update laf module document (#1154)

* Yjl (#74)

* FIX: Query Extension 历史记录拼接不正确 (#1144)

* FIX: Query Extension 历史记录拼接不正确

* add .text

* fix: tts modal close and rerank doc

* laf doc

---------

Co-authored-by: Hexiao Zhang <731931282qq@gmail.com>

* update emb script

* feat: add route push to laf params

* perf: logo size

* README

* README

* laf doc icon

---------

Co-authored-by: Hexiao Zhang <731931282qq@gmail.com>
This commit is contained in:
Archer
2024-04-09 00:15:04 +08:00
committed by GitHub
parent 1fbc407ecf
commit adfad8ff7f
11 changed files with 91 additions and 67 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -31,9 +31,9 @@ weight: 910
3 个模型代码分别为:
1. [https://github.com/labring/FastGPT/tree/main/python/reranker/bge-reranker-base](https://github.com/labring/FastGPT/tree/main/python/reranker/bge-reranker-base)
2. [https://github.com/labring/FastGPT/tree/main/python/reranker/bge-reranker-large](https://github.com/labring/FastGPT/tree/main/python/reranker/bge-reranker-large)
3. [https://github.com/labring/FastGPT/tree/main/python/reranker/bge-rerank-v2-m3](https://github.com/labring/FastGPT/tree/main/python/reranker/bge-rerank-v2-m3)
1. [https://github.com/labring/FastGPT/tree/main/python/bge-rerank/bge-reranker-base](https://github.com/labring/FastGPT/tree/main/python/bge-rerank/bge-reranker-base)
2. [https://github.com/labring/FastGPT/tree/main/python/bge-rerank/bge-reranker-large](https://github.com/labring/FastGPT/tree/main/python/bge-rerank/bge-reranker-large)
3. [https://github.com/labring/FastGPT/tree/main/python/bge-rerank/bge-rerank-v2-m3](https://github.com/labring/FastGPT/tree/main/python/bge-rerank/bge-rerank-v2-m3)
### 3. 安装依赖

View File

@@ -1,59 +1,53 @@
---
title: "Laf 函数调用"
description: "FastGPT Laf 函数调用模块介绍"
icon: "Laf"
icon: "code"
draft: false
toc: true
weight: 355
---
## 特点
- 可重复添加
- 有外部输入
- 手动配置
- 触发执行
- 核中核模块
![](/imgs/laf1.webp)
## 介绍
Laf 函数调用模块可以调用 Laf 账号下的云函数,其操作与 HTTP 模块相同,可以理解为封装了请求 Laf 云函数的 http 模块,值得注意的不同之处为
`Laf 函数调用`模块可以调用 Laf 账号下的云函数,其工作原理与 HTTP 模块相同,有以下特殊特征
- 只能使用 POST 请求
- 请求自带系统参数 systemParams
- 请求自带系统参数 systemParams,无需通过变量传递。
## 具体使用
## 绑定 Laf 账号
调用 Laf 云函数,首先需要绑定 Laf 账号和应用,并且在应用中创建云函数。
要调用 Laf 云函数,首先需要绑定 Laf 账号和应用,并且在应用中创建云函数。
Laf 提供了 PAT(访问凭证) 来实现 Laf 平台外的快捷登录,可以访问 [Laf 文档](https://doc.Laf.run/zh/cli/#%E7%99%BB%E5%BD%95)查看详细如何获取 PAT。
在获取到 PAT 后,我们可以进入 fastgpt 的账号页或是直接在高级编排中使用 Laf 模块,填入 PAT 验证后,选择需要绑定的应用(应用需要是 Running 状态),即可调用 Laf 云函数
在获取到 PAT 后,我们可以进入 FastGPT 的`账号页`或是在高级编排中`Laf模块` 对 Laf 账号进行绑定。Laf 账号是团队共享的,仅团队管理员可配置
填入 PAT 验证后,选择需要绑定的应用(应用需要是 Running 状态),即可调用该应用下的云函数。
> 如果需要解绑则取消绑定后,点击“更新”即可
![](/imgs/laf2.webp)
为了更便捷地调用 Laf 云函数,可以参照下面的代码编写云函数,以便 openAPI 识别
## 编写云函数
Laf 云函数拥有根据 interface 自动生成 OpenAPI 的能力,可以参照下面的代码编写云函数,以便自动生成 OpenAPI 文档。
`Laf模块`可以根据 OpenAPI 文档,自动识别出入参,无需手动添加数据类型。如果不会写 TS可忽略手动在 FastGPT 中添加参数即可。
```ts
import cloud from '@Lafjs/cloud'
import cloud from '@lafjs/cloud'
interface IRequestBody {
username: string // 用户名
passwd?: string // 密码
interface IRequestBody { // 自定义入参FastGPT 传入的均为POST请求。
data1: string // 必填参数
data2?: string // 可选参数
}
interface IResponse {
message: string // 返回信息
data: any // 返回数据
}
type extendedBody = IRequestBody & {
systemParams?: {
appId: string,
interface RequestProps extends IRequestBody { // 完整入参,这个无需改动。
systemParams: { // 这是FastGPT默认会传递过来的参数
appId: string,
variables: string,
histories: string,
cTime: string,
@@ -62,27 +56,45 @@ type extendedBody = IRequestBody & {
}
}
interface IResponse { // 响应内容
message: string // 必返回的参数
msg?: string; // 可选的返回参数
}
export default async function (ctx: FunctionContext): Promise<IResponse> {
const body: extendedBody = ctx.body;
const {
data1,
data2,
systemParams
}: RequestProps = ctx.body;
console.log(body.systemParams.chatId);
console.log({
data1,
data2,
systemParams
});
return {
message: 'ok',
data: '查找到用户名为' + body.username + '的用户'
msg: 'msg'
};
}
```
当然,你也可以在 Laf 平台上选择 fastgpt_template快速生成该函数模板。
具体操作可以是,进入 Laf 的函数页面,新建函数(注意 fastgpt 只会调用 post 请求的函数然后复制上面的代码或者点击更多模板搜索“fastgpt”使用下面的模板
![](/imgs/laf3.webp)
这样就能直接通过点击“同步参数”,一键填写输入输出
## FastGPT 中使用
![](/imgs/laf4.webp)
在选择函数后,可以通过点击“同步参数”,自动同步云函数的参数到 FastGPT 中。当然也可以手动添加,手动修改后的参数不会被“同步参数”修改。
当然也可以手动添加,手动修改后的参数不会被“同步参数”修改
![](/imgs/laf4.png)
## 作用
Laf 账号是绑定在团队上的,团队的成员可以轻松调用已经编写好的云函数
## 使用注意事项
### 调用报错
先在 laf 中调试函数,看是否正常调用。可以通过 console.log打印入参将入参放在 Laf 测试页面的 Body 中进行测试。