Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyExtractedRecipe(sqlDB *db.DB, recipeID int64, extracted *ExtractedRecipe) error
- func ExecuteQuery(database *db.DB, query string) ([]string, [][]string, time.Duration, error)
- func ExtractTextFromPaste(text string) string
- func ExtractTextFromURL(url string) (string, error)
- func RunPipeline(ctx context.Context, cfg PipelineConfig, recipeID int64) (*models.Recipe, error)
- func ScanRow(row *sql.Row, dest ...interface{}) error
- func ValidateReadOnly(sql string) error
- type AIClient
- type AnthropicClient
- type ExecuteQueryResult
- type ExtractedIngredient
- type ExtractedRecipe
- type GenerateSQLResult
- type PipelineConfig
- type ProgressFunc
Constants ¶
const ( StepFetch = 1 StepExtract = 2 StepSave = 3 StepDone = 4 )
Step constants for progress reporting.
const PostgresSchema = `` /* 2530-byte string literal not displayed */
PostgresSchema is the complete DDL for the enplace PostgreSQL database. AUTO-GENERATED from migrations/postgres/*.sql — do not edit manually. Regenerate after adding migrations: see CLAUDE.md "Schema files".
const SQLiteSchema = `` /* 2619-byte string literal not displayed */
SQLiteSchema is the complete DDL for the enplace SQLite database. AUTO-GENERATED from migrations — do not edit manually. Regenerate after adding migrations: see CLAUDE.md "Schema files".
Variables ¶
var StepLabels = map[int]string{ StepFetch: "Fetching recipe content", StepExtract: "Extracting with AI", StepSave: "Saving to database", }
StepLabels maps step numbers to display labels.
Functions ¶
func ApplyExtractedRecipe ¶
func ApplyExtractedRecipe(sqlDB *db.DB, recipeID int64, extracted *ExtractedRecipe) error
ApplyExtractedRecipe writes all AI-extracted data to an existing recipe row. It replaces ingredients and tags, then sets the recipe status to "review". The entire operation runs in a transaction so partial failures are rolled back.
func ExecuteQuery ¶ added in v1.7.0
ExecuteQuery runs a read-only SQL query against the database and returns column names + rows as string slices. It enforces the read-only constraint.
func ExtractTextFromPaste ¶
ExtractTextFromPaste cleans and truncates pasted recipe text.
func ExtractTextFromURL ¶
ExtractTextFromURL fetches a URL and returns clean recipe text. It prioritizes Schema.org JSON-LD, then falls back to main content.
func RunPipeline ¶
RunPipeline orchestrates the three-step recipe extraction pipeline: 1. Fetch & parse content (URL or paste) 2. Extract structured data via Claude 3. Write data to database
It records an AIClassifierRun for steps 1 and 2, and updates recipe status throughout. Returns the populated recipe on success.
func ValidateReadOnly ¶ added in v1.7.0
ValidateReadOnly returns an error if any statement in the SQL is a mutation. It splits on semicolons, strips comments, and checks each statement's leading keyword.
Types ¶
type AIClient ¶
type AIClient interface {
Complete(ctx context.Context, model, systemPrompt, userMessage string) (string, error)
}
AIClient is the interface for calling the Anthropic API. It is an interface to allow mocking in tests.
type AnthropicClient ¶
type AnthropicClient struct {
// contains filtered or unexported fields
}
AnthropicClient wraps the official Anthropic SDK.
func NewAnthropicClient ¶
func NewAnthropicClient(apiKey string) *AnthropicClient
NewAnthropicClient creates an AnthropicClient using the provided API key.
type ExecuteQueryResult ¶ added in v1.7.0
ExecuteQueryResult holds the output of query execution.
type ExtractedIngredient ¶
type ExtractedIngredient struct {
Quantity string `json:"quantity"`
Unit string `json:"unit"`
Name string `json:"name"`
Descriptor *string `json:"descriptor"`
Section *string `json:"section"`
IngredientType *string `json:"ingredient_type"`
UnitWeightG *float64 `json:"unit_weight_g"`
}
ExtractedIngredient is the AI-returned ingredient structure.
type ExtractedRecipe ¶
type ExtractedRecipe struct {
Name string `json:"name"`
Description string `json:"description"`
Directions string `json:"directions"`
PreparationTime *int `json:"preparation_time"`
CookingTime *int `json:"cooking_time"`
Servings *int `json:"servings"`
ServingUnits *string `json:"serving_units"`
IsBread bool `json:"is_bread"`
Ingredients []ExtractedIngredient `json:"ingredients"`
CookingMethods []string `json:"cooking_methods"`
CulturalInfluences []string `json:"cultural_influences"`
Courses []string `json:"courses"`
DietaryRestrictions []string `json:"dietary_restrictions"`
}
ExtractedRecipe is the AI-returned recipe structure.
func ExtractRecipe ¶
func ExtractRecipe(ctx context.Context, client AIClient, model, text string) (*ExtractedRecipe, string, error)
ExtractRecipe calls Claude to extract structured recipe data from text.
type GenerateSQLResult ¶ added in v1.7.0
GenerateSQLResult holds the output of NL→SQL generation.
func GenerateSQL ¶ added in v1.7.0
func GenerateSQL(ctx context.Context, client AIClient, model, dialect, question string) (*GenerateSQLResult, error)
GenerateSQL takes a natural language question and the database schema, sends it to Claude, and returns the generated SQL + a human explanation.
type PipelineConfig ¶
type PipelineConfig struct {
DB *db.DB
Client AIClient
Model string
OnStep ProgressFunc // optional; called at start of each step
}
PipelineConfig holds dependencies for the extraction pipeline.
type ProgressFunc ¶
ProgressFunc is called at the start of each pipeline step.