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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
CORRIGIDO: model_config para evitar warning de namespace protegido
|
| 4 |
"""
|
| 5 |
from pydantic import BaseModel, Field, ConfigDict
|
|
|
|
| 1 |
"""
|
| 2 |
+
Request models """
|
| 3 |
+
Request models para para.AI API v3.0
|
| 4 |
+
Define estrutura de requests para todos os endpoints
|
| 5 |
+
|
| 6 |
+
CORRIGIDO: Adicionado model_config para resolver warning Pydantic
|
| 7 |
+
"""
|
| 8 |
+
from typing import Optional, List
|
| 9 |
+
from pydantic import BaseModel, Field, field_validator, ConfigDict
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# ============================================================================
|
| 13 |
+
# PROCESSING
|
| 14 |
+
# ============================================================================
|
| 15 |
+
|
| 16 |
+
class ProcessingOptionsRequest(BaseModel):
|
| 17 |
+
"""
|
| 18 |
+
Opções de processamento.
|
| 19 |
+
|
| 20 |
+
CORRIGIDO: model_config adicionado para resolver warning de namespace
|
| 21 |
+
"""
|
| 22 |
+
# ✅ Configuração para permitir campos "model_*"
|
| 23 |
+
model_config = ConfigDict(protected_namespaces=())
|
| 24 |
+
|
| 25 |
+
llm_provider: str = Field(
|
| 26 |
+
default="groq",
|
| 27 |
+
description="Provedor LLM (groq/openai/anthropic)"
|
| 28 |
+
)
|
| 29 |
+
model_type: str = Field(
|
| 30 |
+
default="balanced",
|
| 31 |
+
description="Tipo de modelo (fast/balanced/quality)"
|
| 32 |
+
)
|
| 33 |
+
enable_parallel: bool = Field(
|
| 34 |
+
default=True,
|
| 35 |
+
description="Habilitar processamento paralelo"
|
| 36 |
+
)
|
| 37 |
+
max_workers: int = Field(
|
| 38 |
+
default=3,
|
| 39 |
+
ge=1,
|
| 40 |
+
le=10,
|
| 41 |
+
description="Número de workers paralelos"
|
| 42 |
+
)
|
| 43 |
+
save_to_db: bool = Field(
|
| 44 |
+
default=True,
|
| 45 |
+
description="Salvar resultados no banco"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
@field_validator("llm_provider")
|
| 49 |
+
@classmethod
|
| 50 |
+
def validate_provider(cls, v):
|
| 51 |
+
allowed = ["groq", "openai", "anthropic"]
|
| 52 |
+
if v not in allowed:
|
| 53 |
+
raise ValueError(f"Provider deve ser um de: {allowed}")
|
| 54 |
+
return v
|
| 55 |
+
|
| 56 |
+
@field_validator("model_type")
|
| 57 |
+
@classmethod
|
| 58 |
+
def validate_model_type(cls, v):
|
| 59 |
+
allowed = ["fast", "balanced", "quality"]
|
| 60 |
+
if v not in allowed:
|
| 61 |
+
raise ValueError(f"Model type deve ser um de: {allowed}")
|
| 62 |
+
return v
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# ============================================================================
|
| 66 |
+
# LLM TESTING
|
| 67 |
+
# ============================================================================
|
| 68 |
+
|
| 69 |
+
class LLMGenerateRequest(BaseModel):
|
| 70 |
+
"""Request para gerar texto com LLM."""
|
| 71 |
+
|
| 72 |
+
prompt: str = Field(
|
| 73 |
+
...,
|
| 74 |
+
description="Prompt para o LLM",
|
| 75 |
+
min_length=1
|
| 76 |
+
)
|
| 77 |
+
provider: str = Field(
|
| 78 |
+
default="groq",
|
| 79 |
+
description="Provedor LLM"
|
| 80 |
+
)
|
| 81 |
+
model: Optional[str] = Field(
|
| 82 |
+
default=None,
|
| 83 |
+
description="Model específico (opcional)"
|
| 84 |
+
)
|
| 85 |
+
temperature: float = Field(
|
| 86 |
+
default=0.7,
|
| 87 |
+
ge=0.0,
|
| 88 |
+
le=2.0,
|
| 89 |
+
description="Temperatura"
|
| 90 |
+
)
|
| 91 |
+
max_tokens: int = Field(
|
| 92 |
+
default=1024,
|
| 93 |
+
ge=1,
|
| 94 |
+
le=4096,
|
| 95 |
+
description="Máximo de tokens"
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
# ============================================================================
|
| 100 |
+
# PROCESSOR TESTING
|
| 101 |
+
# ============================================================================
|
| 102 |
+
|
| 103 |
+
class ProcessorTestRequest(BaseModel):
|
| 104 |
+
"""Request para testar processador."""
|
| 105 |
+
|
| 106 |
+
processor_name: str = Field(
|
| 107 |
+
...,
|
| 108 |
+
description="Nome do processador (1-9 ou nome completo)"
|
| 109 |
+
)
|
| 110 |
+
ementa: str = Field(
|
| 111 |
+
...,
|
| 112 |
+
description="Texto da ementa",
|
| 113 |
+
min_length=10
|
| 114 |
+
)
|
| 115 |
+
integra: str = Field(
|
| 116 |
+
...,
|
| 117 |
+
description="Texto da íntegra",
|
| 118 |
+
min_length=10
|
| 119 |
+
)
|
| 120 |
+
tribunal: str = Field(
|
| 121 |
+
default="TJPR",
|
| 122 |
+
description="Sigla do tribunal"
|
| 123 |
+
)
|
| 124 |
+
llm_provider: str = Field(
|
| 125 |
+
default="groq",
|
| 126 |
+
description="Provedor LLM"
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
# ============================================================================
|
| 131 |
+
# FILE OPERATIONS
|
| 132 |
+
# ============================================================================
|
| 133 |
+
|
| 134 |
+
class FileCreateRequest(BaseModel):
|
| 135 |
+
"""Request para criar arquivo."""
|
| 136 |
+
|
| 137 |
+
content: str = Field(
|
| 138 |
+
...,
|
| 139 |
+
description="Conteúdo do arquivo"
|
| 140 |
+
)
|
| 141 |
+
filename: str = Field(
|
| 142 |
+
...,
|
| 143 |
+
description="Nome do arquivo"
|
| 144 |
+
)
|
| 145 |
+
acordao_id: Optional[str] = Field(
|
| 146 |
+
default=None,
|
| 147 |
+
description="ID do acórdão relacionado"
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
class FileListRequest(BaseModel):
|
| 152 |
+
"""Request para listar arquivos."""
|
| 153 |
+
|
| 154 |
+
acordao_id: Optional[str] = Field(
|
| 155 |
+
default=None,
|
| 156 |
+
description="Filtrar por acórdão"
|
| 157 |
+
)
|
| 158 |
+
limit: int = Field(
|
| 159 |
+
default=100,
|
| 160 |
+
ge=1,
|
| 161 |
+
le=1000,
|
| 162 |
+
description="Limite de resultados"
|
| 163 |
+
)
|
| 164 |
+
offset: int = Field(
|
| 165 |
+
default=0,
|
| 166 |
+
ge=0,
|
| 167 |
+
description="Offset para paginação"
|
| 168 |
+
)
|
| 169 |
+
a API
|
| 170 |
CORRIGIDO: model_config para evitar warning de namespace protegido
|
| 171 |
"""
|
| 172 |
from pydantic import BaseModel, Field, ConfigDict
|