Documentation
¶
Index ¶
- Constants
- Variables
- func FirstSet[T comparable](in ...T) (result T)
- func GetToolRefInput(prg *Program, ref ToolReference, input string) (string, error)
- func IsMatch(subTool string) bool
- func ObjectSchema(kv ...string) *jsonschema.Schema
- func ParseCredentialArgs(toolName string, input string) (string, string, string, map[string]any, error)
- func PickToolName(toolName string, existing map[string]struct{}) string
- func SplitArg(hasArg string) (prefix, arg string)
- func SplitToolRef(targetToolName string) (toolName, subTool string)
- func ToDisplayText(tool Tool, input string) string
- func ToSysDisplayString(id string, args map[string]string) (string, error)
- func ToToolName(toolName, subTool string) string
- func ToolNormalizer(tool string) string
- type BuiltinFunc
- type ChatCompletionTool
- type CompletionFunctionCall
- type CompletionFunctionDefinition
- type CompletionMessage
- type CompletionMessageRoleType
- type CompletionRequest
- type CompletionStatus
- type CompletionToolCall
- type ContentPart
- type ErrToolNotFound
- type Field
- type Fields
- type Parameters
- type Program
- type Prompt
- type Repo
- type Tool
- func (t *Tool) AddToolMapping(name string, tool Tool)
- func (t Tool) GetChatCompletionTools(prg Program, agentGroup ...ToolReference) (result []ChatCompletionTool, err error)
- func (t Tool) GetInterpreter() string
- func (t Tool) GetNextAgentGroup(prg *Program, agentGroup []ToolReference, toolID string) (result []ToolReference, _ error)
- func (t Tool) GetToolRefsFromNames(names []string) (result []ToolReference, _ error)
- func (t Tool) GetToolsByType(prg *Program, toolType ToolType) ([]ToolReference, error)
- func (t Tool) IsAgentsOnly() bool
- func (t Tool) IsCall() bool
- func (t Tool) IsCommand() bool
- func (t Tool) IsDaemon() bool
- func (t Tool) IsEcho() bool
- func (t Tool) IsHTTP() bool
- func (t Tool) IsMCP() bool
- func (t Tool) IsMCPInvoke() bool
- func (t Tool) IsNoop() bool
- func (t Tool) IsOpenAPI() bool
- type ToolDef
- type ToolReference
- type ToolSet
- type ToolSource
- type ToolType
- type Usage
Constants ¶
const ( CompletionMessageRoleTypeUser = CompletionMessageRoleType("user") CompletionMessageRoleTypeSystem = CompletionMessageRoleType("system") CompletionMessageRoleTypeAssistant = CompletionMessageRoleType("assistant") CompletionMessageRoleTypeTool = CompletionMessageRoleType("tool") )
Chat message role defined by the OpenAI API.
const ( PromptURLEnvVar = "GPTSCRIPT_PROMPT_URL" PromptTokenEnvVar = "GPTSCRIPT_PROMPT_TOKEN" )
const ( DaemonPrefix = "#!sys.daemon" OpenAPIPrefix = "#!sys.openapi" EchoPrefix = "#!sys.echo" CallPrefix = "#!sys.call" MCPPrefix = "#!mcp" MCPInvokePrefix = "#!sys.mcp.invoke." CommandPrefix = "#!" PromptPrefix = "!!" )
const ( ToolTypeContext = ToolType("context") ToolTypeAgent = ToolType("agent") ToolTypeOutput = ToolType("output") ToolTypeInput = ToolType("input") ToolTypeTool = ToolType("tool") ToolTypeCredential = ToolType("credential") ToolTypeDefault = ToolType("") ToolTypeAssistant = ToolType("assistant") ToolTypeProvider = ToolType("provider") )
Variables ¶
var (
DefaultFiles = []string{"agent.gpt", "tool.gpt"}
)
Functions ¶
func FirstSet ¶
func FirstSet[T comparable](in ...T) (result T)
func GetToolRefInput ¶ added in v0.9.6
func GetToolRefInput(prg *Program, ref ToolReference, input string) (string, error)
func ObjectSchema ¶
func ObjectSchema(kv ...string) *jsonschema.Schema
func ParseCredentialArgs ¶ added in v0.8.1
func ParseCredentialArgs(toolName string, input string) (string, string, string, map[string]any, error)
ParseCredentialArgs parses a credential tool name + args into a tool alias (if there is one) and a map of args. Example: "toolName as myCredential with value1 as arg1 and value2 as arg2" -> toolName, myCredential, map[string]any{"arg1": "value1", "arg2": "value2"}, nil
Arg references will be resolved based on the input. Example: - toolName: "toolName with ${var1} as arg1 and ${var2} as arg2" - input: `{"var1": "value1", "var2": "value2"}` result: toolName, "", map[string]any{"arg1": "value1", "arg2": "value2"}, nil
func PickToolName ¶ added in v0.4.0
func SplitArg ¶ added in v0.6.0
SplitArg splits a tool string into the tool name and arguments, and discards the alias if there is one. Examples: toolName => toolName, "" toolName as myAlias => toolName, "" toolName with value1 as arg1 and value2 as arg2 => toolName, "value1 as arg1 and value2 as arg2" toolName as myAlias with value1 as arg1 and value2 as arg2 => toolName, "value1 as arg1 and value2 as arg2"
func SplitToolRef ¶ added in v0.7.0
func ToDisplayText ¶ added in v0.8.0
func ToSysDisplayString ¶ added in v0.8.0
func ToToolName ¶ added in v0.8.3
func ToolNormalizer ¶ added in v0.4.0
Types ¶
type BuiltinFunc ¶
type ChatCompletionTool ¶ added in v0.9.5
type ChatCompletionTool struct {
Function CompletionFunctionDefinition `json:"function,omitempty"`
}
type CompletionFunctionCall ¶
type CompletionFunctionDefinition ¶
type CompletionFunctionDefinition struct {
ToolID string `json:"toolID,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters *jsonschema.Schema `json:"parameters"`
}
type CompletionMessage ¶
type CompletionMessage struct {
Role CompletionMessageRoleType `json:"role,omitempty"`
Content []ContentPart `json:"content,omitempty"`
// ToolCall should be set for only messages of type "tool" and Content[0].Text should be set as the
// result of the call describe by this field
ToolCall *CompletionToolCall `json:"toolCall,omitempty"`
Usage Usage `json:"usage,omitempty"`
}
func (CompletionMessage) ChatText ¶ added in v0.7.0
func (c CompletionMessage) ChatText() string
func (CompletionMessage) IsToolCall ¶
func (c CompletionMessage) IsToolCall() bool
func (CompletionMessage) String ¶
func (c CompletionMessage) String() string
type CompletionMessageRoleType ¶
type CompletionMessageRoleType string
type CompletionRequest ¶
type CompletionRequest struct {
Model string `json:"model,omitempty"`
InternalSystemPrompt *bool `json:"internalSystemPrompt,omitempty"`
Tools []ChatCompletionTool `json:"tools,omitempty"`
Messages []CompletionMessage `json:"messages,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
Chat bool `json:"chat,omitempty"`
Temperature *float32 `json:"temperature,omitempty"`
JSONResponse bool `json:"jsonResponse,omitempty"`
Cache *bool `json:"cache,omitempty"`
}
func (*CompletionRequest) GetCache ¶ added in v0.6.0
func (r *CompletionRequest) GetCache() bool
type CompletionStatus ¶ added in v0.1.4
type CompletionToolCall ¶
type CompletionToolCall struct {
Index *int `json:"index,omitempty"`
ID string `json:"id,omitempty"`
Function CompletionFunctionCall `json:"function,omitempty"`
}
type ContentPart ¶
type ContentPart struct {
Text string `json:"text,omitempty"`
ToolCall *CompletionToolCall `json:"toolCall,omitempty"`
}
func Text ¶
func Text(text string) []ContentPart
type ErrToolNotFound ¶ added in v0.4.0
type ErrToolNotFound struct {
ToolName string
}
func NewErrToolNotFound ¶ added in v0.5.0
func NewErrToolNotFound(toolName string) *ErrToolNotFound
func (*ErrToolNotFound) Error ¶ added in v0.4.0
func (e *ErrToolNotFound) Error() string
type Field ¶ added in v0.9.6
type Field struct {
Name string `json:"name,omitempty"`
Sensitive *bool `json:"sensitive,omitempty"`
Description string `json:"description,omitempty"`
Options []string `json:"options,omitempty"`
}
func (*Field) UnmarshalJSON ¶ added in v0.9.6
UnmarshalJSON will unmarshal the corresponding JSON object for a Field, or a string (for backwards compatibility).
type Fields ¶ added in v0.9.6
type Fields []Field
func (*Fields) UnmarshalJSON ¶ added in v0.9.6
UnmarshalJSON will unmarshal the corresponding JSON object for Fields, or a comma-separated strings (for backwards compatibility).
type Parameters ¶
type Parameters struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
ModelName string `json:"modelName,omitempty"`
ModelProvider bool `json:"modelProvider,omitempty"`
JSONResponse bool `json:"jsonResponse,omitempty"`
Chat bool `json:"chat,omitempty"`
Temperature *float32 `json:"temperature,omitempty"`
Cache *bool `json:"cache,omitempty"`
InternalPrompt *bool `json:"internalPrompt"`
Arguments *jsonschema.Schema `json:"arguments,omitempty"`
Tools []string `json:"tools,omitempty"`
GlobalTools []string `json:"globalTools,omitempty"`
GlobalModelName string `json:"globalModelName,omitempty"`
Context []string `json:"context,omitempty"`
ExportContext []string `json:"exportContext,omitempty"`
Export []string `json:"export,omitempty"`
Agents []string `json:"agents,omitempty"`
Credentials []string `json:"credentials,omitempty"`
ExportCredentials []string `json:"exportCredentials,omitempty"`
InputFilters []string `json:"inputFilters,omitempty"`
ExportInputFilters []string `json:"exportInputFilters,omitempty"`
OutputFilters []string `json:"outputFilters,omitempty"`
ExportOutputFilters []string `json:"exportOutputFilters,omitempty"`
Blocking bool `json:"-"`
Stdin bool `json:"stdin,omitempty"`
Type ToolType `json:"type,omitempty"`
}
func (Parameters) ToolRefNames ¶ added in v0.8.0
func (p Parameters) ToolRefNames() []string
type Program ¶
type Program struct {
Name string `json:"name,omitempty"`
EntryToolID string `json:"entryToolId,omitempty"`
ToolSet ToolSet `json:"toolSet,omitempty"`
OpenAPICache map[string]any `json:"-"`
}
func (Program) SetBlocking ¶ added in v0.3.0
func (Program) TopLevelTools ¶ added in v0.4.0
type Repo ¶ added in v0.2.0
type Repo struct {
// VCS The VCS type, such as "git"
VCS string
// The URL where the VCS repo can be found
Root string
// The path in the repo of this source. This should refer to a directory and not the actual file
Path string
// The filename of the source in the repo, relative to Path
Name string
// The revision of this source
Revision string
}
type Tool ¶
type Tool struct {
ToolDef `json:",inline"`
ID string `json:"id,omitempty"`
ToolMapping map[string][]ToolReference `json:"toolMapping,omitempty"`
LocalTools map[string]string `json:"localTools,omitempty"`
Source ToolSource `json:"source,omitempty"`
WorkingDir string `json:"workingDir,omitempty"`
}
func (*Tool) AddToolMapping ¶ added in v0.7.1
func (Tool) GetChatCompletionTools ¶ added in v0.9.5
func (t Tool) GetChatCompletionTools(prg Program, agentGroup ...ToolReference) (result []ChatCompletionTool, err error)
func (Tool) GetInterpreter ¶ added in v0.8.0
func (Tool) GetNextAgentGroup ¶ added in v0.8.4
func (t Tool) GetNextAgentGroup(prg *Program, agentGroup []ToolReference, toolID string) (result []ToolReference, _ error)
func (Tool) GetToolRefsFromNames ¶ added in v0.6.0
func (t Tool) GetToolRefsFromNames(names []string) (result []ToolReference, _ error)
func (Tool) GetToolsByType ¶ added in v0.9.5
func (t Tool) GetToolsByType(prg *Program, toolType ToolType) ([]ToolReference, error)
func (Tool) IsAgentsOnly ¶ added in v0.9.3
func (Tool) IsMCPInvoke ¶ added in v0.9.6
type ToolDef ¶ added in v0.7.1
type ToolDef struct {
Parameters `json:",inline"`
Instructions string `json:"instructions,omitempty"`
BuiltinFunc BuiltinFunc `json:"-"`
MetaData map[string]string `json:"metaData,omitempty"`
}
type ToolReference ¶ added in v0.6.0
type ToolSource ¶
type ToolSource struct {
Location string `json:"location,omitempty"`
LineNo int `json:"lineNo,omitempty"`
Repo *Repo `json:"repo,omitempty"`
}
func (ToolSource) IsGit ¶ added in v0.9.5
func (t ToolSource) IsGit() bool
func (ToolSource) String ¶
func (t ToolSource) String() string