feat: adicionar suporte a modelos MiniMax (2.7 e 3.0)

This commit is contained in:
2026-06-22 20:34:35 +00:00
parent 9f054a777f
commit 176f064c16
4 changed files with 88 additions and 1 deletions
+53
View File
@@ -351,6 +351,8 @@ export const analyzeCertificate = async (options: AnalyzeOptions): Promise<Repor
return analyzeWithOllama(file, endpoint!, model);
case 'openrouter':
return analyzeWithOpenRouter(file, apiKey, model);
case 'minimax':
return analyzeWithMinimax(file, apiKey, model);
default:
throw new Error(`Provedor não suportado: ${provider}`);
}
@@ -476,5 +478,56 @@ export const analyzeWithOpenRouter = async (file: File, apiKey: string, model: s
throw new Error("Resposta vazia do OpenRouter");
}
return cleanAndParseJson(content) as ReportData;
};
export const analyzeWithMinimax = async (file: File, apiKey: string, model: string = 'minimax-2.7'): Promise<ReportData> => {
if (!apiKey) {
throw new Error("A chave de API do MiniMax não foi fornecida.");
}
const base64Data = await new Promise<string>((resolve) => {
const reader = new FileReader();
reader.onloadend = () => resolve((reader.result as string).split(',')[1]);
reader.readAsDataURL(file);
});
const response = await fetch('https://api.minimax.chat/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model,
messages: [
{
role: 'user',
content: [
{ type: 'text', text: PROMPT_BASE + "\n\nRetorne apenas JSON válido sem formatação markdown." },
{
type: 'image_url',
image_url: { url: `data:${file.type};base64,${base64Data}` }
}
]
}
],
temperature: 0.1,
response_format: { type: 'json_object' }
})
});
if (!response.ok) {
const error = await response.json().catch(() => ({}));
throw new Error(`Erro do MiniMax: ${error.error?.message || 'Erro desconhecido'}`);
}
const data = await response.json();
const content = data.choices[0]?.message?.content;
if (!content) {
throw new Error("Resposta vazia do MiniMax");
}
return cleanAndParseJson(content) as ReportData;
};