ai

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultOpenAIModel             = openai.GPT4o
	DefaultMaxTokens               = 1024
	DefaultTemperature             = float32(0.1)
	DefaultTimeout                 = 15 * time.Second // Used for both HTTP client and individual call fallback
	DefaultSystemPromptTableFormat = ``               /* 1639-byte string literal not displayed */

)

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.

Jump to

Keyboard shortcuts

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