-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Enforce JSON schema for Gemini responses #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,35 @@ export class GeminiProvider extends LLMProvider { | |
| body: JSON.stringify({ | ||
| systemInstruction: { parts: [{ text: systemPrompt }] }, | ||
| contents: [{ parts: [{ text: userMessage }] }], | ||
| // --- TRAVA DE SEGURANÇA DESATIVADA PARA OSINT --- | ||
| safetySettings: [ | ||
| { category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE" }, | ||
| { category: "HARM_CATEGORY_HATE_SPEECH", threshold: "BLOCK_NONE" }, | ||
| { category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold: "BLOCK_NONE" }, | ||
| { category: "HARM_CATEGORY_DANGEROUS_CONTENT", threshold: "BLOCK_NONE" } | ||
| ], | ||
| // ------------------------------------------------ | ||
| generationConfig: { | ||
| maxOutputTokens: opts.maxTokens || 4096, | ||
| // Trava estrutural para garantir o JSON nativo | ||
| responseMimeType: "application/json", | ||
| responseSchema: { | ||
| type: "ARRAY", | ||
|
Comment on lines
32
to
+37
|
||
| items: { | ||
| type: "OBJECT", | ||
| properties: { | ||
| title: { type: "STRING", description: "Short title (max 10 words)" }, | ||
| type: { type: "STRING", enum: ["LONG", "SHORT", "HEDGE", "WATCH", "AVOID"] }, | ||
| ticker: { type: "STRING", description: "Primary instrument" }, | ||
| confidence: { type: "STRING", enum: ["HIGH", "MEDIUM", "LOW"] }, | ||
| rationale: { type: "STRING", description: "2-3 sentence explanation citing specific data" }, | ||
| risk: { type: "STRING", description: "Key risk factor" }, | ||
| horizon: { type: "STRING", description: "Intraday, Days, Weeks, or Months" }, | ||
| signals: { type: "ARRAY", items: { type: "STRING" } } | ||
| }, | ||
| required: ["title", "type", "ticker", "confidence", "rationale", "risk", "horizon", "signals"] | ||
| } | ||
| } | ||
| }, | ||
|
Comment on lines
32
to
53
|
||
| }), | ||
| signal: AbortSignal.timeout(opts.timeout || 60000), | ||
|
|
@@ -34,8 +61,21 @@ export class GeminiProvider extends LLMProvider { | |
| } | ||
|
|
||
| const data = await res.json(); | ||
|
|
||
| // Fallback de segurança caso a API bloqueie em um nível superior (independente do BLOCK_NONE) | ||
| if (data.candidates?.[0]?.finishReason === 'SAFETY') { | ||
| console.warn('[LLM] Alerta de Censura: O modelo recusou a análise do feed por violação de segurança.'); | ||
| } | ||
|
|
||
| const text = data.candidates?.[0]?.content?.parts?.[0]?.text || ''; | ||
|
|
||
| // --- INJEÇÃO DE DEBUG --- | ||
| if (!text || text.length < 10) { | ||
| console.log("\n[DEBUG CRÍTICO] A IA não retornou texto válido. Resposta bruta da API:"); | ||
| console.log(JSON.stringify(data, null, 2)); | ||
| } | ||
| // ------------------------ | ||
|
|
||
| return { | ||
| text, | ||
| usage: { | ||
|
|
@@ -45,4 +85,4 @@ export class GeminiProvider extends LLMProvider { | |
| model: this.model, | ||
| }; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new inline comment is in Portuguese while the rest of the LLM provider files use English comments, which makes the file inconsistent to maintain for the broader team. Please translate it to English (and keep terminology consistent with other providers).