Code Interpreter
Сигнатуры и описания сгенерированы из GoDoc опубликованного модуля и оставлены на английском.
import "github.com/abox-dev/sdk/packages/go-sdk/codeinterpreter"Package codeinterpreter runs Python, JavaScript, and TypeScript in AgentBox.
Index
- Constants
- type Chart
- type ChartType
- type Client
- type Context
- type CreateContextOptions
- type Execution
- type ExecutionError
- type Language
- type Logs
- type OutputMessage
- type RawData
- type Result
- type RunCodeOptions
- type Sandbox
- func (sandbox *Sandbox) CreateContext(ctx context.Context, options *CreateContextOptions) (*Context, error)
- func (sandbox *Sandbox) ListContexts(ctx context.Context) ([]Context, error)
- func (sandbox *Sandbox) RemoveContext(ctx context.Context, contextID string) error
- func (sandbox *Sandbox) RestartContext(ctx context.Context, contextID string) error
- func (sandbox *Sandbox) RunCode(ctx context.Context, code string, options *RunCodeOptions) (*Execution, error)
- type ScaleType
Constants
const (
// DefaultTemplate is the template used when Create receives no template.
DefaultTemplate = "code-interpreter"
// JupyterPort is the internal Code Interpreter service port.
JupyterPort = 49999
)type Chart
Chart retains typed common chart properties and unknown fields in Extra.
type Chart struct {
Type ChartType `json:"type"`
Title string `json:"title"`
Elements []json.RawMessage `json:"elements"`
XLabel string `json:"x_label,omitempty"`
YLabel string `json:"y_label,omitempty"`
XUnit string `json:"x_unit,omitempty"`
YUnit string `json:"y_unit,omitempty"`
XScale ScaleType `json:"x_scale,omitempty"`
YScale ScaleType `json:"y_scale,omitempty"`
Extra map[string]json.RawMessage `json:"-"`
}func (*Chart) UnmarshalJSON
func (chart *Chart) UnmarshalJSON(data []byte) errorUnmarshalJSON decodes known chart fields and preserves unknown fields in Extra.
type ChartType
ChartType identifies a supported chart representation.
type ChartType stringconst (
// ChartLine identifies a line chart.
ChartLine ChartType = "line"
// ChartScatter identifies a scatter chart.
ChartScatter ChartType = "scatter"
// ChartBar identifies a bar chart.
ChartBar ChartType = "bar"
// ChartPie identifies a pie chart.
ChartPie ChartType = "pie"
// ChartBoxAndWhisker identifies a box-and-whisker chart.
ChartBoxAndWhisker ChartType = "box_and_whisker"
// ChartSuper identifies a composite chart.
ChartSuper ChartType = "superchart"
// ChartUnknown identifies a chart type unknown to this SDK version.
ChartUnknown ChartType = "unknown"
)type Client
Client wraps the core client with Code Interpreter creation helpers.
type Client struct{ Core *agentbox.Client }func NewClient
func NewClient(options ...agentbox.ClientOption) (*Client, error)NewClient creates a Code Interpreter client using the core client options.
func (*Client) Connect
func (client *Client) Connect(ctx context.Context, id string, options *agentbox.ConnectSandboxOptions) (*Sandbox, error)Connect attaches to an existing Code Interpreter sandbox.
func (*Client) Create
func (client *Client) Create(ctx context.Context, options *agentbox.CreateSandboxOptions) (*Sandbox, error)Create creates a Code Interpreter sandbox.
type Context
Context identifies a persistent kernel context.
type Context struct {
ID string `json:"id"`
Language string `json:"language"`
Cwd string `json:"cwd"`
}type CreateContextOptions
CreateContextOptions configures a persistent kernel context.
type CreateContextOptions struct {
Language Language `json:"language,omitempty"`
Cwd string `json:"cwd,omitempty"`
RequestTimeout time.Duration `json:"-"`
}type Execution
Execution contains the complete result of one code execution.
type Execution struct {
Results []Result `json:"results"`
Logs Logs `json:"logs"`
Error *ExecutionError `json:"error,omitempty"`
ExecutionCount int `json:"execution_count,omitempty"`
}func (Execution) Text
func (execution Execution) Text() stringText returns the text representation of the main result, if present.
type ExecutionError
ExecutionError is a kernel error and traceback.
type ExecutionError struct {
Name string `json:"name"`
Value string `json:"value"`
Traceback string `json:"traceback"`
}func (ExecutionError) Error
func (e ExecutionError) Error() stringError formats the kernel error name and value.
type Language
Language is a Code Interpreter runtime language.
type Language stringconst (
// Python selects a Python kernel.
Python Language = "python"
// JavaScript selects a JavaScript kernel.
JavaScript Language = "javascript"
// TypeScript selects a TypeScript kernel.
TypeScript Language = "typescript"
)type Logs
Logs contains collected standard output and standard error lines.
type Logs struct {
Stdout []string `json:"stdout"`
Stderr []string `json:"stderr"`
}type OutputMessage
OutputMessage is one stdout or stderr line.
type OutputMessage struct {
Line string
Timestamp int64
Error bool
}func (OutputMessage) String
func (message OutputMessage) String() stringString returns the output line.
type RawData
RawData preserves every MIME representation returned by the kernel.
type RawData map[string]json.RawMessagetype Result
Result contains the decoded and raw MIME representations of one result.
type Result struct {
Text, HTML, Markdown, SVG, PNG, JPEG, PDF, LaTeX, JSON, JavaScript string
Data map[string]any
Chart *Chart
Extra map[string]json.RawMessage
Raw RawData
IsMainResult bool
}func (Result) Formats
func (result Result) Formats() []stringFormats returns the available raw MIME keys in sorted order.
type RunCodeOptions
RunCodeOptions configures code execution and streaming callbacks.
type RunCodeOptions struct {
Language Language
Context *Context
Env map[string]string
RequestTimeout time.Duration
ExecutionTimeout time.Duration
OnStdout func(OutputMessage)
OnStderr func(OutputMessage)
OnResult func(Result)
OnError func(ExecutionError)
}type Sandbox
Sandbox is a core sandbox with notebook-kernel APIs.
type Sandbox struct{ *agentbox.Sandbox }func (*Sandbox) CreateContext
func (sandbox *Sandbox) CreateContext(ctx context.Context, options *CreateContextOptions) (*Context, error)CreateContext creates a persistent kernel context.
func (*Sandbox) ListContexts
func (sandbox *Sandbox) ListContexts(ctx context.Context) ([]Context, error)ListContexts returns all persistent kernel contexts in the sandbox.
func (*Sandbox) RemoveContext
func (sandbox *Sandbox) RemoveContext(ctx context.Context, contextID string) errorRemoveContext removes a persistent kernel context.
func (*Sandbox) RestartContext
func (sandbox *Sandbox) RestartContext(ctx context.Context, contextID string) errorRestartContext restarts a persistent kernel context.
func (*Sandbox) RunCode
func (sandbox *Sandbox) RunCode(ctx context.Context, code string, options *RunCodeOptions) (*Execution, error)RunCode executes source code and collects streamed NDJSON output.
type ScaleType
ScaleType identifies a chart axis scale.
type ScaleType stringconst (
// ScaleLinear identifies a linear scale.
ScaleLinear ScaleType = "linear"
// ScaleDatetime identifies a date and time scale.
ScaleDatetime ScaleType = "datetime"
// ScaleCategorical identifies a categorical scale.
ScaleCategorical ScaleType = "categorical"
// ScaleLog identifies a logarithmic scale.
ScaleLog ScaleType = "log"
// ScaleSymlog identifies a symmetric logarithmic scale.
ScaleSymlog ScaleType = "symlog"
// ScaleLogit identifies a logit scale.
ScaleLogit ScaleType = "logit"
// ScaleFunction identifies a custom function scale.
ScaleFunction ScaleType = "function"
// ScaleFunctionLog identifies a logarithmic custom function scale.
ScaleFunctionLog ScaleType = "functionlog"
// ScaleAsinh identifies an inverse hyperbolic sine scale.
ScaleAsinh ScaleType = "asinh"
)Generated by gomarkdoc