Fix AI regressions
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1555,6 +1555,14 @@ export const ValidationStep = <T extends string>({
|
||||
});
|
||||
console.log('Sending data for validation:', data);
|
||||
|
||||
// Clean the data to ensure we only send what's needed
|
||||
const cleanedData = data.map(item => {
|
||||
const { __errors, __index, ...cleanProduct } = item;
|
||||
return cleanProduct;
|
||||
});
|
||||
|
||||
console.log('Cleaned data for validation:', cleanedData);
|
||||
|
||||
setAiValidationProgress(prev => ({
|
||||
...prev,
|
||||
status: "Sending data to AI service and awaiting response...",
|
||||
@@ -1566,11 +1574,17 @@ export const ValidationStep = <T extends string>({
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ products: data }),
|
||||
body: JSON.stringify({ products: cleanedData }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('AI validation failed');
|
||||
const errorText = await response.text();
|
||||
console.error('AI validation error response:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
body: errorText
|
||||
});
|
||||
throw new Error(`AI validation failed: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
setAiValidationProgress(prev => ({
|
||||
|
||||
@@ -7,22 +7,18 @@ import { useToast } from "@/hooks/use-toast"
|
||||
import { Loader2 } from "lucide-react"
|
||||
import config from "@/config"
|
||||
|
||||
interface CacheStatus {
|
||||
isCacheValid: boolean
|
||||
lastUpdated: string | null
|
||||
timeUntilExpiry: string
|
||||
}
|
||||
|
||||
interface TaxonomyStats {
|
||||
categories: number
|
||||
themes: number
|
||||
colors: number
|
||||
taxCodes: number
|
||||
sizeCategories: number
|
||||
suppliers: number
|
||||
companies: number
|
||||
artists: number
|
||||
}
|
||||
|
||||
interface DebugData {
|
||||
cacheStatus: CacheStatus
|
||||
taxonomyStats: TaxonomyStats | null
|
||||
basePrompt: string
|
||||
sampleFullPrompt: string
|
||||
@@ -72,39 +68,6 @@ export function AiValidationDebug() {
|
||||
}
|
||||
}
|
||||
|
||||
const refreshCache = async () => {
|
||||
if (!confirm('Are you sure you want to refresh the cache?')) return
|
||||
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const response = await fetch(`${config.apiUrl}/ai-validation/refresh-cache`, {
|
||||
method: 'POST'
|
||||
})
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to refresh cache')
|
||||
}
|
||||
const data = await response.json()
|
||||
if (data.success) {
|
||||
toast({
|
||||
title: "Success",
|
||||
description: "Cache refreshed successfully"
|
||||
})
|
||||
fetchDebugData()
|
||||
} else {
|
||||
throw new Error(data.error || 'Failed to refresh cache')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error refreshing cache:', error)
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Error",
|
||||
description: error instanceof Error ? error.message : "Failed to refresh cache"
|
||||
})
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetchDebugData()
|
||||
}, [])
|
||||
@@ -122,32 +85,11 @@ export function AiValidationDebug() {
|
||||
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
Refresh Data
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={refreshCache}
|
||||
disabled={isLoading}
|
||||
>
|
||||
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
Force Cache Refresh
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{debugData && (
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Cache Status</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-2">
|
||||
<div>Valid: {debugData.cacheStatus.isCacheValid ? "Yes" : "No"}</div>
|
||||
<div>Last Updated: {debugData.cacheStatus.lastUpdated || "never"}</div>
|
||||
<div>Expires in: {debugData.cacheStatus.timeUntilExpiry}</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Taxonomy Stats</CardTitle>
|
||||
@@ -160,6 +102,9 @@ export function AiValidationDebug() {
|
||||
<div>Colors: {debugData.taxonomyStats.colors}</div>
|
||||
<div>Tax Codes: {debugData.taxonomyStats.taxCodes}</div>
|
||||
<div>Size Categories: {debugData.taxonomyStats.sizeCategories}</div>
|
||||
<div>Suppliers: {debugData.taxonomyStats.suppliers}</div>
|
||||
<div>Companies: {debugData.taxonomyStats.companies}</div>
|
||||
<div>Artists: {debugData.taxonomyStats.artists}</div>
|
||||
</div>
|
||||
) : (
|
||||
<div>No taxonomy data available</div>
|
||||
|
||||
Reference in New Issue
Block a user