← Back to Pull requests

feat: IA das Edge Functions passa da Lovable para a DeepSeek (deepseek-flash, texto + imagem) #452

Closed
unknown closed this pull request without merging on Nov 12, 2026 04:30 UTC
View on GitHub
unknown unknown commented on Nov 12, 2026 00:50 UTC
Author

Por quê


O dono pediu para trocar a IA da Lovable pela DeepSeek. Hoje as 5 funções de IA estão fora do ar: não existe LOVABLE_API_KEY no projeto frjbfeamybqsejlvmqbl.

Além disso, OCR e process-document-ocr chamavam https://api.lovable.dev/v1/chat/completions, um host diferente do gateway (ai-gateway.lovable.dev) que as outras usam.

Mudança


Novo helper supabase/functions/_shared/aiProvider.ts:
  • URL: AI_CHAT_URL = https://api.deepseek.com/chat/completions, API compatível com OpenAI.

  • aiApiKey(): lê o secret DEEPSEEK_API_KEY.

  • aiModel(): lê o secret DEEPSEEK_MODEL; o padrão é deepseek-flash.
  • Pela doc oficial da DeepSeek (https://api-docs.deepseek.com/guides/vision/), deepseek-flash aceita texto e imagem (image_url com data URL base64, até 32 MiB por imagem). Por isso um único modelo atende chat, OCR e biometria.

    | Função | Antes | Depois |
    |---|---|---|
    | assistente-ia | gateway Lovable, gemini-2.5-flash | DeepSeek, aiModel() |
    | validar-biometria | gateway Lovable, gemini-2.5-flash (imagem) | DeepSeek |
    | OCR | api.lovable.dev, gemini-2.5-flash (imagem) | DeepSeek |
    | process-document-ocr | api.lovable.dev, gemini-2.0-flash (imagem) | DeepSeek |
    | alertas-preditivos | OpenAI ou gateway (LOVABLE_API_KEY), gpt-4o-mini | sem AI_GATEWAY_URL, usa a DeepSeek quando a chave existe; OPENAI_API_KEY sozinha continua funcionando |

    O comportamento sem chave não muda: as funções seguem respondendo "não configurado" (503 / pendente). PENDENCIAS.md foi atualizado para o nome novo da chave.

    Verificado


  • Teste novo _shared/aiProvider.test.ts (URL, chave vazia ou ausente, modelo padrão e override): passou.

  • bash scripts/typecheck-edge.sh: exit 0, 0 funções com erro.

  • audit-security-config, audit-bridge-frontend-contract, audit-canonical-project, audit-migration-style: exit 0.

  • prettier --check nos arquivos novos e no PENDENCIAS.md: ok.
  • NÃO verificado


  • Chamada real à DeepSeek: a DEEPSEEK_API_KEY ainda não foi fornecida. Falta ver a qualidade do OCR e da biometria nas imagens reais.

  • O deploy das funções depende de canonical-edge-functions.yml, que pede aprovação no environment Production.
  • ---
    _Generated by Claude Code_

    Diff: 289 lines (+216 / -73) across 3 files Reviewer: adm01-debug Review duration: 219m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 289 lines diff across 3 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.339
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #452"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.8% (MEDIUM) · Higher = larger blast radius
    44.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.4% · Safe to merge
    19.4%