llm

package
v0.0.0-...-9bc178f Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderOpenAI    = "openai"
	ProviderOllama    = "ollama"
	ProviderAlibaba   = "alibaba"
	ProviderAnthropic = "anthropic"
	ProviderLMStudio  = "lmstudio"
	ProviderCoze      = "coze"
)
View Source
const (
	LLM_OPENAI    = "llm.openai"
	LLM_ANTHROPIC = "llm.anthropic"
	LLM_COZE      = "llm.coze"
	LLM_OLLAMA    = "llm.ollama"
	LLM_LMSTUDIO  = "llm.lmstudio"
	LLM_ALIBABA   = "llm.alibaba"
)
View Source
const (
	OutputFormatText       = "text"
	OutputFormatJSON       = "json"
	OutputFormatJSONObject = "json_object"
	OutputFormatJSONSchema = "json_schema"
	OutputFormatXML        = "xml"
	OutputFormatHTML       = "html"
	OutputFormatSQL        = "sql"
)

Variables

This section is empty.

Functions

func GenerateLingRequestID

func GenerateLingRequestID() string

Types

type AlibabaHandler

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

func NewAlibabaHandler

func NewAlibabaHandler(ctx context.Context, llmOptions *LLMOptions) (*AlibabaHandler, error)

func (*AlibabaHandler) GetMaxMemoryMessages

func (h *AlibabaHandler) GetMaxMemoryMessages() int

func (*AlibabaHandler) Interrupt

func (h *AlibabaHandler) Interrupt()

func (*AlibabaHandler) Provider

func (h *AlibabaHandler) Provider() string

func (*AlibabaHandler) Query

func (h *AlibabaHandler) Query(text, model string) (string, error)

func (*AlibabaHandler) QueryStream

func (h *AlibabaHandler) QueryStream(text string, options *QueryOptions, callback func(segment string, isComplete bool) error) (*QueryResponse, error)

func (*AlibabaHandler) QueryWithOptions

func (h *AlibabaHandler) QueryWithOptions(text string, options *QueryOptions) (*QueryResponse, error)

func (*AlibabaHandler) ResetMemory

func (h *AlibabaHandler) ResetMemory()

func (*AlibabaHandler) SetMaxMemoryMessages

func (h *AlibabaHandler) SetMaxMemoryMessages(n int)

func (*AlibabaHandler) SummarizeMemory

func (h *AlibabaHandler) SummarizeMemory(model string) (string, error)

type AnthropicHandler

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

func NewAnthropicHandler

func NewAnthropicHandler(ctx context.Context, llmOptions *LLMOptions) (*AnthropicHandler, error)

func (*AnthropicHandler) GetMaxMemoryMessages

func (h *AnthropicHandler) GetMaxMemoryMessages() int

func (*AnthropicHandler) Interrupt

func (h *AnthropicHandler) Interrupt()

func (*AnthropicHandler) Provider

func (h *AnthropicHandler) Provider() string

func (*AnthropicHandler) Query

func (h *AnthropicHandler) Query(text, model string) (string, error)

func (*AnthropicHandler) QueryStream

func (h *AnthropicHandler) QueryStream(text string, options *QueryOptions, callback func(segment string, isComplete bool) error) (*QueryResponse, error)

func (*AnthropicHandler) QueryWithOptions

func (h *AnthropicHandler) QueryWithOptions(text string, options *QueryOptions) (*QueryResponse, error)

func (*AnthropicHandler) ResetMemory

func (h *AnthropicHandler) ResetMemory()

func (*AnthropicHandler) SetMaxMemoryMessages

func (h *AnthropicHandler) SetMaxMemoryMessages(n int)

func (*AnthropicHandler) SummarizeMemory

func (h *AnthropicHandler) SummarizeMemory(model string) (string, error)

type CompletionTokensDetails

type CompletionTokensDetails struct {
	AudioTokens              int
	ReasoningTokens          int
	AcceptedPredictionTokens int
	RejectedPredictionTokens int
}

type CozeHandler

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

func NewCozeHandler

func NewCozeHandler(ctx context.Context, llmOptions *LLMOptions) (*CozeHandler, error)

func (*CozeHandler) GetMaxMemoryMessages

