feat(ai): switch from DeepSeek to local Ollama (qwen3:14b)
- Point AI client to localhost:11434/v1 (Ollama) - Remove DeepSeek API key dependency - Update model name to qwen3:14b across all routes - Update test mocks to use createLocalLLMClient - Removes need for DEEPSEEK_API_KEY setting Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,8 +6,7 @@ import { withUser, asAdmin } from '@/lib/db/with-user'
|
||||
import { writeAuditLog } from '@/lib/db/audit'
|
||||
import { incidents, sites, zones, auditLog } from '@/lib/db/schema'
|
||||
import { eq, and, gte, desc } from 'drizzle-orm'
|
||||
import { createDeepSeekClient } from '@/lib/claude/client'
|
||||
import { getApiKey } from '@/lib/settings'
|
||||
import { createLocalLLMClient } from '@/lib/claude/client'
|
||||
|
||||
type ZoneAggregate = {
|
||||
zone: string
|
||||
@@ -103,13 +102,12 @@ export async function POST() {
|
||||
return NextResponse.json({ error: 'Rate limit: wait 60 seconds between AI requests' }, { status: 429 })
|
||||
}
|
||||
|
||||
const deepseekKey = await getApiKey('DEEPSEEK_API_KEY')
|
||||
const client = createDeepSeekClient(deepseekKey)
|
||||
const client = createLocalLLMClient()
|
||||
|
||||
let res: Awaited<ReturnType<typeof client.chat.completions.create>>
|
||||
try {
|
||||
res = await client.chat.completions.create({
|
||||
model: 'deepseek-v4-pro',
|
||||
model: 'qwen3:14b',
|
||||
max_tokens: 2048,
|
||||
messages: [
|
||||
{
|
||||
@@ -168,7 +166,7 @@ Flag only zones with rising or elevated risk (at most 5 flags; do not flag healt
|
||||
|
||||
await withUser(session.sub, async tx =>
|
||||
writeAuditLog(tx, 'incidents', session.sub, 'ai_risk_flags',
|
||||
{ flags, summary: input.summary, model: 'deepseek-v4-pro' })
|
||||
{ flags, summary: input.summary, model: 'qwen3:14b' })
|
||||
)
|
||||
|
||||
return NextResponse.json({ flags, summary: input.summary })
|
||||
|
||||
@@ -6,8 +6,7 @@ import { withUser, asAdmin } from '@/lib/db/with-user'
|
||||
import { writeAuditLog } from '@/lib/db/audit'
|
||||
import { incidents, auditLog, sites, zones } from '@/lib/db/schema'
|
||||
import { eq, and, gte, sql } from 'drizzle-orm'
|
||||
import { createDeepSeekClient } from '@/lib/claude/client'
|
||||
import { getApiKey } from '@/lib/settings'
|
||||
import { createLocalLLMClient } from '@/lib/claude/client'
|
||||
|
||||
export async function POST(
|
||||
_request: NextRequest,
|
||||
@@ -32,8 +31,7 @@ export async function POST(
|
||||
if (Number(rateRow?.cnt ?? 0) > 0)
|
||||
return NextResponse.json({ error: 'Rate limited — please wait 60 seconds' }, { status: 429 })
|
||||
|
||||
const deepseekKey = await getApiKey('DEEPSEEK_API_KEY')
|
||||
const client = createDeepSeekClient(deepseekKey)
|
||||
const client = createLocalLLMClient()
|
||||
|
||||
const [incident] = await withUser(session.sub, async tx =>
|
||||
tx.select({
|
||||
@@ -59,7 +57,7 @@ export async function POST(
|
||||
let res: Awaited<ReturnType<typeof client.chat.completions.create>>
|
||||
try {
|
||||
res = await client.chat.completions.create({
|
||||
model: 'deepseek-v4-pro',
|
||||
model: 'qwen3:14b',
|
||||
max_tokens: 2048,
|
||||
messages: [
|
||||
{
|
||||
@@ -107,7 +105,7 @@ Provide 3–5 Why steps drilling from immediate cause to root cause. Frame CAPA
|
||||
await withUser(session.sub, async tx => {
|
||||
await writeAuditLog(tx, 'incidents', id, 'ai_rca_draft', {
|
||||
root_cause_summary: draft.root_cause_summary as string,
|
||||
model: 'deepseek-v4-pro',
|
||||
model: 'qwen3:14b',
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ import { withUser, asAdmin } from '@/lib/db/with-user'
|
||||
import { writeAuditLog } from '@/lib/db/audit'
|
||||
import { incidents, auditLog } from '@/lib/db/schema'
|
||||
import { eq, and, gte, sql } from 'drizzle-orm'
|
||||
import { createDeepSeekClient } from '@/lib/claude/client'
|
||||
import { getApiKey } from '@/lib/settings'
|
||||
import { createLocalLLMClient } from '@/lib/claude/client'
|
||||
|
||||
export async function POST(
|
||||
_request: NextRequest,
|
||||
@@ -32,8 +31,7 @@ export async function POST(
|
||||
if (Number(rateRow?.cnt ?? 0) > 0)
|
||||
return NextResponse.json({ error: 'Rate limited — please wait 60 seconds' }, { status: 429 })
|
||||
|
||||
const deepseekKey = await getApiKey('DEEPSEEK_API_KEY')
|
||||
const client = createDeepSeekClient(deepseekKey)
|
||||
const client = createLocalLLMClient()
|
||||
|
||||
const [incident] = await withUser(session.sub, async tx =>
|
||||
tx.select({
|
||||
@@ -50,7 +48,7 @@ export async function POST(
|
||||
let res: Awaited<ReturnType<typeof client.chat.completions.create>>
|
||||
try {
|
||||
res = await client.chat.completions.create({
|
||||
model: 'deepseek-v4-pro',
|
||||
model: 'qwen3:14b',
|
||||
max_tokens: 1024,
|
||||
messages: [
|
||||
{
|
||||
@@ -105,7 +103,7 @@ Output exactly this JSON structure:
|
||||
}
|
||||
|
||||
await withUser(session.sub, async tx => {
|
||||
await writeAuditLog(tx, 'incidents', id, 'ai_triage_suggest', { suggestion: input, model: 'deepseek-v4-pro' })
|
||||
await writeAuditLog(tx, 'incidents', id, 'ai_triage_suggest', { suggestion: input, model: 'qwen3:14b' })
|
||||
})
|
||||
|
||||
return NextResponse.json(input)
|
||||
|
||||
@@ -6,8 +6,7 @@ import { withUser, asAdmin } from '@/lib/db/with-user'
|
||||
import { writeAuditLog } from '@/lib/db/audit'
|
||||
import { auditLog } from '@/lib/db/schema'
|
||||
import { eq, and, gte, sql } from 'drizzle-orm'
|
||||
import { createDeepSeekClient } from '@/lib/claude/client'
|
||||
import { getApiKey } from '@/lib/settings'
|
||||
import { createLocalLLMClient } from '@/lib/claude/client'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await getSession()
|
||||
@@ -26,8 +25,7 @@ export async function POST(request: NextRequest) {
|
||||
if (Number(rateRow?.cnt ?? 0) > 0)
|
||||
return NextResponse.json({ error: 'Rate limited — please wait 60 seconds' }, { status: 429 })
|
||||
|
||||
const deepseekKey = await getApiKey('DEEPSEEK_API_KEY')
|
||||
const client = createDeepSeekClient(deepseekKey)
|
||||
const client = createLocalLLMClient()
|
||||
|
||||
let body: { description?: string; incident_type?: string }
|
||||
try {
|
||||
@@ -42,7 +40,7 @@ export async function POST(request: NextRequest) {
|
||||
let res: Awaited<ReturnType<typeof client.chat.completions.create>>
|
||||
try {
|
||||
res = await client.chat.completions.create({
|
||||
model: 'deepseek-v4-pro',
|
||||
model: 'qwen3:14b',
|
||||
max_tokens: 1024,
|
||||
messages: [
|
||||
{
|
||||
@@ -89,7 +87,7 @@ Scoring criteria: specificity (location, time, persons involved), completeness (
|
||||
|
||||
await withUser(session.sub, async tx => {
|
||||
await writeAuditLog(tx, 'incidents', session.sub, 'ai_quality_check', {
|
||||
score: input.score, passes: input.passes, model: 'deepseek-v4-pro',
|
||||
score: input.score, passes: input.passes, model: 'qwen3:14b',
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user