gptscript-ai / gptscript

Build AI assistants that interact with your systems
https://gptscript.ai
Apache License 2.0
3.07k stars 270 forks source link

interp/embedded(expr): init embedded expr-lang.org #818

Closed rinor closed 1 month ago

rinor commented 2 months ago

Experimenting with https://expr-lang.org/. Just a draft implementation to start a feasibility discussion and mostly to check where and how might be useful in practice.

Right now I just converted some stuff from https://github.com/gptscript-ai/context :

Note: For testing, I'm using only builtin stuff language-definition. Things can be improved by exposing additional custom data/functions/types.

Share Input Filter: At syntax filter


Name: At syntax filter Description: Translates @name command into "Call tool name with command"

!sys.interp.expr

// INPUT - variant let input = INPUT == nil || len(INPUT) == 0 ? "" : trim(INPUT); !(input startsWith '@') || len(input) < 2 ? input : let parts = split(input[1:], " ") | map(trim(#)) | filter(len(#) > 0); len(parts) == 1 ? "Call the tool \"" + parts[0] + "\" with defaultPromptParameter as empty" : "Call the tool \"" + parts[0] + "\" with defaultPromptParameter as exactly \"" + join(parts[1:], " ") + "\""


- https://github.com/gptscript-ai/context/tree/main/available-agents

```go
Name: Available Agents
Description: List the agents that are available in the current context
Context: sys.context
Type: context

#!sys.interp.expr
// GPTSCRIPT_CONTEXT
let agents = GPTSCRIPT_CONTEXT.AgentGroup | filter(.ToolID != GPTSCRIPT_CONTEXT.CurrentAgent().ToolID) | map({"\t" + .Named + " " + GPTSCRIPT_CONTEXT.Program.ToolSet[.ToolID].Description});
len(agents) == 0 ? "" : "You have the following (" + string(len(agents)) + ") agent(s) available to you:\n" + join(agents, "\n")

I plan to check and try to convert more scripts and tools to get a better understanding, but please feel free to propose stuff that you would like me to check.

rinor commented 1 month ago

https://github.com/gptscript-ai/gptscript/pull/830#issuecomment-2317952526

embedding will be revisited later on.