func (h *CozeHandler) GetMaxMemoryMessages() int

func (*CozeHandler) Interrupt

func (h *CozeHandler) Interrupt()

func (*CozeHandler) Provider

func (h *CozeHandler) Provider() string

func (*CozeHandler) Query

func (h *CozeHandler) Query(text, model string) (string, error)

func (*CozeHandler) QueryStream

func (h *CozeHandler) QueryStream(text string, options *QueryOptions, callback func(segment string, isComplete bool) error) (*QueryResponse, error)

func (*CozeHandler) QueryWithOptions

func (h *CozeHandler) QueryWithOptions(text string, options *QueryOptions) (*QueryResponse, error)

func (*CozeHandler) ResetMemory

func (h *CozeHandler) ResetMemory()

func (*CozeHandler) SetMaxMemoryMessages

func (h *CozeHandler) SetMaxMemoryMessages(n int)

func (*CozeHandler) SummarizeMemory

func (h *CozeHandler) SummarizeMemory(model string) (string, error)

type FewShotExample

type FewShotExample struct {
	User      string
	Assistant string
}

type LLMDetails

type LLMDetails struct {
	RequestID               string
	Provider                string
	BaseURL                 string
	Model                   string
	Input                   string
	SystemPrompt            string
	N                       int
	MaxTokens               int
	EstimatedMaxOutputChars int
	FilterEmoji             bool
	RequestedOutputFormat   string
	AppliedResponseFormat   string
	ResponseFormatApplied   bool
	ResponseID              string
	Object                  string
	Created                 int64
	SystemFingerprint       string
	PromptFilterResultsJSON string
	ServiceTierJSON         string
	ChoicesCount            int
	Choices                 []QueryChoice
	Usage                   *TokenUsage
	UsageRawJSON            string
	ChoicesRawJSON          string
	RawResponseJSON         string
}

type LLMHandler

type LLMHandler interface {
	Query(text, model string) (string, error)

	QueryWithOptions(text string, options *QueryOptions) (*QueryResponse, error)

	QueryStream(text string, options *QueryOptions, callback func(segment string, isComplete bool) error) (*QueryResponse, error)

	Provider() string

	Interrupt()

	ResetMemory()

	SummarizeMemory(model string) (string, error)

	SetMaxMemoryMessages(n int)

	GetMaxMemoryMessages() int
}

LLMHandler common llm hanlder interface

func NewLLMProvider

func NewLLMProvider(ctx context.Context, provider, apiKey, apiURL, systemPrompt string) (LLMHandler, error)

NewLLMProvider provides a SoulNexus-like factory signature for Ling.

func NewProviderHandler

func NewProviderHandler(ctx context.Context, provider string, llmOptions *LLMOptions) (LLMHandler, error)

NewProviderHandler creates an LLM handler by provider type. Note: in Ling, non-OpenAI providers currently use OpenAI-compatible chat API shape.

type LLMOptions

type LLMOptions struct {
	Provider        string
	ApiKey          string
	BaseURL         string
	SystemPrompt    string
	FewShotExamples []FewShotExample
	// Logger is optional; used for async memory summarization warnings and diagnostics.
	Logger *zap.Logger
}

type LLMProvider

type LLMProvider string

LLMProvider common provider type

func (LLMProvider) ToString

func (lp LLMProvider) ToString() string

ToString toString for llm

type LMStudioHandler

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

func NewLMStudioHandler

func NewLMStudioHandler(ctx context.Context, llmOptions *LLMOptions) (*LMStudioHandler, error)

func (*LMStudioHandler) GetMaxMemoryMessages

func (h *LMStudioHandler) GetMaxMemoryMessages() int

func (*LMStudioHandler) Interrupt

func (h *LMStudioHandler) Interrupt()

func (*LMStudioHandler) Provider

func (h *LMStudioHandler) Provider() string

func (*LMStudioHandler) Query

func (h *LMStudioHandler) Query(text, model string) (string, error)

func (*LMStudioHandler) QueryStream

func (h *LMStudioHandler) QueryStream(text string, options *QueryOptions, callback func(segment string, isComplete bool) error) (*QueryResponse, error)

func (*LMStudioHandler) QueryWithOptions

