types

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 6

Documentation

Index

Constants

View Source
const (
	CompletionMessageRoleTypeUser      = CompletionMessageRoleType("user")
	CompletionMessageRoleTypeSystem    = CompletionMessageRoleType("system")
	CompletionMessageRoleTypeAssistant = CompletionMessageRoleType("assistant")
	CompletionMessageRoleTypeTool      = CompletionMessageRoleType("tool")
)

Chat message role defined by the OpenAI API.

View Source
const (
	DaemonPrefix  = "#!sys.daemon"
	OpenAPIPrefix = "#!sys.openapi"
	EchoPrefix    = "#!sys.echo"
	CommandPrefix = "#!"
)

Variables

This section is empty.

Functions

func FirstSet

func FirstSet[T comparable](in ...T) (result T)

func ObjectSchema

func ObjectSchema(kv ...string) *openapi3.Schema

func PickToolName added in v0.4.0

func PickToolName(toolName string, existing map[string]struct{}) string

func SplitArg added in v0.6.0

func SplitArg(hasArg string) (prefix, arg string)

func SplitToolRef added in v0.7.0

func SplitToolRef(targetToolName string) (toolName, subTool string)

func ToolNormalizer added in v0.4.0

func ToolNormalizer(tool string) string

Types

type BuiltinFunc

type BuiltinFunc func(ctx context.Context, env []string, input string) (string, error)

type CompletionFunctionCall

type CompletionFunctionCall struct {
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`
}

type CompletionFunctionDefinition

type CompletionFunctionDefinition struct {
	ToolID      string           `json:"toolID,omitempty"`
	Name        string           `json:"name"`
	Description string           `json:"description,omitempty"`
	Parameters  *openapi3.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                []CompletionTool    `json:"tools,omitempty"`
	Messages             []CompletionMessage `json:"messages,omitempty"`
	MaxTokens            int                 `json:"maxTokens,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 CompletionStatus struct {
	CompletionID    string
	Request         any
	Response        any
	Usage           Usage
	Cached          bool
	Chunks          any
	PartialResponse *CompletionMessage
}

type CompletionTool

type CompletionTool struct {
	Function CompletionFunctionDefinition `json:"function,omitempty"`
}

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 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       *openapi3.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"`
	Credentials     []string         `json:"credentials,omitempty"`
	Blocking        bool             `json:"-"`
}

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) ChatName added in v0.6.0

func (p Program) ChatName() string

func (Program) GetCompletionTools added in v0.4.0

func (p Program) GetCompletionTools() (result []CompletionTool, err error)

func (Program) GetContextToolRefs added in v0.6.0

func (p Program) GetContextToolRefs(toolID string) ([]ToolReference, error)

func (Program) IsChat added in v0.6.0

func (p Program) IsChat() bool

func (Program) SetBlocking added in v0.3.0

func (p Program) SetBlocking() Program

func (Program) TopLevelTools added in v0.4.0

func (p Program) TopLevelTools() (result []Tool)

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 {
	Parameters   `json:",inline"`
	Instructions string `json:"instructions,omitempty"`

	ID          string            `json:"id,omitempty"`
	ToolMapping map[string]string `json:"toolMapping,omitempty"`
	LocalTools  map[string]string `json:"localTools,omitempty"`
	BuiltinFunc BuiltinFunc       `json:"-"`
	Source      ToolSource        `json:"source,omitempty"`
	WorkingDir  string            `json:"workingDir,omitempty"`
}

func (Tool) GetCompletionTools added in v0.4.0

func (t Tool) GetCompletionTools(prg Program) (result []CompletionTool, err error)

func (Tool) GetContextTools added in v0.7.0

func (t Tool) GetContextTools(prg Program) ([]ToolReference, error)

func (Tool) GetExportedContext added in v0.7.0

func (t Tool) GetExportedContext(prg Program) ([]ToolReference, error)

func (Tool) GetExportedTools added in v0.7.0

func (t Tool) GetExportedTools(prg Program) ([]ToolReference, error)

func (Tool) GetToolRefsFromNames added in v0.6.0

func (t Tool) GetToolRefsFromNames(names []string) (result []ToolReference, _ error)

func (Tool) IsCommand

func (t Tool) IsCommand() bool

func (Tool) IsDaemon

func (t Tool) IsDaemon() bool

func (Tool) IsEcho added in v0.7.0

func (t Tool) IsEcho() bool

func (Tool) IsHTTP

func (t Tool) IsHTTP() bool

func (Tool) IsOpenAPI added in v0.4.0

func (t Tool) IsOpenAPI() bool

func (Tool) String

func (t Tool) String() string

type ToolReference added in v0.6.0

type ToolReference struct {
	Named     string
	Reference string
	Arg       string
	ToolID    string
}

type ToolSet

type ToolSet map[string]Tool

type ToolSource

type ToolSource struct {
	Location string `json:"location,omitempty"`
	LineNo   int    `json:"lineNo,omitempty"`
	Repo     *Repo  `json:"repo,omitempty"`
}

func (ToolSource) String

func (t ToolSource) String() string

type Usage added in v0.7.0

type Usage struct {
	PromptTokens     int `json:"promptTokens,omitempty"`
	CompletionTokens int `json:"completionTokens,omitempty"`
	TotalTokens      int `json:"totalTokens,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL