update see calss

This commit is contained in:
2026-08-23 22:03:57 +02:00
parent f3d4fb56ed
commit 8983cfc8a1
32 changed files with 1884 additions and 22 deletions
+15 -5
View File
@@ -20,6 +20,7 @@ import (
"strings"
"time"
"github.com/descrybe/descrybe-v2/apps/api/internal/aiaudit"
"github.com/descrybe/descrybe-v2/apps/api/internal/aiprompts"
"github.com/descrybe/descrybe-v2/apps/api/internal/aiprovider"
"github.com/descrybe/descrybe-v2/apps/api/internal/catalog"
@@ -58,12 +59,14 @@ func main() {
log.Fatalf("db ping: %v", err)
}
pipeline := newWorkerLikePipeline(ctx, pool, cfg)
pipeline, auditedSvc := newWorkerLikePipeline(ctx, pool, cfg)
if strings.TrimSpace(*llmBase) != "" {
// Everything else stays production-identical; only the provider endpoint is
// pinned so a local run does not depend on the configured remote model.
pipeline.AI = fixedCompleter{
client: processing.NewOpenAIClient(*llmKey, *llmBase, *llmModel, 0, 2),
client: auditedSvc.WrapAudit(
processing.NewOpenAIClient(*llmKey, *llmBase, *llmModel, 0, 2),
uuid.Nil, "processing", processing.AIProviderInternal),
}
log.Printf("LLM override: base=%s model=%s", *llmBase, *llmModel)
}
@@ -93,7 +96,7 @@ func (f fixedCompleter) ResolveCompleterForRole(ctx context.Context, id uuid.UUI
// newWorkerLikePipeline mirrors cmd/worker/main.go so this proof exercises the same
// code path production does.
func newWorkerLikePipeline(ctx context.Context, pool *pgxpool.Pool, cfg config.Config) *processing.Pipeline {
func newWorkerLikePipeline(ctx context.Context, pool *pgxpool.Pool, cfg config.Config) (*processing.Pipeline, *aiprovider.Service) {
platSettings := platformsettings.NewService(pool, platformsettings.EnvConfig{
AppEncryptionKey: cfg.AppEncryptionKey,
CredentialsEncryptionKey: cfg.CredentialsEncryptionKey,
@@ -115,6 +118,7 @@ func newWorkerLikePipeline(ctx context.Context, pool *pgxpool.Pool, cfg config.C
ProcessingMaxRetries: cfg.ProcessingMaxRetries,
})
aiSvc.Platform = platSettings
aiSvc.WithAudit(aiaudit.NewRecorder(pool))
p := processing.NewPipeline(pool)
p.AI = aiSvc
p.Prompts = aiprompts.NewService(pool)
@@ -130,7 +134,7 @@ func newWorkerLikePipeline(ctx context.Context, pool *pgxpool.Pool, cfg config.C
} else {
log.Printf("OpenAI: source=%s base=%s model=%s", oi.Source, oi.BaseURL, oi.Model)
}
return p
return p, aiSvc
}
func runExisting(ctx context.Context, pool *pgxpool.Pool, p *processing.Pipeline, companyName, gtin string, limit int, ptype string) error {
@@ -179,9 +183,15 @@ func runExisting(ctx context.Context, pool *pgxpool.Pool, p *processing.Pipeline
func processAndReport(ctx context.Context, pool *pgxpool.Pool, p *processing.Pipeline, companyID uuid.UUID, rawIDs []uuid.UUID, ptype string) error {
// Clear prior enhance hashes so the run cannot be skipped as "unchanged".
// The hash lives twice: once on field_sources and once per language inside
// localized_content — clearing only the first still hash-skips the LLM.
if _, err := pool.Exec(ctx, `
UPDATE processed_products
SET field_sources = field_sources - 'enhance_input_hash'
SET field_sources = field_sources - 'enhance_input_hash',
localized_content = COALESCE((
SELECT jsonb_object_agg(k, v - 'enhance_input_hash')
FROM jsonb_each(COALESCE(localized_content, '{}'::jsonb)) AS t(k, v)
), '{}'::jsonb)
WHERE company_id = $1 AND raw_product_id = ANY($2)`, companyID, rawIDs); err != nil {
return err
}