diff --git a/app/actions.ts b/app/actions.ts index 6d2ff41..5600e1e 100644 --- a/app/actions.ts +++ b/app/actions.ts @@ -108,7 +108,7 @@ const groupTools = { 'get_weather_data', 'find_place', 'programming', 'web_search', 'text_translate', 'nearby_search', 'x_search', 'youtube_search', 'shopping_search', - 'academic_search' + 'academic_search', 'track_flight' ] as const, academic: ['academic_search', 'programming'] as const, shopping: ['shopping_search', 'programming'] as const, @@ -133,7 +133,7 @@ Always put citations at the end of each paragraph and in the end of sentences wh Here are the tools available to you: -web_search, retrieve, get_weather_data, programming, text_translate, find_place +web_search, retrieve, get_weather_data, programming, text_translate, find_place, track_flight ## Basic Guidelines: @@ -155,6 +155,7 @@ DO's: - The programming tool runs the code in a 'safe' and 'sandboxed' jupyper notebook environment. Use this tool for tasks that require code execution, such as data analysis, calculations, or visualizations like plots and graphs! Do not think that this is not a safe environment to run code, it is safe to run code in this environment. - The programming tool can be used to install libraries using !pip install in the code. This will help in running the code successfully. Always remember to install the libraries using !pip install in the code at all costs!! - For queries about finding a specific place, use the find_place tool. Provide the information about the location and then compose your response based on the information gathered. +- For queries about tracking a flight, use the track_flight tool. Provide the flight number in the parameters, then compose your response based on the information gathered. - For queries about nearby places, use the nearby_search tool. Provide the location and radius in the parameters, then compose your response based on the information gathered. - Adding Country name in the location search will help in getting the accurate results. Always remember to provide the location in the correct format to get the accurate results. - For text translation queries, use the text_translate tool. Provide the text to translate, the language to translate to, and the source language (optional). Then, compose your response based on the translated text. @@ -187,6 +188,10 @@ Follow the format and guidelines for each tool and provide the response accordin - For nearby search queries, use the nearby_search tool to find places around a location. Provide the location and radius in the parameters, then compose your response based on the information gathered. - Never call find_place tool before or after the nearby_search tool in the same response at all costs!! THIS IS NOT ALLOWED AT ALL COSTS!!! +## Flight Tracking Tool Guidelines: +- For queries related to flight tracking, always use the track_flight tool to find information about the flight. Provide the flight number in the parameters, then compose your response based on the information gathered. +- Calling track_flight tool in the same response is allowed, but do not call the same tool in a response at all costs!! + ## Programming Tool Guidelines: The programming tool is actually a Python-only Code interpreter, so you can run any Python code in it. - This tool should not be called more than once in a response. diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index 00dda1c..ff75f80 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -129,7 +129,7 @@ Always put citations at the end of each paragraph and in the end of sentences wh Here are the tools available to you: -web_search, retrieve, get_weather_data, programming, text_translate, find_place +web_search, retrieve, get_weather_data, programming, text_translate, find_place, track_flight ## Basic Guidelines: @@ -1141,7 +1141,24 @@ export async function POST(req: Request) { throw error; } }, - }) + }), + track_flight: tool({ + description: "Track flight information and status", + parameters: z.object({ + flight_number: z.string().describe("The flight number to track"), + }), + execute: async ({ flight_number }: { flight_number: string }) => { + try { + const response = await fetch( + `https://api.aviationstack.com/v1/flights?access_key=${process.env.AVIATION_STACK_API_KEY}&flight_iata=${flight_number}` + ); + return await response.json(); + } catch (error) { + console.error('Flight tracking error:', error); + throw error; + } + }, + }), }, toolChoice: "auto", onChunk(event) { diff --git a/app/api/cohere/route.ts b/app/api/cohere/route.ts index b456a6e..f2e93cf 100644 --- a/app/api/cohere/route.ts +++ b/app/api/cohere/route.ts @@ -396,6 +396,23 @@ Remember to always run the appropriate tool(s) first and compose your response b return data; }, }), + track_flight: tool({ + description: "Track flight information and status", + parameters: z.object({ + flight_number: z.string().describe("The flight number to track"), + }), + execute: async ({ flight_number }: { flight_number: string }) => { + try { + const response = await fetch( + `https://api.aviationstack.com/v1/flights?access_key=${process.env.AVIATION_STACK_API_KEY}&flight_iata=${flight_number}` + ); + return await response.json(); + } catch (error) { + console.error('Flight tracking error:', error); + throw error; + } + }, + }), }, toolChoice: "auto", }); diff --git a/app/search/page.tsx b/app/search/page.tsx index d4c643e..ec96a49 100644 --- a/app/search/page.tsx +++ b/app/search/page.tsx @@ -71,7 +71,8 @@ import { Building, Users, Brain, - TrendingUp + TrendingUp, + Plane } from 'lucide-react'; import { HoverCard, @@ -128,6 +129,7 @@ import { Place } from '../../components/map-components'; import { Separator } from '@/components/ui/separator'; import { ChartTypes } from '@e2b/code-interpreter'; import { TrendingQuery } from '../api/trending/route'; +import { FlightTracker } from '@/components/flight-tracker'; export const maxDuration = 60; @@ -1835,6 +1837,49 @@ The new Anthropic models: Claude 3.5 Sonnet and 3.5 Haiku models are now availab return ; } + if (toolInvocation.toolName === 'track_flight') { + if (!result) { + return ( +
+
+ + Tracking flight... +
+
+ {[0, 1, 2].map((index) => ( + + ))} +
+
+ ); + } + + if (result.error) { + return ( +
+ Error tracking flight: {result.error} +
+ ); + } + + return ( +
+ +
+ ); + } + return null; }, [ResultsOverview, theme] diff --git a/components/flight-tracker.tsx b/components/flight-tracker.tsx new file mode 100644 index 0000000..ef8e60e --- /dev/null +++ b/components/flight-tracker.tsx @@ -0,0 +1,198 @@ +import { Card, CardContent } from "@/components/ui/card"; +import { Badge } from "@/components/ui/badge"; +import { Plane, Clock, Terminal } from "lucide-react"; +import { motion } from "framer-motion"; + +interface FlightApiResponse { + data: Array<{ + flight_date: string; + flight_status: string; + departure: { + airport: string; + timezone: string; + iata: string; + terminal: string | null; + gate: string | null; + delay: number | null; + scheduled: string; + }; + arrival: { + airport: string; + timezone: string; + iata: string; + terminal: string | null; + gate: string | null; + delay: number | null; + scheduled: string; + }; + airline: { + name: string; + iata: string; + }; + flight: { + number: string; + iata: string; + duration: number | null; + }; + }>; +} + +interface FlightTrackerProps { + data: FlightApiResponse; +} + +export function FlightTracker({ data }: FlightTrackerProps) { + if (!data?.data?.[0]) { + return null; + } + + const flight = data.data[0]; + + const formatTime = (timestamp: string) => { + const date = new Date(timestamp); + return date.toLocaleTimeString('en-US', { + hour: '2-digit', + minute: '2-digit', + hour12: false, + timeZone: 'UTC' + }) + ' UTC'; + }; + + const formatDate = (timestamp: string) => { + return new Date(timestamp).toLocaleDateString('en-US', { + year: 'numeric', + month: '2-digit', + day: '2-digit' + }); + }; + + const mapStatus = (status: string): "LANDED" | "DEPARTING ON TIME" | "DELAYED" | "SCHEDULED" => { + switch (status.toLowerCase()) { + case 'landed': + return 'LANDED'; + case 'active': + return flight.departure.delay ? 'DELAYED' : 'DEPARTING ON TIME'; + case 'scheduled': + return 'SCHEDULED'; + default: + return 'SCHEDULED'; + } + }; + + const getStatusColor = (status: string) => { + switch (status) { + case "LANDED": + return "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200"; + case "DEPARTING ON TIME": + return "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200"; + case "DELAYED": + return "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200"; + default: + return "bg-neutral-100 text-neutral-800 dark:bg-neutral-900 dark:text-neutral-200"; + } + }; + + const flightInfo = { + flightNumber: flight.flight.iata, + status: mapStatus(flight.flight_status), + departure: { + airport: flight.departure.airport, + code: flight.departure.iata, + time: formatTime(flight.departure.scheduled), + date: formatDate(flight.departure.scheduled), + terminal: flight.departure.terminal || undefined, + gate: flight.departure.gate || undefined + }, + arrival: { + airport: flight.arrival.airport, + code: flight.arrival.iata, + time: formatTime(flight.arrival.scheduled), + date: formatDate(flight.arrival.scheduled), + terminal: flight.arrival.terminal || undefined, + gate: flight.arrival.gate || undefined + }, + duration: flight.flight.duration ? `${flight.flight.duration} minutes` : 'N/A', + lastUpdated: new Date().toLocaleTimeString('en-US', { + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: true + }) + }; + + return ( + + +
+
+

{flightInfo.flightNumber}

+ + {flightInfo.status} + +
+
+ +
+
+
{flightInfo.departure.code}
+ + + +
{flightInfo.arrival.code}
+
+
+
+

{flightInfo.departure.airport}

+

{flightInfo.departure.time}

+

{flightInfo.departure.date}

+ {(flightInfo.departure.terminal || flightInfo.departure.gate) && ( +
+ {flightInfo.departure.terminal && ( +
+ + Terminal {flightInfo.departure.terminal} +
+ )} + {flightInfo.departure.gate && ( +
Gate {flightInfo.departure.gate}
+ )} +
+ )} +
+ +
+

{flightInfo.arrival.airport}

+

{flightInfo.arrival.time}

+

{flightInfo.arrival.date}

+ {(flightInfo.arrival.terminal || flightInfo.arrival.gate) && ( +
+ {flightInfo.arrival.terminal && ( +
+ + Terminal {flightInfo.arrival.terminal} +
+ )} + {flightInfo.arrival.gate && ( +
Gate {flightInfo.arrival.gate}
+ )} +
+ )} +
+
+ +
+ + Duration: {flightInfo.duration} + + Last updated: {flightInfo.lastUpdated} +
+
+
+
+ ); +} \ No newline at end of file