fix(chart): use correct AI provider pattern
Use getChatProvider() + provider.getModel() instead of resolveAiRouteWithTiming which doesn't return a provider function. Follow the pattern used in chat/insights/route.ts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { generateText } from 'ai'
|
||||
import { resolveAiRouteWithTiming } from '@/lib/ai/router'
|
||||
import { runLaneWithBillingUser, willUseByokForLane } from '@/lib/ai/provider-for-user'
|
||||
import { getChatProvider } from '@/lib/ai/factory'
|
||||
import { willUseByokForLane } from '@/lib/ai/provider-for-user'
|
||||
import { getSystemConfig } from '@/lib/config'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { auth } from '@/auth'
|
||||
import { toolRegistry } from '@/lib/ai/tools'
|
||||
import { checkEntitlementOrThrow, QuotaExceededError } from '@/lib/entitlements'
|
||||
import { trackFeatureUsage } from '@/lib/usage-tracker'
|
||||
|
||||
@@ -92,12 +91,11 @@ export async function POST(req: Request) {
|
||||
console.log('[suggest-charts] analyzeLen:', textToAnalyze.length, 'preview:', textToAnalyze.substring(0, 100))
|
||||
|
||||
// 3. Build AI context
|
||||
let sysConfig, provider, model
|
||||
let provider, model
|
||||
try {
|
||||
sysConfig = await getSystemConfig()
|
||||
const result = await resolveAiRouteWithTiming('chat', sysConfig)
|
||||
provider = result.provider
|
||||
model = result.model
|
||||
const sysConfig = await getSystemConfig()
|
||||
provider = getChatProvider(sysConfig)
|
||||
model = provider.getModel()
|
||||
console.log('[suggest-charts] AI model:', model)
|
||||
} catch (e) {
|
||||
console.error('[suggest-charts] AI ROUTE ERROR:', e)
|
||||
@@ -113,7 +111,7 @@ export async function POST(req: Request) {
|
||||
try {
|
||||
// 4. Call AI to analyze and suggest - direct JSON response (no tool)
|
||||
const { text } = await generateText({
|
||||
model: provider(model),
|
||||
model,
|
||||
system: `You are a data visualization assistant. Analyze the provided text and suggest appropriate chart types.
|
||||
|
||||
IMPORTANT: You MUST respond with valid JSON only. No markdown, no code blocks, no explanations.
|
||||
|
||||
Reference in New Issue
Block a user