2
0

(openai) Enable setVariable function in tools

Closes #1178
This commit is contained in:
Baptiste Arnaud
2024-01-22 09:22:28 +01:00
parent b438c174c4
commit 42008f8c18
24 changed files with 258 additions and 43 deletions

View File

@@ -43,7 +43,9 @@ A more useful example would be, of course, to call an API to get the weather of
<img src="/images/blocks/integrations/openai/tools.png" alt="OpenAI tools" />
</Frame>
As you can see, the code block expects the body of the Javascript function. You can use the `return` keyword to return values.
As you can see, the code block expects the body of the Javascript function. You should use the `return` keyword to return value to give back to OpenAI as the result of the function.
If you'd like to set variables directly in this code block, you can use the [`setVariable` function](../logic/script#setvariable-function).
## Ask assistant

View File

@@ -3,9 +3,9 @@ title: Script block
icon: code
---
The "Script" block allows you to execute Javascript code. If you want to set a variable value with Javascript, use the [Set variable block](./set-variable) instead. You can't set a variable with the script block.
The "Script" block allows you to execute Javascript code.
**It doesn't allow you to create a custom visual block**
<Info>This block doesn't allow you to create a custom visual block</Info>
<Frame>
<img src="/images/blocks/logic/code.png" width="600" alt="Code block" />
@@ -18,6 +18,22 @@ You need to write `console.log({{My variable}})` instead of `console.log("{{My v
</Info>
## `setVariable` function
If you want to set a variable value with Javascript, the [Set variable block](./set-variable) is more appropriate for most cases.
However, if you'd like to set variables with the script blocks, you can use the `setVariable` function in your script:
```js
if({{My variable}} === 'foo') {
setVariable('My variable', 'bar')
} else {
setVariable('My variable', 'other')
}
```
The `setVariable` function is only available in script executed on the server, so it won't work if the `Execute on client?` is checked.
## Examples
### Reload page

View File

@@ -371,6 +371,9 @@
"content": {
"type": "string"
},
"isExecutedOnClient": {
"type": "boolean"
},
"shouldExecuteInParentContext": {
"type": "boolean"
}
@@ -6580,6 +6583,9 @@
"content": {
"type": "string"
},
"isExecutedOnClient": {
"type": "boolean"
},
"shouldExecuteInParentContext": {
"type": "boolean"
}
@@ -11101,6 +11107,9 @@
"content": {
"type": "string"
},
"isExecutedOnClient": {
"type": "boolean"
},
"shouldExecuteInParentContext": {
"type": "boolean"
}
@@ -24814,6 +24823,9 @@
"content": {
"type": "string"
},
"isExecutedOnClient": {
"type": "boolean"
},
"shouldExecuteInParentContext": {
"type": "boolean"
}
@@ -28073,6 +28085,9 @@
"content": {
"type": "string"
},
"isExecutedOnClient": {
"type": "boolean"
},
"shouldExecuteInParentContext": {
"type": "boolean"
}
@@ -30882,6 +30897,9 @@
"content": {
"type": "string"
},
"isExecutedOnClient": {
"type": "boolean"
},
"shouldExecuteInParentContext": {
"type": "boolean"
}

View File

@@ -4527,6 +4527,9 @@
"content": {
"type": "string"
},
"isExecutedOnClient": {
"type": "boolean"
},
"shouldExecuteInParentContext": {
"type": "boolean"
}
@@ -8289,6 +8292,9 @@
"content": {
"type": "string"
},
"isExecutedOnClient": {
"type": "boolean"
},
"shouldExecuteInParentContext": {
"type": "boolean"
}