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 { generateText } from 'ai'
|
||||||
import { resolveAiRouteWithTiming } from '@/lib/ai/router'
|
import { getChatProvider } from '@/lib/ai/factory'
|
||||||
import { runLaneWithBillingUser, willUseByokForLane } from '@/lib/ai/provider-for-user'
|
import { willUseByokForLane } from '@/lib/ai/provider-for-user'
|
||||||
import { getSystemConfig } from '@/lib/config'
|
import { getSystemConfig } from '@/lib/config'
|
||||||
import { prisma } from '@/lib/prisma'
|
import { prisma } from '@/lib/prisma'
|
||||||
import { auth } from '@/auth'
|
import { auth } from '@/auth'
|
||||||
import { toolRegistry } from '@/lib/ai/tools'
|
|
||||||
import { checkEntitlementOrThrow, QuotaExceededError } from '@/lib/entitlements'
|
import { checkEntitlementOrThrow, QuotaExceededError } from '@/lib/entitlements'
|
||||||
import { trackFeatureUsage } from '@/lib/usage-tracker'
|
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))
|
console.log('[suggest-charts] analyzeLen:', textToAnalyze.length, 'preview:', textToAnalyze.substring(0, 100))
|
||||||
|
|
||||||
// 3. Build AI context
|
// 3. Build AI context
|
||||||
let sysConfig, provider, model
|
let provider, model
|
||||||
try {
|
try {
|
||||||
sysConfig = await getSystemConfig()
|
const sysConfig = await getSystemConfig()
|
||||||
const result = await resolveAiRouteWithTiming('chat', sysConfig)
|
provider = getChatProvider(sysConfig)
|
||||||
provider = result.provider
|
model = provider.getModel()
|
||||||
model = result.model
|
|
||||||
console.log('[suggest-charts] AI model:', model)
|
console.log('[suggest-charts] AI model:', model)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[suggest-charts] AI ROUTE ERROR:', e)
|
console.error('[suggest-charts] AI ROUTE ERROR:', e)
|
||||||
@@ -113,7 +111,7 @@ export async function POST(req: Request) {
|
|||||||
try {
|
try {
|
||||||
// 4. Call AI to analyze and suggest - direct JSON response (no tool)
|
// 4. Call AI to analyze and suggest - direct JSON response (no tool)
|
||||||
const { text } = await generateText({
|
const { text } = await generateText({
|
||||||
model: provider(model),
|
model,
|
||||||
system: `You are a data visualization assistant. Analyze the provided text and suggest appropriate chart types.
|
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.
|
IMPORTANT: You MUST respond with valid JSON only. No markdown, no code blocks, no explanations.
|
||||||
|
|||||||
Reference in New Issue
Block a user