feat: implement plant health check functionality with AI analysis, credit management, and UI integration
This commit is contained in:
@@ -107,10 +107,16 @@ const normalizeIdentifyResult = (raw, language) => {
|
||||
const waterIntervalRaw = getNumber(careInfoRaw.waterIntervalDays);
|
||||
const light = getString(careInfoRaw.light);
|
||||
const temp = getString(careInfoRaw.temp);
|
||||
if (waterIntervalRaw == null || !light || !temp) {
|
||||
if (waterIntervalRaw == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const LIGHT_DEFAULTS = { de: 'Helles indirektes Licht', es: 'Luz indirecta brillante', en: 'Bright indirect light' };
|
||||
const TEMP_DEFAULTS = { de: '15–25 °C', es: '15–25 °C', en: '59–77 °F (15–25 °C)' };
|
||||
const lang = language || 'en';
|
||||
const resolvedLight = (light && light !== 'Unknown') ? light : (LIGHT_DEFAULTS[lang] || LIGHT_DEFAULTS.en);
|
||||
const resolvedTemp = (temp && temp !== 'Unknown') ? temp : (TEMP_DEFAULTS[lang] || TEMP_DEFAULTS.en);
|
||||
|
||||
const fallbackDescription = language === 'de'
|
||||
? `${name} wurde per KI erkannt. Pflegehinweise sind unten aufgefuehrt.`
|
||||
: language === 'es'
|
||||
@@ -124,8 +130,8 @@ const normalizeIdentifyResult = (raw, language) => {
|
||||
description: description || fallbackDescription,
|
||||
careInfo: {
|
||||
waterIntervalDays: Math.round(clamp(waterIntervalRaw, 1, 45)),
|
||||
light,
|
||||
temp,
|
||||
light: resolvedLight,
|
||||
temp: resolvedTemp,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -216,6 +222,10 @@ const buildIdentifyPrompt = (language, mode) => {
|
||||
'Rules:',
|
||||
nameLanguageInstruction,
|
||||
`- "description" and "careInfo.light" must be written in ${getLanguageLabel(language)}.`,
|
||||
`- "careInfo.light": short light requirement in ${getLanguageLabel(language)} (e.g. "bright indirect light", "full sun", "partial shade"). Must always be a real value, never "Unknown".`,
|
||||
language === 'en'
|
||||
? '- "careInfo.temp": temperature range in both Celsius and Fahrenheit (e.g. "18–24 °C (64–75 °F)"). Must always be a real plant-specific value, never "Unknown".'
|
||||
: '- "careInfo.temp": temperature range in Celsius (e.g. "18–24 °C"). Must always be a real plant-specific value, never "Unknown".',
|
||||
'- "botanicalName" must use accepted Latin scientific naming and must not be invented or misspelled.',
|
||||
'- If species is uncertain, prefer genus-level naming (for example: "Calathea sp.").',
|
||||
'- "confidence" must be between 0 and 1.',
|
||||
@@ -356,7 +366,7 @@ const identifyPlant = async ({ imageUri, language, mode = 'primary', plan = 'fre
|
||||
role: 'user',
|
||||
content: [
|
||||
{ type: 'text', text: buildIdentifyPrompt(language, mode) },
|
||||
{ type: 'image_url', image_url: { url: imageUri } },
|
||||
{ type: 'image_url', image_url: { url: imageUri, detail: 'low' } },
|
||||
],
|
||||
},
|
||||
],
|
||||
@@ -416,7 +426,7 @@ const analyzePlantHealth = async ({ imageUri, language, plantContext }) => {
|
||||
role: 'user',
|
||||
content: [
|
||||
{ type: 'text', text: buildHealthPrompt(language, plantContext) },
|
||||
{ type: 'image_url', image_url: { url: imageUri } },
|
||||
{ type: 'image_url', image_url: { url: imageUri, detail: 'low' } },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user