diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index 5b82945..37f1e24 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -1,6 +1,6 @@ import { openai } from "@ai-sdk/openai"; import { anthropic } from '@ai-sdk/anthropic' -import { convertToCoreMessages, streamText } from "ai"; +import { convertToCoreMessages, streamText, tool } from "ai"; import { z } from "zod"; // Allow streaming responses up to 30 seconds @@ -27,6 +27,7 @@ export async function POST(req: Request) { "Once you have found the information, you provide the user with the information you found in brief like a news paper detail." + "The detail should be 3-5 paragraphs in 10-12 sentences, some time pointers, each with citations in the [Text](link) format always!" + "Citations can be inline of the text like this: Hey there! [Google](https://google.com) is a search engine." + + "Do not start the responses with newline characters, always start with the first sentence." + "The current date is: " + new Date() .toLocaleDateString("en-US", { @@ -39,7 +40,7 @@ export async function POST(req: Request) { "Never use the heading format in your response!." + "Refrain from saying things like 'Certainly! I'll search for information about OpenAI GPT-4o mini using the web search tool.'", tools: { - web_search: { + web_search: tool({ description: 'Search the web for information with the given query, max results and search depth.', parameters: z.object({ query: z.string() @@ -82,7 +83,7 @@ export async function POST(req: Request) { results: context } } - }, + }), }, onFinish: async (event) => { console.log(event.text); diff --git a/app/page.tsx b/app/page.tsx index dc20586..92989cc 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -37,6 +37,7 @@ export default function Home() { const [showToolResults, setShowToolResults] = useState<{ [key: number]: boolean }>({}); const [isModelSelectorOpen, setIsModelSelectorOpen] = useState(false); const [selectedModel, setSelectedModel] = useState('Speed'); + const [showExamples, setShowExamples] = useState(false) const { isLoading, input, messages, setInput, append, handleSubmit, setMessages } = useChat({ api: '/api/chat', @@ -315,33 +316,39 @@ export default function Home() { value={input} onChange={(e) => setInput(e.target.value)} disabled={isLoading} - className="w-full h-10 py-3 px-4 bg-gray-100 rounded-full pr-12 focus:outline-none focus:ring-2 focus:ring-green-500 text-sm sm:text-base" + className="w-full min-h-12 py-3 px-4 bg-muted border border-input rounded-full pr-12 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 text-sm sm:text-base" + onFocus={() => setShowExamples(true)} + onBlur={() => setShowExamples(false)} /> -
- {exampleQueries.map((query, index) => ( - - ))} +
+
+
+ {exampleQueries.map((message, index) => ( + + ))} +
+
)} @@ -362,7 +369,7 @@ export default function Home() { initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.5, delay: 0.2 }} - className="text-lg sm:text-2xl font-medium font-serif" + className="text-2xl font-medium font-serif" > {lastSubmittedQuery} @@ -390,7 +397,7 @@ export default function Home() { {messages.map((message, index) => (
{message.role === 'assistant' && message.content && ( - +

Answer

@@ -428,18 +435,16 @@ export default function Home() { value={input} onChange={(e) => setInput(e.target.value)} disabled={isLoading} - className="w-full h-10 py-3 px-4 bg-gray-100 rounded-full pr-12 focus:outline-none focus:ring-2 focus:ring-green-500 text-sm" + className="w-full min-h-12 py-3 px-4 bg-muted border border-input rounded-full pr-12 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 text-sm sm:text-base" />