func (h *LMStudioHandler) QueryWithOptions(text string, options *QueryOptions) (*QueryResponse, error)

func (*LMStudioHandler) ResetMemory

func (h *LMStudioHandler) ResetMemory()

func (*LMStudioHandler) SetMaxMemoryMessages

func (h *LMStudioHandler) SetMaxMemoryMessages(n int)

func (*LMStudioHandler) SummarizeMemory

func (h *LMStudioHandler) SummarizeMemory(model string) (string, error)

type OllamaHandler

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

func NewOllamaHandler

func NewOllamaHandler(ctx context.Context, llmOptions *LLMOptions) (*OllamaHandler, error)

func (*OllamaHandler) GetMaxMemoryMessages

func (h *OllamaHandler) GetMaxMemoryMessages() int

func (*OllamaHandler) Interrupt

func (h *OllamaHandler) Interrupt()

func (*OllamaHandler) Provider

func (h *OllamaHandler) Provider() string

func (*OllamaHandler) Query

func (h *OllamaHandler) Query(text, model string) (string, error)

func (*OllamaHandler) QueryStream

func (h *OllamaHandler) QueryStream(text string, options *QueryOptions, callback func(segment string, isComplete bool) error) (*QueryResponse, error)

func (*OllamaHandler) QueryWithOptions

func (h *OllamaHandler) QueryWithOptions(text string, options *QueryOptions) (*QueryResponse, error)

func (*OllamaHandler) ResetMemory

func (h *OllamaHandler) ResetMemory()

func (*OllamaHandler) SetMaxMemoryMessages

func (h *OllamaHandler) SetMaxMemoryMessages(n int)

func (*OllamaHandler) SummarizeMemory

func (h *OllamaHandler) SummarizeMemory(model string) (string, error)

type OpenaiHandler

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

func NewOpenaiHandler

func NewOpenaiHandler(ctx context.Context, llmOptions *LLMOptions) (*OpenaiHandler, error)

func (*OpenaiHandler) GetMaxMemoryMessages

func (oh *OpenaiHandler) GetMaxMemoryMessages() int

func (*OpenaiHandler) Interrupt

func (oh *OpenaiHandler) Interrupt()

func (*OpenaiHandler) Provider

func (oh *OpenaiHandler) Provider() string

func (*OpenaiHandler) Query

func (oh *OpenaiHandler) Query(text, model string) (string, error)

func (*OpenaiHandler) QueryStream

func (oh *OpenaiHandler) QueryStream(text string, options *QueryOptions, callback func(segment string, isComplete bool) error) (*QueryResponse, error)

func (*OpenaiHandler) QueryWithOptions

func (oh *OpenaiHandler) QueryWithOptions(text string, options *QueryOptions) (*QueryResponse, error)

func (*OpenaiHandler) ResetMemory

func (oh *OpenaiHandler) ResetMemory()

func (*OpenaiHandler) SetMaxMemoryMessages

func (oh *OpenaiHandler) SetMaxMemoryMessages(n int)

func (*OpenaiHandler) SummarizeMemory

func (oh *OpenaiHandler) SummarizeMemory(model string) (string, error)

type PromptTokensDetails

type PromptTokensDetails struct {
	AudioTokens  int
	CachedTokens int
}

type QueryChoice

type QueryChoice struct {
	Index        int
	Content      string
	FinishReason string
}

type QueryOptions

type QueryOptions struct {
	Model            string
	N                int
	MaxTokens        int
	Temperature      float32
	TopP             float32
	LogitBias        map[string]int
	FilterEmoji      bool
	EnableJSONOutput bool
	OutputFormat     string
	// EmotionalTone, when true, appends a short instruction so replies read warmer and more human (still factual).
	EmotionalTone bool
	// contains filtered or unexported fields
}

type QueryResponse

type QueryResponse struct {
	Provider string
	Model    string
	Choices  []QueryChoice
	Usage    *TokenUsage
}

type TokenUsage

type TokenUsage struct {
	PromptTokens            int
	CompletionTokens        int
	TotalTokens             int
	PromptTokensDetails     *PromptTokensDetails
	CompletionTokensDetails *CompletionTokensDetails
}

Jump to

Keyboard shortcuts

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