mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-02 01:02:05 +08:00
aaa7d17ef1
* feat: encapsulate logger (#6535) * feat: encapsulate logger * update engines --------- Co-authored-by: archer <545436317@qq.com> * next config * dev shell * Agent sandbox (#6532) * docs: switch to docs layout and apply black theme (#6533) * feat: add Gemini 3.1 models - Add gemini-3.1-pro-preview (released February 19, 2026) - Add gemini-3.1-flash-lite-preview (released March 3, 2026) Both models support: - 1M context window - 64k max response - Vision - Tool choice * docs: switch to docs layout and apply black theme - Change layout from notebook to docs - Update logo to icon + text format - Apply fumadocs black theme - Simplify global.css (keep only navbar and TOC styles) - Fix icon components to properly accept className props - Add mobile text overflow handling - Update Node engine requirement to >=20.x * doc * doc * lock * fix: ts * doc * doc --------- Co-authored-by: archer <archer@archerdeMac-mini.local> Co-authored-by: archer <545436317@qq.com> * Doc (#6493) * cloud doc * doc refactor * doc move * seo * remove doc * yml * doc * fix: tsconfig * fix: tsconfig * sandbox version (#6497) * sandbox version * add sandbox log * update lock * fix * fix: sandbox * doc * add console * i18n * sandbxo in agent * feat: agent sandbox * lock * feat: sandbox ui * sandbox check exists * env tempalte * doc * lock * sandbox in chat window * sandbox entry * fix: test * rename var * sandbox config tip * update sandbox lifecircle * update prompt * rename provider test * sandbox logger * yml --------- Co-authored-by: Archer <archer@fastgpt.io> Co-authored-by: archer <archer@archerdeMac-mini.local> * perf: sandbox error tip * Add sandbox limit and fix some issue (#6550) * sandbox in plan * fix: some issue * fix: test * editor default path * fix: comment * perf: sandbox worksapce * doc * perf: del sandbox * sandbox build * fix: test * fix: pr comment --------- Co-authored-by: Ryo <whoeverimf5@gmail.com> Co-authored-by: Archer <archer@fastgpt.io> Co-authored-by: archer <archer@archerdeMac-mini.local>
100 lines
2.2 KiB
Plaintext
100 lines
2.2 KiB
Plaintext
---
|
||
title: 代码运行(弃)
|
||
description: FastGPT 代码运行节点介绍(适用于 4.14.7 及以下版本)
|
||
---
|
||
|
||
> 本文档适用于 FastGPT **4.14.7 及以下版本**。4.14.8 及以上版本请参考 [代码运行(新版)](/docs/introduction/guide/dashboard/workflow/sandbox-v5)。
|
||
|
||

|
||
|
||
## 功能
|
||
|
||
可用于执行一段简单的 js 代码,用于进行一些复杂的数据处理。代码运行在沙盒中,无法进行网络请求、dom和异步操作。如需复杂操作,需外挂 HTTP 实现。
|
||
|
||
**注意事项**
|
||
|
||
- 私有化用户需要部署`fastgpt-sandbox` 镜像,并配置`CODE_SANDBOX_URL`环境变量。
|
||
- 沙盒最大运行 10s, 32M 内存限制。
|
||
|
||
|
||
## 变量输入
|
||
|
||
可在自定义输入中添加代码运行需要的变量,在代码的 main 函数中,可解构出相同名字的变量。
|
||
|
||
如上图,自定义输入中有 data1 和 data2 两个变量,main 函数中可以解构出相同名字的变量。
|
||
|
||
## 结果输出
|
||
|
||
务必返回一个 object 对象
|
||
|
||
自定义输出中,可以添加变量名来获取 object 对应 key 下的值。例如上图中,返回了一个对象:
|
||
|
||
```json
|
||
{
|
||
result: data1,
|
||
data2
|
||
}
|
||
```
|
||
|
||
他有 2 个 key:result和 data2(js 缩写,key=data2,value=data2)。这时候自定义输出中就可以添加 2 个变量来获取对应 key 下的 value。
|
||
|
||
## 内置 JS 全局变量
|
||
|
||
### delay 延迟
|
||
|
||
延迟 1 秒后返回
|
||
|
||
```js
|
||
async function main({data1, data2}){
|
||
await delay(1000)
|
||
return {
|
||
result: "111"
|
||
}
|
||
}
|
||
```
|
||
|
||
### countToken 统计 token
|
||
|
||
```js
|
||
function main({input}){
|
||
return {
|
||
result: countToken(input)
|
||
}
|
||
}
|
||
```
|
||
|
||

|
||
|
||
### strToBase64 字符串转 base64(4.8.11 版本新增)
|
||
|
||
可用于将 SVG 图片转换为 base64 格式展示。
|
||
|
||
```js
|
||
function main({input}){
|
||
|
||
return {
|
||
/*
|
||
param1: input 需要转换的字符串
|
||
param2: base64 prefix 前缀
|
||
*/
|
||
result: strToBase64(input,'data:image/svg+xml;base64,')
|
||
}
|
||
}
|
||
```
|
||
|
||

|
||
|
||
### createHmac 加密
|
||
|
||
与 node 中 crypto 的 createHmac 方法一致。
|
||
|
||
```js
|
||
function main({secret}){
|
||
const {sign,timestamp} = createHmac('sha256',secret)
|
||
|
||
return {
|
||
sign,timestamp
|
||
}
|
||
}
|
||
```
|