diff --git a/package.json b/package.json index 5715c2a..999740d 100644 --- a/package.json +++ b/package.json @@ -15,13 +15,11 @@ "@headlessui/react": "^2.2.0", "@iarna/toml": "^2.2.5", "@icons-pack/react-simple-icons": "^12.3.0", - "@langchain/anthropic": "^0.3.24", - "@langchain/community": "^0.3.49", - "@langchain/core": "^0.3.66", - "@langchain/google-genai": "^0.2.15", - "@langchain/groq": "^0.2.3", - "@langchain/ollama": "^0.2.3", - "@langchain/openai": "^0.6.2", + "@langchain/anthropic": "^0.3.15", + "@langchain/community": "^0.3.36", + "@langchain/core": "^0.3.42", + "@langchain/google-genai": "^0.1.12", + "@langchain/openai": "^0.0.25", "@langchain/textsplitters": "^0.1.0", "@tailwindcss/typography": "^0.5.12", "@xenova/transformers": "^2.17.2", @@ -33,7 +31,7 @@ "drizzle-orm": "^0.40.1", "html-to-text": "^9.0.5", "jspdf": "^3.0.1", - "langchain": "^0.3.30", + "langchain": "^0.1.30", "lucide-react": "^0.363.0", "mammoth": "^1.9.1", "markdown-to-jsx": "^7.7.2", diff --git a/src/app/api/chat/route.ts b/src/app/api/chat/route.ts index ba88da6..e566edb 100644 --- a/src/app/api/chat/route.ts +++ b/src/app/api/chat/route.ts @@ -1,7 +1,11 @@ +import prompts from '@/lib/prompts'; +import MetaSearchAgent from '@/lib/search/metaSearchAgent'; import crypto from 'crypto'; import { AIMessage, BaseMessage, HumanMessage } from '@langchain/core/messages'; import { EventEmitter } from 'stream'; import { + chatModelProviders, + embeddingModelProviders, getAvailableChatModelProviders, getAvailableEmbeddingModelProviders, } from '@/lib/providers'; @@ -134,8 +138,6 @@ const handleHistorySave = async ( where: eq(chats.id, message.chatId), }); - const fileData = files.map(getFileDetails); - if (!chat) { await db .insert(chats) @@ -144,15 +146,9 @@ const handleHistorySave = async ( title: message.content, createdAt: new Date().toString(), focusMode: focusMode, - files: fileData, - }) - .execute(); - } else if (JSON.stringify(chat.files ?? []) != JSON.stringify(fileData)) { - db.update(chats) - .set({ files: files.map(getFileDetails), }) - .where(eq(chats.id, message.chatId)); + .execute(); } const messageExists = await db.query.messages.findFirst({ @@ -227,7 +223,7 @@ export const POST = async (req: Request) => { if (body.chatModel?.provider === 'custom_openai') { llm = new ChatOpenAI({ - apiKey: getCustomOpenaiApiKey(), + openAIApiKey: getCustomOpenaiApiKey(), modelName: getCustomOpenaiModelName(), temperature: 0.7, configuration: { diff --git a/src/app/api/config/route.ts b/src/app/api/config/route.ts index f117cce..0c11b23 100644 --- a/src/app/api/config/route.ts +++ b/src/app/api/config/route.ts @@ -11,7 +11,6 @@ import { getAimlApiKey, getLMStudioApiEndpoint, updateConfig, - getOllamaApiKey, } from '@/lib/config'; import { getAvailableChatModelProviders, @@ -54,7 +53,6 @@ export const GET = async (req: Request) => { config['openaiApiKey'] = getOpenaiApiKey(); config['ollamaApiUrl'] = getOllamaApiEndpoint(); - config['ollamaApiKey'] = getOllamaApiKey(); config['lmStudioApiUrl'] = getLMStudioApiEndpoint(); config['anthropicApiKey'] = getAnthropicApiKey(); config['groqApiKey'] = getGroqApiKey(); @@ -95,7 +93,6 @@ export const POST = async (req: Request) => { }, OLLAMA: { API_URL: config.ollamaApiUrl, - API_KEY: config.ollamaApiKey, }, DEEPSEEK: { API_KEY: config.deepseekApiKey, diff --git a/src/app/api/discover/route.ts b/src/app/api/discover/route.ts index 415aee8..b1c761d 100644 --- a/src/app/api/discover/route.ts +++ b/src/app/api/discover/route.ts @@ -1,77 +1,55 @@ import { searchSearxng } from '@/lib/searxng'; -const websitesForTopic = { - tech: { - query: ['technology news', 'latest tech', 'AI', 'science and innovation'], - links: ['techcrunch.com', 'wired.com', 'theverge.com'], - }, - finance: { - query: ['finance news', 'economy', 'stock market', 'investing'], - links: ['bloomberg.com', 'cnbc.com', 'marketwatch.com'], - }, - art: { - query: ['art news', 'culture', 'modern art', 'cultural events'], - links: ['artnews.com', 'hyperallergic.com', 'theartnewspaper.com'], - }, - sports: { - query: ['sports news', 'latest sports', 'cricket football tennis'], - links: ['espn.com', 'bbc.com/sport', 'skysports.com'], - }, - entertainment: { - query: ['entertainment news', 'movies', 'TV shows', 'celebrities'], - links: ['hollywoodreporter.com', 'variety.com', 'deadline.com'], - }, -}; +const articleWebsites = [ + 'yahoo.com', + 'www.exchangewire.com', + 'businessinsider.com', + /* 'wired.com', + 'mashable.com', + 'theverge.com', + 'gizmodo.com', + 'cnet.com', + 'venturebeat.com', */ +]; -type Topic = keyof typeof websitesForTopic; +const topics = ['AI', 'tech']; /* TODO: Add UI to customize this */ export const GET = async (req: Request) => { try { const params = new URL(req.url).searchParams; - const mode: 'normal' | 'preview' = (params.get('mode') as 'normal' | 'preview') || 'normal'; - const topic: Topic = (params.get('topic') as Topic) || 'tech'; - - const selectedTopic = websitesForTopic[topic]; let data = []; if (mode === 'normal') { - const seenUrls = new Set(); - data = ( - await Promise.all( - selectedTopic.links.flatMap((link) => - selectedTopic.query.map(async (query) => { + await Promise.all([ + ...new Array(articleWebsites.length * topics.length) + .fill(0) + .map(async (_, i) => { return ( - await searchSearxng(`site:${link} ${query}`, { - engines: ['bing news'], - pageno: 1, - language: 'en', - }) + await searchSearxng( + `site:${articleWebsites[i % articleWebsites.length]} ${ + topics[i % topics.length] + }`, + { + engines: ['bing news'], + pageno: 1, + }, + ) ).results; }), - ), - ) + ]) ) + .map((result) => result) .flat() - .filter((item) => { - const url = item.url?.toLowerCase().trim(); - if (seenUrls.has(url)) return false; - seenUrls.add(url); - return true; - }) .sort(() => Math.random() - 0.5); } else { data = ( await searchSearxng( - `site:${selectedTopic.links[Math.floor(Math.random() * selectedTopic.links.length)]} ${selectedTopic.query[Math.floor(Math.random() * selectedTopic.query.length)]}`, - { - engines: ['bing news'], - pageno: 1, - language: 'en', - }, + `site:${articleWebsites[Math.floor(Math.random() * articleWebsites.length)]} ${topics[Math.floor(Math.random() * topics.length)]}`, + { engines: ['bing news'], pageno: 1 }, ) ).results; } diff --git a/src/app/api/images/route.ts b/src/app/api/images/route.ts index e02854d..db39d9f 100644 --- a/src/app/api/images/route.ts +++ b/src/app/api/images/route.ts @@ -49,7 +49,7 @@ export const POST = async (req: Request) => { if (body.chatModel?.provider === 'custom_openai') { llm = new ChatOpenAI({ - apiKey: getCustomOpenaiApiKey(), + openAIApiKey: getCustomOpenaiApiKey(), modelName: getCustomOpenaiModelName(), temperature: 0.7, configuration: { diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts index 5f752ec..970ec42 100644 --- a/src/app/api/search/route.ts +++ b/src/app/api/search/route.ts @@ -81,7 +81,8 @@ export const POST = async (req: Request) => { if (body.chatModel?.provider === 'custom_openai') { llm = new ChatOpenAI({ modelName: body.chatModel?.name || getCustomOpenaiModelName(), - apiKey: body.chatModel?.customOpenAIKey || getCustomOpenaiApiKey(), + openAIApiKey: + body.chatModel?.customOpenAIKey || getCustomOpenaiApiKey(), temperature: 0.7, configuration: { baseURL: diff --git a/src/app/api/suggestions/route.ts b/src/app/api/suggestions/route.ts index 99179d2..e92e5ec 100644 --- a/src/app/api/suggestions/route.ts +++ b/src/app/api/suggestions/route.ts @@ -48,7 +48,7 @@ export const POST = async (req: Request) => { if (body.chatModel?.provider === 'custom_openai') { llm = new ChatOpenAI({ - apiKey: getCustomOpenaiApiKey(), + openAIApiKey: getCustomOpenaiApiKey(), modelName: getCustomOpenaiModelName(), temperature: 0.7, configuration: { diff --git a/src/app/api/videos/route.ts b/src/app/api/videos/route.ts index 7e8288b..34ae7fd 100644 --- a/src/app/api/videos/route.ts +++ b/src/app/api/videos/route.ts @@ -49,7 +49,7 @@ export const POST = async (req: Request) => { if (body.chatModel?.provider === 'custom_openai') { llm = new ChatOpenAI({ - apiKey: getCustomOpenaiApiKey(), + openAIApiKey: getCustomOpenaiApiKey(), modelName: getCustomOpenaiModelName(), temperature: 0.7, configuration: { diff --git a/src/app/api/weather/route.ts b/src/app/api/weather/route.ts index afaf8a6..7594aa9 100644 --- a/src/app/api/weather/route.ts +++ b/src/app/api/weather/route.ts @@ -1,10 +1,6 @@ export const POST = async (req: Request) => { try { - const body: { - lat: number; - lng: number; - measureUnit: 'Imperial' | 'Metric'; - } = await req.json(); + const body: { lat: number; lng: number } = await req.json(); if (!body.lat || !body.lng) { return Response.json( @@ -16,9 +12,7 @@ export const POST = async (req: Request) => { } const res = await fetch( - `https://api.open-meteo.com/v1/forecast?latitude=${body.lat}&longitude=${body.lng}¤t=weather_code,temperature_2m,is_day,relative_humidity_2m,wind_speed_10m&timezone=auto${ - body.measureUnit === 'Metric' ? '' : '&temperature_unit=fahrenheit' - }${body.measureUnit === 'Metric' ? '' : '&wind_speed_unit=mph'}`, + `https://api.open-meteo.com/v1/forecast?latitude=${body.lat}&longitude=${body.lng}¤t=weather_code,temperature_2m,is_day,relative_humidity_2m,wind_speed_10m&timezone=auto`, ); const data = await res.json(); @@ -39,16 +33,12 @@ export const POST = async (req: Request) => { humidity: number; windSpeed: number; icon: string; - temperatureUnit: 'C' | 'F'; - windSpeedUnit: 'm/s' | 'mph'; } = { temperature: data.current.temperature_2m, condition: '', humidity: data.current.relative_humidity_2m, windSpeed: data.current.wind_speed_10m, icon: '', - temperatureUnit: body.measureUnit === 'Metric' ? 'C' : 'F', - windSpeedUnit: body.measureUnit === 'Metric' ? 'm/s' : 'mph', }; const code = data.current.weather_code; diff --git a/src/app/c/[chatId]/page.tsx b/src/app/c/[chatId]/page.tsx index 672107a..aac125a 100644 --- a/src/app/c/[chatId]/page.tsx +++ b/src/app/c/[chatId]/page.tsx @@ -1,17 +1,9 @@ -'use client'; - import ChatWindow from '@/components/ChatWindow'; -import { useParams } from 'next/navigation'; import React from 'react'; -import { ChatProvider } from '@/lib/hooks/useChat'; -const Page = () => { - const { chatId }: { chatId: string } = useParams(); - return ( - - - - ); +const Page = ({ params }: { params: Promise<{ chatId: string }> }) => { + const { chatId } = React.use(params); + return ; }; export default Page; diff --git a/src/app/discover/page.tsx b/src/app/discover/page.tsx index 8e20e50..eb7de7f 100644 --- a/src/app/discover/page.tsx +++ b/src/app/discover/page.tsx @@ -4,7 +4,6 @@ import { Search } from 'lucide-react'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { toast } from 'sonner'; -import { cn } from '@/lib/utils'; interface Discover { title: string; @@ -13,66 +12,60 @@ interface Discover { thumbnail: string; } -const topics: { key: string; display: string }[] = [ - { - display: 'Tech & Science', - key: 'tech', - }, - { - display: 'Finance', - key: 'finance', - }, - { - display: 'Art & Culture', - key: 'art', - }, - { - display: 'Sports', - key: 'sports', - }, - { - display: 'Entertainment', - key: 'entertainment', - }, -]; - const Page = () => { const [discover, setDiscover] = useState(null); const [loading, setLoading] = useState(true); - const [activeTopic, setActiveTopic] = useState(topics[0].key); - - const fetchArticles = async (topic: string) => { - setLoading(true); - try { - const res = await fetch(`/api/discover?topic=${topic}`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }); - - const data = await res.json(); - - if (!res.ok) { - throw new Error(data.message); - } - - data.blogs = data.blogs.filter((blog: Discover) => blog.thumbnail); - - setDiscover(data.blogs); - } catch (err: any) { - console.error('Error fetching data:', err.message); - toast.error('Error fetching data'); - } finally { - setLoading(false); - } - }; useEffect(() => { - fetchArticles(activeTopic); - }, [activeTopic]); + const fetchData = async () => { + try { + const res = await fetch(`/api/discover`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }); - return ( + const data = await res.json(); + + if (!res.ok) { + throw new Error(data.message); + } + + data.blogs = data.blogs.filter((blog: Discover) => blog.thumbnail); + + setDiscover(data.blogs); + } catch (err: any) { + console.error('Error fetching data:', err.message); + toast.error('Error fetching data'); + } finally { + setLoading(false); + } + }; + + fetchData(); + }, []); + + return loading ? ( +
+ +
+ ) : ( <>
@@ -83,73 +76,35 @@ const Page = () => {
-
- {topics.map((t, i) => ( -
setActiveTopic(t.key)} - > - {t.display} -
- ))} -
- - {loading ? ( -
- -
- ) : ( -
- {discover && - discover?.map((item, i) => ( - - {item.title} -
-
- {item.title.slice(0, 100)}... -
-

- {item.content.slice(0, 100)}... -

+
+ {discover && + discover?.map((item, i) => ( + + {item.title} +
+
+ {item.title.slice(0, 100)}...
- - ))} -
- )} +

+ {item.content.slice(0, 100)}... +

+
+ + ))} +
); diff --git a/src/app/page.tsx b/src/app/page.tsx index 25981b5..e18aca9 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,5 +1,4 @@ import ChatWindow from '@/components/ChatWindow'; -import { ChatProvider } from '@/lib/hooks/useChat'; import { Metadata } from 'next'; import { Suspense } from 'react'; @@ -12,9 +11,7 @@ const Home = () => { return (
- - - +
); diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx index 6fb8255..b91519e 100644 --- a/src/app/settings/page.tsx +++ b/src/app/settings/page.tsx @@ -21,7 +21,6 @@ interface SettingsType { anthropicApiKey: string; geminiApiKey: string; ollamaApiUrl: string; - ollamaApiKey: string; lmStudioApiUrl: string; deepseekApiKey: string; aimlApiKey: string; @@ -149,9 +148,6 @@ const Page = () => { const [automaticImageSearch, setAutomaticImageSearch] = useState(false); const [automaticVideoSearch, setAutomaticVideoSearch] = useState(false); const [systemInstructions, setSystemInstructions] = useState(''); - const [measureUnit, setMeasureUnit] = useState<'Imperial' | 'Metric'>( - 'Metric', - ); const [savingStates, setSavingStates] = useState>({}); useEffect(() => { @@ -214,10 +210,6 @@ const Page = () => { setSystemInstructions(localStorage.getItem('systemInstructions')!); - setMeasureUnit( - localStorage.getItem('measureUnit')! as 'Imperial' | 'Metric', - ); - setIsLoading(false); }; @@ -376,8 +368,6 @@ const Page = () => { localStorage.setItem('embeddingModel', value); } else if (key === 'systemInstructions') { localStorage.setItem('systemInstructions', value); - } else if (key === 'measureUnit') { - localStorage.setItem('measureUnit', value.toString()); } } catch (err) { console.error('Failed to save:', err); @@ -426,35 +416,13 @@ const Page = () => { ) : ( config && (
- +

Theme

-
-

- Measurement Units -

-