From 52ae696468992c1451ff3b7c95a1201dea9ea208 Mon Sep 17 00:00:00 2001 From: Reversean Date: Tue, 21 Jul 2026 19:27:13 +0300 Subject: [PATCH] fix(ai): improve AI prompt formatting and add gateway fallback Restructure the CTO instruction prompt with explicit Markdown formatting rules (consistent list indentation, no tabs, no nested code blocks) so the model's output renders correctly. Switch to deepseek/deepseek-v4-flash and add a gateway provider fallback order (novita, azure, deepseek) so requests survive a single provider outage. Drop the now-unneeded hand-written ambient types for the `ai`/`@ai-sdk/openai` modules. Co-authored-by: Gleb Kiva --- package.json | 2 +- src/integrations/vercel-ai/index.ts | 8 ++++-- .../vercel-ai/instructions/cto.ts | 25 +++++++++++++++---- src/types/vercel-ai.d.ts | 18 ------------- 4 files changed, 27 insertions(+), 26 deletions(-) delete mode 100644 src/types/vercel-ai.d.ts diff --git a/package.json b/package.json index 674c52be..1e9ebca4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hawk.api", - "version": "1.5.5", + "version": "1.5.6", "main": "index.ts", "license": "BUSL-1.1", "scripts": { diff --git a/src/integrations/vercel-ai/index.ts b/src/integrations/vercel-ai/index.ts index b063b4c4..c9382eb0 100644 --- a/src/integrations/vercel-ai/index.ts +++ b/src/integrations/vercel-ai/index.ts @@ -1,6 +1,5 @@ import { EventAddons, EventData } from '@hawk.so/types'; import { generateText } from 'ai'; -import { openai } from '@ai-sdk/openai'; import { eventSolvingInput } from './inputs/eventSolving'; import { ctoInstruction } from './instructions/cto'; @@ -17,7 +16,7 @@ class VercelAIApi { /** * @todo make it dynamic, get from project settings */ - this.modelId = 'deepseek/deepseek-v3.1'; + this.modelId = 'deepseek/deepseek-v4-flash'; } /** @@ -32,6 +31,11 @@ class VercelAIApi { model: this.modelId, system: ctoInstruction, prompt: eventSolvingInput(payload), + providerOptions: { + gateway: { + order: ['novita', 'azure', 'deepseek'], + }, + }, }); return text; diff --git a/src/integrations/vercel-ai/instructions/cto.ts b/src/integrations/vercel-ai/instructions/cto.ts index 9d267044..111a1588 100644 --- a/src/integrations/vercel-ai/instructions/cto.ts +++ b/src/integrations/vercel-ai/instructions/cto.ts @@ -1,9 +1,24 @@ export const ctoInstruction = `Ты технический директор ИТ компании, тебе нужно пояснить ошибку и предложить решение. -Предоставь ответ в следующем формате: +Предоставь ответ **строго** в следующем формате на русском языке: -1. Описание проблемы -2. Решение проблемы -3. Описание того, как можно предотвратить подобную ошибку в будущем +[Краткое summary] -Ответь на русском языке.`; +## Описание проблемы +[Подробный, но лаконичный анализ сути проблемы] + +## Решение +[Конкретные шаги по исправлению + рекомендуемый лучший вариант] + +## Как избежать повторения +[Как предотвратить повторение подобной ошибки в будущем: процессы, инструменты, архитектурные решения, code review и т.д.] + +**Formatting instructions:** +- Output only valid Markdown. +- Use consistent indentation for all nested lists. +- Never use tabs instead of spaces. +- Use links if necessary. +- Never use numbering in headings. +- Prefer sections with nested headings to avoid deeply-nested lists. +- Never nest inline code-blocks inside headings. +- Never nest multiline code-blocks inside lists.`; diff --git a/src/types/vercel-ai.d.ts b/src/types/vercel-ai.d.ts deleted file mode 100644 index 33d02c19..00000000 --- a/src/types/vercel-ai.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -declare module 'ai' { - /** - * Minimal type for generateText used in server-side integration. - */ - export function generateText(input: { - model: any; - system?: string; - prompt: string; - }): Promise<{ text: string }>; -} - -declare module '@ai-sdk/openai' { - /** - * Minimal types for OpenAI provider. - */ - export function createOpenAI(config?: { apiKey?: string }): (model: string) => any; - export const openai: (model: string) => any; -}