Documentation
¶
Index ¶
- Variables
- func DestroyEnvironment() error
- func InitializeEnvironment() error
- func InitializeGenAiLibrary() error
- func IsInitialized() bool
- func OgaResultToError(result *C.OgaResult) error
- func SetSharedLibraryPath(path string)
- func SetTelemetryEnabled(enabled bool)
- type Engine
- func (e *Engine) Destroy()
- func (e *Engine) Generate(ctx context.Context, messages [][]Message, tools []string, ...) (<-chan SequenceDelta, <-chan error, error)
- func (e *Engine) GetStatistics() *Statistics
- func (e *Engine) Stop()
- func (e *Engine) Submit(ctx context.Context, messages []Message, tools []string, ...) (<-chan SequenceDelta, <-chan error, error)
- type GenerationOptions
- type Guidance
- type GuidanceType
- type Images
- type MaxLengthReachedError
- type Message
- type NamedTensors
- type SequenceDelta
- type Session
- func (s *Session) Destroy()
- func (s *Session) Generate(ctx context.Context, messages [][]Message, tools []string, ...) (<-chan SequenceDelta, <-chan error, error)
- func (s *Session) GenerateWithImages(ctx context.Context, messages [][]Message, images *Images, tools []string, ...) (<-chan SequenceDelta, <-chan error, error)
- func (s *Session) GetStatistics() *Statistics
- type Statistics
Constants ¶
This section is empty.
Variables ¶
var ErrNotInitialized = fmt.Errorf("InitializeEnvironment() has either " +
"not yet been called, or did not return successfully")
Functions ¶
func DestroyEnvironment ¶
func DestroyEnvironment() error
DestroyEnvironment Call this function to clean up the internal onnxruntime environment when it is no longer required.
func InitializeEnvironment ¶
func InitializeEnvironment() error
func InitializeGenAiLibrary ¶
func InitializeGenAiLibrary() error
InitializeGenAiLibrary loads the ONNX Runtime GenAI shared library specified by onnxGenaiSharedLibraryPath (or a default) so its exported symbols become available. The assumption is that libonnxruntime.so is available in the same folder where the libonnxruntime-genai.so is located.
func IsInitialized ¶
func IsInitialized() bool
func OgaResultToError ¶
func SetSharedLibraryPath ¶
func SetSharedLibraryPath(path string)
func SetTelemetryEnabled ¶ added in v0.3.2
func SetTelemetryEnabled(enabled bool)
SetTelemetryEnabled enables or disables telemetry collection in ORT GenAI.
Types ¶
type Engine ¶ added in v0.3.0
type Engine struct {
// contains filtered or unexported fields
}
Engine provides continuous batching via the OgaEngine C API. Multiple goroutines may call Submit concurrently; the engine batches their requests for efficient inference.
func CreateEngine ¶ added in v0.3.0
CreateEngine creates a new Engine from the given model path. The engine starts a background loop that processes submitted requests.
func CreateEngineWithOptions ¶ added in v0.3.0
func CreateEngineWithOptions(configDirectoryPath string, providers []string, providerOptions map[string]map[string]string) (*Engine, error)
CreateEngineWithOptions creates a new Engine with explicit execution provider configuration.
func (*Engine) Destroy ¶ added in v0.3.0
func (e *Engine) Destroy()
Destroy stops the engine and releases all resources. It must not be called concurrently with Submit or other Engine methods.
func (*Engine) Generate ¶ added in v0.3.0
func (e *Engine) Generate(ctx context.Context, messages [][]Message, tools []string, opts *GenerationOptions) (<-chan SequenceDelta, <-chan error, error)
func (*Engine) GetStatistics ¶ added in v0.3.0
func (e *Engine) GetStatistics() *Statistics
GetStatistics returns generation performance metrics for the engine.
func (*Engine) Submit ¶ added in v0.3.0
func (e *Engine) Submit(ctx context.Context, messages []Message, tools []string, opts *GenerationOptions) (<-chan SequenceDelta, <-chan error, error)
Submit submits a generation request to the engine and returns channels for streaming output. Multiple goroutines may call Submit concurrently.
Callers should pass a context with a deadline or timeout. If more than 256 goroutines submit concurrently without deadlines, Stop may block until the excess callers' contexts are cancelled.
type GenerationOptions ¶
type Guidance ¶ added in v0.2.0
type Guidance struct {
Type GuidanceType
Data string
// EnableFFTokens speeds up generation by force-forwarding tokens that satisfy the grammar
// without calling the model. Only valid when BatchSize=1 and beam_size=1.
EnableFFTokens bool
}
Guidance configures constrained (guided) generation. Requires a recent OGA runtime.
type GuidanceType ¶ added in v0.2.0
type GuidanceType string
GuidanceType specifies the constrained-generation strategy passed to OgaGeneratorParamsSetGuidance.
const ( GuidanceTypeJSONSchema GuidanceType = "json_schema" GuidanceTypeRegex GuidanceType = "regex" GuidanceTypeLarkGrammar GuidanceType = "lark_grammar" )
type Images ¶ added in v0.0.2
type Images struct {
// contains filtered or unexported fields
}
Images represents a collection of loaded images for multimodal processing.
func LoadImageFromBuffer ¶ added in v0.0.2
LoadImageFromBuffer loads a single image from a byte buffer.
func LoadImages ¶ added in v0.0.2
LoadImages loads multiple images from file paths or data URIs.
func LoadImagesFromBuffers ¶ added in v0.0.2
LoadImagesFromBuffers loads multiple images from byte buffers.
type MaxLengthReachedError ¶ added in v0.1.0
type MaxLengthReachedError struct{}
func (MaxLengthReachedError) Error ¶ added in v0.1.0
func (e MaxLengthReachedError) Error() string
type NamedTensors ¶ added in v0.0.2
type NamedTensors struct {
// contains filtered or unexported fields
}
NamedTensors represents a collection of named tensor inputs.
func (*NamedTensors) Destroy ¶ added in v0.0.2
func (nt *NamedTensors) Destroy()
Destroy releases the named tensors resources.
type SequenceDelta ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func CreateSession ¶ added in v0.1.0
func CreateSessionWithOptions ¶ added in v0.1.0
func CreateSessionWithOptions(configDirectoryPath string, providers []string, providerOptions map[string]map[string]string) (*Session, error)
CreateSessionWithOptions builds a GenAI config from a config directory, applies execution providers and options, creates the model and tokenizer, and returns a Session. providers: list of EP names in priority order (e.g., ["cuda"], ["NvTensorRtRtx"], ["OpenVINO"]). providerOptions: map of EP name -> map of key/value options.
func (*Session) Generate ¶
func (s *Session) Generate(ctx context.Context, messages [][]Message, tools []string, generationOptions *GenerationOptions) (<-chan SequenceDelta, <-chan error, error)
func (*Session) GenerateWithImages ¶ added in v0.0.2
func (s *Session) GenerateWithImages(ctx context.Context, messages [][]Message, images *Images, tools []string, generationOptions *GenerationOptions) (<-chan SequenceDelta, <-chan error, error)
GenerateWithImages generates text using pre-processed named tensors (for multimodal inputs). Currently only supports a single prompt.
func (*Session) GetStatistics ¶
func (s *Session) GetStatistics() *Statistics
GetStatistics returns the last computed statistics for the session.