lingo

package
v0.0.0-...-ebe1316 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package lingo provides local replacements for LingByte/lingoroutine modules.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedFileType = errors.New("unsupported file type")
	ErrEmptyInput          = errors.New("empty input")
)

Lg is the global zap logger instance.

Functions

func CorsMiddleware

func CorsMiddleware() gin.HandlerFunc

CorsMiddleware returns a Gin middleware that handles CORS headers.

func Fail

func Fail(c *gin.Context, msg string, data interface{})

Fail returns a 400 JSON error response.

func FailWithCode

func FailWithCode(c *gin.Context, code int, msg string, data interface{})

FailWithCode returns a custom HTTP status JSON error response.

func GenerateLingRequestID

func GenerateLingRequestID() string

GenerateLingRequestID generates a unique request ID.

func GetBoolEnv

func GetBoolEnv(key string) bool

GetBoolEnv reads an environment variable as boolean.

func GetEnv

func GetEnv(key string) string

GetEnv reads an environment variable, defaults to empty string.

func Init

func Init(cfg *LogConfig, mode string) error

Init initializes the global logger with the given config.

func InjectDB

func InjectDB(db *gorm.DB) gin.HandlerFunc

InjectDB returns a Gin middleware that injects *gorm.DB into the context.

func LoadEnv

func LoadEnv(mode string) error

LoadEnv loads .env and .env.$MODE files from the working directory.

func SetupDatabase

func SetupDatabase(dsn string, models ...any) (*gorm.DB, error)

SetupDatabase creates a GORM database connection and auto-migrates models.

func Success

func Success(c *gin.Context, msg string, data interface{})

Success returns a 200 JSON success response.

Types

type ApiResponse

type ApiResponse struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data,omitempty"`
}

type Choice

type Choice struct {
	Content      string
	FinishReason string
	ToolCalls    []chatToolCall // 当 finish_reason=tool_calls 时有值
}

Choice is a single completion choice.

type LLMOptions

type LLMOptions struct {
	Provider     string
	ApiKey       string
	BaseURL      string
	SystemPrompt string
	Logger       *zap.Logger
}

LLMOptions configures the LLM provider handler.

type LogConfig

type LogConfig struct {
	Level      string
	Filename   string
	MaxSize    int
	MaxAge     int
	MaxBackups int
	Daily      bool
}

LogConfig matches the lingoroutine logger.LogConfig structure.

type ParseOptions

type ParseOptions struct {
	MaxTextLength      int
	PreserveLineBreaks bool
	IncludeTables      bool
}

type ParseRequest

type ParseRequest struct {
	FileName string
	Content  []byte
	FileType string
}

type ParseResult

type ParseResult struct {
	Text     string
	FileType string
	FileName string
	ParsedAt time.Time
}

func ParseAuto

func ParseAuto(ctx context.Context, req *ParseRequest, opts *ParseOptions) (*ParseResult, error)

ParseAuto tries to parse a document from raw bytes.

type ProviderHandler

type ProviderHandler interface {
	ResetMemory()
	QueryWithOptions(userMessage string, opts *QueryOptions) (*QueryResult, error)
	// RecordToolResult adds a tool execution result to the history(用于多轮工具调用循环)。
	RecordToolResult(toolCallID string, content string)
}

ProviderHandler is the interface for LLM interactions.

func NewProviderHandler

func NewProviderHandler(ctx context.Context, provider string, opts *LLMOptions) (ProviderHandler, error)

NewProviderHandler creates a handler for the specified LLM provider. Supports: openai, ollama, lmstudio, alibaba (qwen), anthropic (claude), coze, siliconflow. All providers use OpenAI-compatible /chat/completions API format.

type QueryOptions

type QueryOptions struct {
	Model       string
	Temperature float32
	MaxTokens   int
}

QueryOptions controls generation parameters for a single query.

type QueryResult

type QueryResult struct {
	Choices   []Choice
	Usage     *UsageInfo
	ToolCalls []chatToolCall // 当 finish_reason=tool_calls 时有值
}

QueryResult represents the response from an LLM query.

type UsageInfo

type UsageInfo struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

UsageInfo tracks token consumption.

Jump to

Keyboard shortcuts

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