Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions srp/lua.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,61 +178,66 @@ Perform a similarity sort between the source and value.
source must be a array of strings, and value must be a string.
return a array of index sorted by similarity.

This is a async function. use `similarity(triggerId, source, value):await()` to wait for the result.
This is an async function. Use `similarity(triggerId, source, value):await()` to wait for the result.

### `generateImage(triggerId, prompt, negative)`

> This function requires low level access.

Generate an image with the prompt and negative. returns the asset CBS (like `{{asset::assetId}}`).

This is a async function. use `generateImage(triggerId, prompt, negative):await()` to wait for the result.
This is an async function. Use `generateImage(triggerId, prompt, negative):await()` to wait for the result.

### `LLM(triggerId, data)`

> This function requires low level access.

Performs a llm request with the data. returns the response.
Performs a LLM request with a message data. Returns the response.

The message data must be a table of messages in the format of:

data must be a message format, with the format of:
```lua
{
-- the message role, can be "system", "assistant", "user"
{
role = "system",
data = "system message"
content = "system message"
},
{
role = "assistant",
data = "char message"
content = "char message"
},
{
role = "user",
data = "user message"
content = "user message"
}
...
}
```

the response format is:
The response format is:

```lua
{
success = true,
message = "response message",
result = "response message",
}
```

This is a async function. use `LLM(triggerId, data):await()` to wait for the result.

### `simpleLLM(triggerId, message)`

> This function requires low level access.

Performs a simple llm request with the message. returns the response.
both the message and response format is string.
Performs a LLM request with a string prompt. Returns the response.

This is a async function. use `simpleLLM(triggerId, message):await()` to wait for the result.
The response format is:

```lua
{
success = true,
result = "response message",
}
```


## Tips
Expand All @@ -246,4 +251,4 @@ This is a async function. use `simpleLLM(triggerId, message):await()` to wait fo
- The lua script is executed in a sandbox environment, so you can't access the file system or network.
- You can't use external libraries except the included `json.lua`.
- If error occurs in the lua script, the application will work as if the script is not executed, and the error message will be displayed in the console.
- The Lua version is based on [Lua 5.4](https://www.lua.org/manual/5.4/)
- The Lua version is based on [Lua 5.4](https://www.lua.org/manual/5.4/)