Documentation
¶
Index ¶
Constants ¶
Variables ¶
View Source
var ErrInvalidSQLGeneratedByAI = errors.New("AI generated invalid SQL syntax")
ErrInvalidSQLGeneratedByAI is returned when the SQL generated by AI is not parsable.
Functions ¶
This section is empty.
Types ¶
type ClientOptions ¶
type ClientOptions struct {
APIKey string
Model string
MaxTokens int
Temperature float32
Timeout time.Duration // This timeout is used for HTTP client and as default for callTimeout
BaseURL string
}
ClientOptions contains settings for creating an OpenAI client
type OpenAIClient ¶
type OpenAIClient struct {
// contains filtered or unexported fields
}
OpenAIClient represents a client for interacting with OpenAI's API
func NewClient ¶
func NewClient(opts ClientOptions, logger *slog.Logger) (*OpenAIClient, error)
NewClient creates a new OpenAI client with the given options
func (*OpenAIClient) GenerateSQL ¶
func (c *OpenAIClient) GenerateSQL( ctx context.Context, naturalLanguageQuery string, schema string, tableName string, currentQuery string, ) (string, error)
GenerateSQL generates a SQL query from a natural language query and schema. It uses the model, maxTokens, and temperature configured during client initialization. The provided context should handle overall timeout; this method applies an additional internal timeout (c.callTimeout) for the specific API call.
Click to show internal directories.
Click to hide internal directories.