services

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	StepFetch   = 1
	StepExtract = 2
	StepSave    = 3
	StepDone    = 4
)

Step constants for progress reporting.

View Source
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".

View Source
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

View Source
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

func ExecuteQuery(database *db.DB, query string) ([]string, [][]string, time.Duration, error)

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

func ExtractTextFromPaste(text string) string

ExtractTextFromPaste cleans and truncates pasted recipe text.

func ExtractTextFromURL

func ExtractTextFromURL(url string) (string, error)

ExtractTextFromURL fetches a URL and returns clean recipe text. It prioritizes Schema.org JSON-LD, then falls back to main content.

func RunPipeline

func RunPipeline(ctx context.Context, cfg PipelineConfig, recipeID int64) (*models.Recipe, error)

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 ScanRow added in v1.7.0

func ScanRow(row *sql.Row, dest ...interface{}) error

ScanRow is a helper to scan a single row into a destination.

func ValidateReadOnly added in v1.7.0

func ValidateReadOnly(sql string) error

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.

func (*AnthropicClient) Complete

func (a *AnthropicClient) Complete(ctx context.Context, model, sysPrompt, userMessage string) (string, error)

Complete sends a message to Claude and returns the text response.

type ExecuteQueryResult added in v1.7.0

type ExecuteQueryResult struct {
	Columns  []string
	Rows     [][]string
	Duration time.Duration
}

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

type GenerateSQLResult struct {
	SQL         string
	Explanation string
}

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

type ProgressFunc func(step int, label string)

ProgressFunc is called at the start of each pipeline step.

Jump to

Keyboard shortcuts

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