Documentation
¶
Index ¶
- Variables
- func BuildPrompt(schema, question string) string
- func CleanSQL(sql string) string
- func ExtractSQL(response string) string
- func FewShotExamples() []struct{ ... }
- func FormatSchema(tables []Table) string
- func ParseResponse(response string) (string, error)
- func SystemPrompt() string
- func ValidateSQL(sql string) error
- type ChatMessage
- type ChatRequest
- type ChatResponse
- type Client
- type Column
- type Config
- type GenerateSQLRequest
- type GenerateSQLResponse
- type SQLError
- type Service
- type StreamCallback
- type Table
- type Usage
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptySQL = &SQLError{Message: "SQL query is empty"} ErrNotSelectQuery = &SQLError{Message: "query must be a SELECT statement"} )
Errors
Functions ¶
func BuildPrompt ¶
BuildPrompt builds a complete prompt with schema and question
func ExtractSQL ¶
ExtractSQL extracts SQL query from LLM response
func FewShotExamples ¶
FewShotExamples returns example question-SQL pairs
func FormatSchema ¶
FormatSchema formats database schema for LLM prompt
func ParseResponse ¶
ParseResponse parses LLM response and extracts SQL
func ValidateSQL ¶
ValidateSQL performs basic validation on extracted SQL
Types ¶
type ChatMessage ¶
ChatMessage represents a chat message
func BuildPromptWithContext ¶
func BuildPromptWithContext(schema, question string, history []ChatMessage) []ChatMessage
BuildPromptWithContext builds a prompt with conversation history
func BuildPromptWithExamples ¶
func BuildPromptWithExamples(schema, question string) []ChatMessage
BuildPromptWithExamples builds a prompt with few-shot examples
type ChatRequest ¶
type ChatRequest struct {
Messages []ChatMessage
Stream bool
Temperature float32
MaxTokens int
}
ChatRequest represents a chat completion request
type ChatResponse ¶
ChatResponse represents a chat completion response
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps OpenAI-compatible API client
func (*Client) Chat ¶
func (c *Client) Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)
Chat sends a chat completion request
func (*Client) ChatStream ¶
func (c *Client) ChatStream(ctx context.Context, req ChatRequest, callback StreamCallback) error
ChatStream sends a streaming chat completion request
func (*Client) ChatWithRetry ¶
func (c *Client) ChatWithRetry(ctx context.Context, req ChatRequest, maxRetries int) (*ChatResponse, error)
ChatWithRetry sends a chat request with exponential backoff retry
type GenerateSQLRequest ¶
type GenerateSQLRequest struct {
Question string
Schema string
History []ChatMessage
}
GenerateSQLRequest represents a SQL generation request
type GenerateSQLResponse ¶
type GenerateSQLResponse struct {
SQL string
RawResponse string
TokensUsed int
FinishReason string
}
GenerateSQLResponse represents a SQL generation response
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides high-level LLM operations
func (*Service) GenerateSQL ¶
func (s *Service) GenerateSQL(ctx context.Context, req GenerateSQLRequest) (*GenerateSQLResponse, error)
GenerateSQL generates SQL from natural language question
func (*Service) GenerateSQLStream ¶
func (s *Service) GenerateSQLStream(ctx context.Context, req GenerateSQLRequest, callback func(chunk string) error) (string, error)
GenerateSQLStream generates SQL with streaming
type StreamCallback ¶
StreamCallback is called for each chunk in streaming mode