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);
|
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 => ({
|
setAiValidationProgress(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
status: "Sending data to AI service and awaiting response...",
|
status: "Sending data to AI service and awaiting response...",
|
||||||
@@ -1566,11 +1574,17 @@ export const ValidationStep = <T extends string>({
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ products: data }),
|
body: JSON.stringify({ products: cleanedData }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
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 => ({
|
setAiValidationProgress(prev => ({
|
||||||
|
|||||||
@@ -7,22 +7,18 @@ import { useToast } from "@/hooks/use-toast"
|
|||||||
import { Loader2 } from "lucide-react"
|
import { Loader2 } from "lucide-react"
|
||||||
import config from "@/config"
|
import config from "@/config"
|
||||||
|
|
||||||
interface CacheStatus {
|
|
||||||
isCacheValid: boolean
|
|
||||||
lastUpdated: string | null
|
|
||||||
timeUntilExpiry: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TaxonomyStats {
|
interface TaxonomyStats {
|
||||||
categories: number
|
categories: number
|
||||||
themes: number
|
themes: number
|
||||||
colors: number
|
colors: number
|
||||||
taxCodes: number
|
taxCodes: number
|
||||||
sizeCategories: number
|
sizeCategories: number
|
||||||
|
suppliers: number
|
||||||
|
companies: number
|
||||||
|
artists: number
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DebugData {
|
interface DebugData {
|
||||||
cacheStatus: CacheStatus
|
|
||||||
taxonomyStats: TaxonomyStats | null
|
taxonomyStats: TaxonomyStats | null
|
||||||
basePrompt: string
|
basePrompt: string
|
||||||
sampleFullPrompt: 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(() => {
|
useEffect(() => {
|
||||||
fetchDebugData()
|
fetchDebugData()
|
||||||
}, [])
|
}, [])
|
||||||
@@ -122,32 +85,11 @@ export function AiValidationDebug() {
|
|||||||
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||||
Refresh Data
|
Refresh Data
|
||||||
</Button>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{debugData && (
|
{debugData && (
|
||||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 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>
|
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Taxonomy Stats</CardTitle>
|
<CardTitle>Taxonomy Stats</CardTitle>
|
||||||
@@ -160,6 +102,9 @@ export function AiValidationDebug() {
|
|||||||
<div>Colors: {debugData.taxonomyStats.colors}</div>
|
<div>Colors: {debugData.taxonomyStats.colors}</div>
|
||||||
<div>Tax Codes: {debugData.taxonomyStats.taxCodes}</div>
|
<div>Tax Codes: {debugData.taxonomyStats.taxCodes}</div>
|
||||||
<div>Size Categories: {debugData.taxonomyStats.sizeCategories}</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>
|
||||||
) : (
|
) : (
|
||||||
<div>No taxonomy data available</div>
|
<div>No taxonomy data available</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user