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
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 4m12s
This commit is contained in:
@@ -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) => {
|
router.post('/plan-trip', passport.authenticate('jwt', { session: false }), async (req, res, next) => {
|
||||||
try {
|
// try {
|
||||||
const { items, store, userLocation } = req.body;
|
// const { items, store, userLocation } = req.body;
|
||||||
logger.info(`Server-side trip planning requested for user.`);
|
// logger.info(`Server-side trip planning requested for user.`);
|
||||||
const result = await aiService.planTripWithMaps(items, store, userLocation);
|
// const result = await aiService.planTripWithMaps(items, store, userLocation);
|
||||||
res.status(200).json(result);
|
// res.status(200).json(result);
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
logger.error('Error in /api/ai/plan-trip endpoint:', { error });
|
// logger.error('Error in /api/ai/plan-trip endpoint:', { error });
|
||||||
next(error);
|
// next(error);
|
||||||
}
|
// }
|
||||||
|
res.status(501).json({ message: 'This feature is currently disabled.' });
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- STUBBED AI Routes for Future Features ---
|
// --- STUBBED AI Routes for Future Features ---
|
||||||
|
|||||||
@@ -109,14 +109,14 @@ export const searchWeb = async (items: FlyerItem[], tokenOverride?: string): Pro
|
|||||||
* @param userLocation The user's current geographic coordinates.
|
* @param userLocation The user's current geographic coordinates.
|
||||||
* @returns A text response with trip planning advice and a list of map sources.
|
* @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> => {
|
// export const planTripWithMaps = async (items: FlyerItem[], store: Store | undefined, userLocation: GeolocationCoordinates, tokenOverride?: string): Promise<Response> => {
|
||||||
logger.debug("Stub: planTripWithMaps called with location:", { userLocation });
|
// logger.debug("Stub: planTripWithMaps called with location:", { userLocation });
|
||||||
return apiFetchWithAuth('/ai/plan-trip', {
|
// return apiFetchWithAuth('/ai/plan-trip', {
|
||||||
method: 'POST',
|
// method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
// headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ items, store, userLocation }),
|
// body: JSON.stringify({ items, store, userLocation }),
|
||||||
}, tokenOverride);
|
// }, tokenOverride);
|
||||||
};
|
// };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [STUB] Generates an image based on a text prompt using the Imagen model.
|
* [STUB] Generates an image based on a text prompt using the Imagen model.
|
||||||
|
|||||||
@@ -275,39 +275,42 @@ export const extractTextFromImageArea = async (
|
|||||||
* @returns A text response with trip planning advice and a list of map sources.
|
* @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; }[]}> => {
|
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 topItems = items.slice(0, 5).map(i => i.item).join(', ');
|
||||||
const storeName = store?.name || 'the grocery store';
|
// const storeName = store?.name || 'the grocery store';
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
const response = await model.generateContent({
|
// const response = await model.generateContent({
|
||||||
model: "gemini-2.5-flash",
|
// model: "gemini-2.5-flash",
|
||||||
// Make the prompt more specific by providing context for the location.
|
// // Make the prompt more specific by providing context for the location.
|
||||||
// This helps the AI ground its search more accurately.
|
// // This helps the AI ground its search more accurately.
|
||||||
contents: `My current location is latitude ${userLocation.latitude}, longitude ${userLocation.longitude}.
|
// 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.
|
// 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?`,
|
// Also, are there any other specialty stores nearby (like a bakery or butcher) that might have good deals on related items?`,
|
||||||
config: {
|
// config: {
|
||||||
tools: [{googleMaps: {}}],
|
// tools: [{googleMaps: {}}],
|
||||||
toolConfig: {
|
// toolConfig: {
|
||||||
retrievalConfig: {
|
// retrievalConfig: {
|
||||||
latLng: {
|
// latLng: {
|
||||||
latitude: userLocation.latitude,
|
// latitude: userLocation.latitude,
|
||||||
longitude: userLocation.longitude
|
// longitude: userLocation.longitude
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
|
|
||||||
// In a real implementation, you would render the map URLs from the sources.
|
// // In a real implementation, you would render the map URLs from the sources.
|
||||||
const sources = (response.candidates?.[0]?.groundingMetadata?.groundingChunks || []).map(chunk => ({
|
// const sources = (response.candidates?.[0]?.groundingMetadata?.groundingChunks || []).map(chunk => ({
|
||||||
uri: chunk.web?.uri || '',
|
// uri: chunk.web?.uri || '',
|
||||||
title: chunk.web?.title || 'Untitled'
|
// title: chunk.web?.title || 'Untitled'
|
||||||
}));
|
// }));
|
||||||
return { text: response.text ?? '', sources };
|
// return { text: response.text ?? '', sources };
|
||||||
} catch (apiError) {
|
// } catch (apiError) {
|
||||||
logger.error("Google GenAI API call failed in planTripWithMaps:", { error: apiError });
|
// logger.error("Google GenAI API call failed in planTripWithMaps:", { error: apiError });
|
||||||
throw 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.");
|
||||||
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user