Documentation
¶
Overview ¶
Package lingo provides local replacements for LingByte/lingoroutine modules.
Index ¶
- Variables
- func CorsMiddleware() gin.HandlerFunc
- func Fail(c *gin.Context, msg string, data interface{})
- func FailWithCode(c *gin.Context, code int, msg string, data interface{})
- func GenerateLingRequestID() string
- func GetBoolEnv(key string) bool
- func GetEnv(key string) string
- func Init(cfg *LogConfig, mode string) error
- func InjectDB(db *gorm.DB) gin.HandlerFunc
- func LoadEnv(mode string) error
- func SetupDatabase(dsn string, models ...any) (*gorm.DB, error)
- func Success(c *gin.Context, msg string, data interface{})
- type ApiResponse
- type Choice
- type LLMOptions
- type LogConfig
- type ParseOptions
- type ParseRequest
- type ParseResult
- type ProviderHandler
- type QueryOptions
- type QueryResult
- type UsageInfo
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnsupportedFileType = errors.New("unsupported file type") ErrEmptyInput = errors.New("empty input") )
var Lg *zap.Logger
Lg is the global zap logger instance.
Functions ¶
func CorsMiddleware ¶
func CorsMiddleware() gin.HandlerFunc
CorsMiddleware returns a Gin middleware that handles CORS headers.
func FailWithCode ¶
FailWithCode returns a custom HTTP status JSON error response.
func GenerateLingRequestID ¶
func GenerateLingRequestID() string
GenerateLingRequestID generates a unique request ID.
func GetBoolEnv ¶
GetBoolEnv reads an environment variable as boolean.
func InjectDB ¶
func InjectDB(db *gorm.DB) gin.HandlerFunc
InjectDB returns a Gin middleware that injects *gorm.DB into the context.
func SetupDatabase ¶
SetupDatabase creates a GORM database connection and auto-migrates models.
Types ¶
type ApiResponse ¶
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 ParseRequest ¶
type ParseResult ¶
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 ¶
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.