worker

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package worker provides subprocess worker management for llm-compiler. It handles spawning worker processes, communication protocol, and lifecycle management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWorkerProcess

func IsWorkerProcess() bool

IsWorkerProcess returns true if the current process is running as a worker

func ShouldUseSubprocess

func ShouldUseSubprocess() bool

ShouldUseSubprocess returns true if subprocess mode is enabled

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages communication with a worker subprocess

func NewClient

func NewClient() (*Client, error)

NewClient creates and starts a new worker subprocess

func NewClientWithFd

func NewClientWithFd(fd3File *os.File) (*Client, error)

NewClientWithFd creates a worker subprocess and passes the given file as fd3

func (*Client) Close

func (c *Client) Close() error

Close shuts down the worker subprocess

func (*Client) Pid

func (c *Client) Pid() int

Pid returns the process ID of the worker subprocess

func (*Client) SendRequest

func (c *Client) SendRequest(modelSpec, prompt string, maxTokens int) (string, error)

SendRequest sends a request to the worker and waits for the response

type Handler

type Handler interface {
	// Generate processes a prompt and returns the generated text
	Generate(prompt, modelSpec string, maxTokens int) (string, error)
}

Handler is the interface that must be implemented to handle worker requests

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool manages a pool of worker clients for parallel processing

func NewPool

func NewPool(size int) (*Pool, error)

NewPool creates a new worker pool with the specified number of workers

func (*Pool) Close

func (p *Pool) Close() error

Close shuts down all workers in the pool

func (*Pool) Get

func (p *Pool) Get() *Client

Get returns the next client in the pool (round-robin)

func (*Pool) Size

func (p *Pool) Size() int

Size returns the number of workers in the pool

type Request

type Request struct {
	ID        string `json:"id"`
	ModelSpec string `json:"model_spec"`
	Prompt    string `json:"prompt"`
	MaxTokens int    `json:"max_tokens"`
}

Request is sent from client to worker over stdin as JSON newline.

type Response

type Response struct {
	ID  string `json:"id"`
	Val string `json:"val"`
	Err string `json:"err"`
}

Response is sent from worker to client over stdout as JSON newline.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server runs inside a spawned worker process and handles incoming requests

func NewServer

func NewServer(handler Handler) *Server

NewServer creates a new worker server with the given handler

func (*Server) Run

func (s *Server) Run()

Run starts the server loop, reading requests from stdin and writing responses to stdout. This method blocks until stdin is closed or an error occurs.

func (*Server) WriteStatus

func (s *Server) WriteStatus(format string, args ...interface{})

WriteStatus writes a status message to the status output (fd3 or stderr)

Jump to

Keyboard shortcuts

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