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/api/trending/route.ts b/app/api/trending/route.ts
new file mode 100644
index 0000000..561285d
--- /dev/null
+++ b/app/api/trending/route.ts
@@ -0,0 +1,121 @@
+import { NextResponse } from 'next/server';
+
+export interface TrendingQuery {
+ icon: string;
+ text: string;
+ category: string;
+}
+
+interface RedditPost {
+ data: {
+ title: string;
+ };
+}
+
+async function fetchGoogleTrends(): Promise {
+ const fetchTrends = async (geo: string): Promise => {
+ try {
+ const response = await fetch(`https://trends.google.com/trends/trendingsearches/daily/rss?geo=${geo}`, {
+ headers: {
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
+ }
+ });
+
+ if (!response.ok) {
+ throw new Error(`Failed to fetch from Google Trends RSS for geo: ${geo}`);
+ }
+
+ const xmlText = await response.text();
+ const items = xmlText.match(/(?!Daily Search Trends)(.*?)<\/title>/g) || [];
+
+ return items.map(item => ({
+ icon: 'trending',
+ text: item.replace(/<\/?title>/g, ''),
+ category: 'trending' // TODO: add category based on the query results
+ }));
+ } catch (error) {
+ console.error(`Failed to fetch Google Trends for geo: ${geo}`, error);
+ return [];
+ }
+ };
+
+ const trendsIN = await fetchTrends('IN');
+ const trendsUS = await fetchTrends('US');
+
+ return [...trendsIN, ...trendsUS];
+}
+
+async function fetchRedditQuestions(): Promise {
+ try {
+ const response = await fetch(
+ 'https://www.reddit.com/r/askreddit/hot.json?limit=100',
+ {
+ headers: {
+ 'User-Agent': 'MiniPerplx/1.0'
+ }
+ }
+ );
+
+ const data = await response.json();
+ const maxLength = 50;
+
+ return data.data.children
+ .map((post: RedditPost) => ({
+ icon: 'question',
+ text: post.data.title,
+ category: 'community'
+ }))
+ .filter((query: TrendingQuery) => query.text.length <= maxLength)
+ .slice(0, 15);
+ } catch (error) {
+ console.error('Failed to fetch Reddit questions:', error);
+ return [];
+ }
+}
+
+async function fetchFromMultipleSources() {
+ const [googleTrends,
+ // redditQuestions
+] = await Promise.all([
+ fetchGoogleTrends(),
+ // fetchRedditQuestions(),
+ ]);
+
+ const allQueries = [...googleTrends,
+ // ...redditQuestions
+];
+ return allQueries
+ .sort(() => Math.random() - 0.5);
+}
+
+export async function GET() {
+ try {
+ const trends = await fetchFromMultipleSources();
+
+ if (trends.length === 0) {
+ // Fallback queries if both sources fail
+ return NextResponse.json([
+ {
+ icon: 'sparkles',
+ text: "What causes the Northern Lights?",
+ category: 'science'
+ },
+ {
+ icon: 'code',
+ text: "Explain quantum computing",
+ category: 'tech'
+ },
+ {
+ icon: 'globe',
+ text: "Most beautiful places in Japan",
+ category: 'travel'
+ }
+ ]);
+ }
+
+ return NextResponse.json(trends);
+ } catch (error) {
+ console.error('Failed to fetch trends:', error);
+ return NextResponse.error();
+ }
+}
\ No newline at end of file
diff --git a/app/search/page.tsx b/app/search/page.tsx
index 2251dce..a640b13 100644
--- a/app/search/page.tsx
+++ b/app/search/page.tsx
@@ -68,7 +68,11 @@ import {
Book,
Eye,
ExternalLink,
- Building
+ Building,
+ Users,
+ Brain,
+ TrendingUp,
+ Plane
} from 'lucide-react';
import {
HoverCard,
@@ -124,6 +128,8 @@ import NearbySearchMapView from '@/components/nearby-search-map-view';
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;
@@ -585,6 +591,8 @@ const HomeContent = () => {
const [openChangelog, setOpenChangelog] = useState(false);
+ const [trendingQueries, setTrendingQueries] = useState([]);
+
const { isLoading, input, messages, setInput, append, handleSubmit, setMessages, reload, stop } = useChat({
maxSteps: 10,
body: {
@@ -623,6 +631,21 @@ const HomeContent = () => {
}
}, [initialState.query, append, setInput, messages.length]);
+ useEffect(() => {
+ const fetchTrending = async () => {
+ try {
+ const res = await fetch('/api/trending');
+ if (!res.ok) throw new Error('Failed to fetch trending queries');
+ const data = await res.json();
+ setTrendingQueries(data);
+ } catch (error) {
+ console.error('Error fetching trending queries:', error);
+ setTrendingQueries([]);
+ }
+ };
+
+ fetchTrending();
+ }, []);
const ThemeToggle: React.FC = () => {
const { theme, setTheme } = useTheme();
@@ -1118,7 +1141,7 @@ The new Anthropic models: Claude 3.5 Sonnet and 3.5 Haiku models are now availab
-
+
{result.map((product: ShoppingProduct) => (
))}
@@ -1819,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]
@@ -2042,15 +2103,12 @@ The new Anthropic models: Claude 3.5 Sonnet and 3.5 Haiku models are now availab
return () => window.removeEventListener('scroll', handleScroll);
}, [messages, suggestedQuestions]);
- const handleExampleClick = async (card: typeof suggestionCards[number]) => {
+ const handleExampleClick = async (card: TrendingQuery) => {
const exampleText = card.text;
track("search example", { query: exampleText });
lastSubmittedQueryRef.current = exampleText;
setHasSubmitted(true);
setSuggestedQuestions([]);
- console.log('exampleText', exampleText);
- console.log('lastSubmittedQuery', lastSubmittedQueryRef.current);
-
await append({
content: exampleText.trim(),
role: 'user',
@@ -2087,21 +2145,6 @@ The new Anthropic models: Claude 3.5 Sonnet and 3.5 Haiku models are now availab
}
}, [input, messages, editingMessageIndex, setMessages, handleSubmit]);
- const suggestionCards = [
- {
- icon: ,
- text: "Shah Rukh Khan",
- },
- {
- icon: ,
- text: "Weather in Doha",
- },
- {
- icon: ,
- text: "Count the no. of r's in strawberry?",
- },
- ];
-
interface NavbarProps { }
const Navbar: React.FC = () => {
@@ -2152,20 +2195,92 @@ The new Anthropic models: Claude 3.5 Sonnet and 3.5 Haiku models are now availab
);
};
- const SuggestionCards: React.FC<{ selectedModel: string }> = ({ selectedModel }) => {
- return (
-