Documentation
¶
Overview ¶
Package ds4 provides Go-native conveniences for the ds4 inference engine.
The lower-level github.com/NimbleMarkets/ds4go/ds4api package is the strict purego wrapper around ds4.h. This package owns runtime policy such as default paths, friendly diagnostics, and small convenience entry points.
Index ¶
- Constants
- func DefaultDir() string
- func DefaultLibraryDir() string
- func DefaultLibraryPath() string
- func DefaultModelPath() string
- func EnrichEngineOpenError(err error) error
- func Load(path string) (*ds4api.Library, error)
- func NewEngine(opts ds4api.EngineOptions) (*ds4api.Engine, error)
- func SetDefaultLibrary(lib *ds4api.Library)
- type Backend
- type Engine
- type EngineOptions
- type GenerateOptions
- type Generator
- func (g Generator) Continue(opts GenerateOptions) ([]int, error)
- func (g Generator) Generate(prompt []int, opts GenerateOptions) ([]int, error)
- func (g Generator) GenerateString(prompt string, opts GenerateOptions) (string, error)
- func (g Generator) GenerateTokens(prompt *ds4api.Tokens, opts GenerateOptions) ([]int, error)
- type Library
- type Session
- type ThinkMode
- type TokenEmitFunc
- type Tokens
Constants ¶
const ( // DefaultTemperature is ds4's default sampling temperature. DefaultTemperature = ds4api.DefaultTemperature // DefaultTopP is ds4's default nucleus sampling probability. DefaultTopP = ds4api.DefaultTopP // DefaultMinP is ds4's default minimum relative-probability filter. DefaultMinP = ds4api.DefaultMinP // BackendMetal selects the Metal backend. BackendMetal = ds4api.BackendMetal // BackendCUDA selects the CUDA backend. BackendCUDA = ds4api.BackendCUDA // BackendCPU selects the CPU reference backend. BackendCPU = ds4api.BackendCPU // ThinkNone disables thinking markers in chat prompts. ThinkNone = ds4api.ThinkNone // ThinkHigh enables ordinary high-effort thinking. ThinkHigh = ds4api.ThinkHigh // ThinkMax enables the maximum-effort thinking prefix when the context is large enough. ThinkMax = ds4api.ThinkMax )
Variables ¶
This section is empty.
Functions ¶
func DefaultDir ¶
func DefaultDir() string
DefaultDir returns the ds4go data directory.
DS4_DIR overrides the default. When DS4_DIR is unset, DefaultDir returns "$HOME/.ds4" when the user home directory can be determined, otherwise ".ds4".
func DefaultLibraryDir ¶
func DefaultLibraryDir() string
DefaultLibraryDir returns the directory where libds4 is installed by default: the "lib" subdirectory of DefaultDir.
func DefaultLibraryPath ¶
func DefaultLibraryPath() string
DefaultLibraryPath returns the preferred libds4 shared-library path.
Search order is DS4_LIB, DS4_DIR/lib, executable-local paths, and finally the platform library name for system loader lookup.
The current working directory is deliberately NOT searched: loading a shared library from the CWD would let an attacker who can write a file into a directory the user happens to run ds4go from plant a malicious libds4 and gain code execution (binary planting). Use DS4_LIB or DS4_DIR to load a library from a non-default location.
func DefaultModelPath ¶
func DefaultModelPath() string
DefaultModelPath returns the path to the default model symlink.
The default model is a symlink at $DS4_DIR/models/ds4flash.gguf that points to the active downloaded model. Use ds4go model set to switch it.
func EnrichEngineOpenError ¶
EnrichEngineOpenError adds process names to ds4 engine-open errors that mention lock-holder PIDs.
func Load ¶
Load loads libds4 using ds4go's runtime path policy.
Passing an empty path searches DS4_LIB, DS4_DIR/lib, executable-local library locations, and finally the platform loader path. The current working directory is not searched; see DefaultLibraryPath.
func NewEngine ¶
func NewEngine(opts ds4api.EngineOptions) (*ds4api.Engine, error)
NewEngine loads the default libds4 shared library and opens a ds4 engine.
func SetDefaultLibrary ¶
SetDefaultLibrary makes lib the low-level package default library.
Types ¶
type EngineOptions ¶
type EngineOptions = ds4api.EngineOptions
EngineOptions configures ds4_engine_open.
type GenerateOptions ¶
type GenerateOptions struct {
// MaxTokens is the maximum number of tokens to generate.
MaxTokens int
// Temperature controls sampling. Values <= 0 use argmax.
Temperature float32
// TopK limits sampling to the best k tokens when Temperature > 0.
TopK int
// TopP applies nucleus sampling when Temperature > 0.
TopP float32
// MinP applies minimum probability sampling when Temperature > 0.
MinP float32
// Seed seeds ds4's sampler. A zero seed is valid and deterministic.
Seed uint64
// StopOnEOS stops generation when ds4 emits the engine EOS token.
StopOnEOS bool
// ExcludeToken asks argmax generation to skip a specific token id.
ExcludeToken int
// OnToken streams generated tokens. Returning normally continues generation.
OnToken ds4api.TokenEmitFunc
}
GenerateOptions controls Go-native session generation helpers.
type Generator ¶
Generator binds a ds4 engine and session for Go-native generation helpers.
func (Generator) Continue ¶
func (g Generator) Continue(opts GenerateOptions) ([]int, error)
Continue generates tokens from the current session logits.
func (Generator) Generate ¶
func (g Generator) Generate(prompt []int, opts GenerateOptions) ([]int, error)
Generate synchronizes to prompt and generates tokens from the session.
func (Generator) GenerateString ¶
func (g Generator) GenerateString(prompt string, opts GenerateOptions) (string, error)
GenerateString tokenizes prompt, generates, and decodes the generated text.
func (Generator) GenerateTokens ¶
GenerateTokens synchronizes to prompt and generates tokens from the session.
type TokenEmitFunc ¶
type TokenEmitFunc = ds4api.TokenEmitFunc
TokenEmitFunc is called when ds4 emits a generated token.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
ds4go
command
Command ds4go is a pure-Go CLI for the ds4 inference engine.
|
Command ds4go is a pure-Go CLI for the ds4 inference engine. |
|
Package ds4api provides pure-Go bindings for the ds4 inference engine.
|
Package ds4api provides pure-Go bindings for the ds4 inference engine. |
|
examples
|
|
|
chat
command
Command chat is an interactive ds4 REPL.
|
Command chat is an interactive ds4 REPL. |
|
openai-compatible
command
Command openai-compatible serves a minimal OpenAI-style chat endpoint backed by the ds4 engine.
|
Command openai-compatible serves a minimal OpenAI-style chat endpoint backed by the ds4 engine. |
|
simple
command
Command simple loads a ds4 model and generates one response.
|
Command simple loads a ds4 model and generates one response. |
|
internal
|
|
|
cliopts
Package cliopts defines the command-line flag surface shared by the ds4go CLI and examples.
|
Package cliopts defines the command-line flag surface shared by the ds4go CLI and examples. |
|
install
Package install downloads prebuilt libds4 release assets for the ds4go CLI.
|
Package install downloads prebuilt libds4 release assets for the ds4go CLI. |
|
models
Package models manages ds4go's curated model catalog.
|
Package models manages ds4go's curated model catalog. |