comment out road trip planning as it requires google maps api key $$$
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 4m12s

This commit is contained in:
2025-12-03 21:02:57 -08:00
parent aefa3f6121
commit 79393548c6
3 changed files with 53 additions and 49 deletions

View File

@@ -348,15 +348,16 @@ router.post('/search-web', passport.authenticate('jwt', { session: false }), asy
});
router.post('/plan-trip', passport.authenticate('jwt', { session: false }), async (req, res, next) => {
try {
const { items, store, userLocation } = req.body;
logger.info(`Server-side trip planning requested for user.`);
const result = await aiService.planTripWithMaps(items, store, userLocation);
res.status(200).json(result);
} catch (error) {
logger.error('Error in /api/ai/plan-trip endpoint:', { error });
next(error);
}
// try {
// const { items, store, userLocation } = req.body;
// logger.info(`Server-side trip planning requested for user.`);
// const result = await aiService.planTripWithMaps(items, store, userLocation);
// res.status(200).json(result);
// } catch (error) {
// logger.error('Error in /api/ai/plan-trip endpoint:', { error });
// next(error);
// }
res.status(501).json({ message: 'This feature is currently disabled.' });
});
// --- STUBBED AI Routes for Future Features ---

View File

@@ -109,14 +109,14 @@ export const searchWeb = async (items: FlyerItem[], tokenOverride?: string): Pro
* @param userLocation The user's current geographic coordinates.
* @returns A text response with trip planning advice and a list of map sources.
*/
export const planTripWithMaps = async (items: FlyerItem[], store: Store | undefined, userLocation: GeolocationCoordinates, tokenOverride?: string): Promise<Response> => {
logger.debug("Stub: planTripWithMaps called with location:", { userLocation });
return apiFetchWithAuth('/ai/plan-trip', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ items, store, userLocation }),
}, tokenOverride);
};
// export const planTripWithMaps = async (items: FlyerItem[], store: Store | undefined, userLocation: GeolocationCoordinates, tokenOverride?: string): Promise<Response> => {
// logger.debug("Stub: planTripWithMaps called with location:", { userLocation });
// return apiFetchWithAuth('/ai/plan-trip', {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify({ items, store, userLocation }),
// }, tokenOverride);
// };
/**
* [STUB] Generates an image based on a text prompt using the Imagen model.

View File

@@ -275,39 +275,42 @@ export const extractTextFromImageArea = async (
* @returns A text response with trip planning advice and a list of map sources.
*/
export const planTripWithMaps = async (items: FlyerItem[], store: { name: string } | undefined, userLocation: GeolocationCoordinates): Promise<{text: string; sources: { uri: string; title: string; }[]}> => {
const topItems = items.slice(0, 5).map(i => i.item).join(', ');
const storeName = store?.name || 'the grocery store';
// const topItems = items.slice(0, 5).map(i => i.item).join(', ');
// const storeName = store?.name || 'the grocery store';
try {
const response = await model.generateContent({
model: "gemini-2.5-flash",
// Make the prompt more specific by providing context for the location.
// This helps the AI ground its search more accurately.
contents: `My current location is latitude ${userLocation.latitude}, longitude ${userLocation.longitude}.
I have a shopping list with items like ${topItems}. Find the nearest ${storeName} to me and suggest the best route.
Also, are there any other specialty stores nearby (like a bakery or butcher) that might have good deals on related items?`,
config: {
tools: [{googleMaps: {}}],
toolConfig: {
retrievalConfig: {
latLng: {
latitude: userLocation.latitude,
longitude: userLocation.longitude
}
}
}
},
});
// try {
// const response = await model.generateContent({
// model: "gemini-2.5-flash",
// // Make the prompt more specific by providing context for the location.
// // This helps the AI ground its search more accurately.
// contents: `My current location is latitude ${userLocation.latitude}, longitude ${userLocation.longitude}.
// I have a shopping list with items like ${topItems}. Find the nearest ${storeName} to me and suggest the best route.
// Also, are there any other specialty stores nearby (like a bakery or butcher) that might have good deals on related items?`,
// config: {
// tools: [{googleMaps: {}}],
// toolConfig: {
// retrievalConfig: {
// latLng: {
// latitude: userLocation.latitude,
// longitude: userLocation.longitude
// }
// }
// }
// },
// });
// In a real implementation, you would render the map URLs from the sources.
const sources = (response.candidates?.[0]?.groundingMetadata?.groundingChunks || []).map(chunk => ({
uri: chunk.web?.uri || '',
title: chunk.web?.title || 'Untitled'
}));
return { text: response.text ?? '', sources };
} catch (apiError) {
logger.error("Google GenAI API call failed in planTripWithMaps:", { error: apiError });
throw apiError;
}
// // In a real implementation, you would render the map URLs from the sources.
// const sources = (response.candidates?.[0]?.groundingMetadata?.groundingChunks || []).map(chunk => ({
// uri: chunk.web?.uri || '',
// title: chunk.web?.title || 'Untitled'
// }));
// return { text: response.text ?? '', sources };
// } catch (apiError) {
// logger.error("Google GenAI API call failed in planTripWithMaps:", { error: apiError });
// throw apiError;
// }
// Return a 501 Not Implemented error as this feature is disabled.
throw new Error("The 'planTripWithMaps' feature is currently disabled due to API costs.");
};