From 24f861340930accc1cda00932da06ba9313df5bb Mon Sep 17 00:00:00 2001 From: zaidmukaddam Date: Wed, 7 Aug 2024 19:40:41 +0530 Subject: [PATCH] chore: Complete Animations and fix system prompt for Claude --- app/api/chat/route.ts | 6 +++- app/page.tsx | 80 ++++++++++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 24 deletions(-) diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index 0513c37..5b82945 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -23,6 +23,7 @@ export async function POST(req: Request) { system: "You are an AI web search engine that helps users find information on the internet." + "You use the 'web_search' tool to search for information on the internet." + + "Always call the 'web_search' tool to get the information, no need to do a chain of thought or say anything else, go straight to the point." + "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." + @@ -36,7 +37,7 @@ export async function POST(req: Request) { }) .replace(/(\w+), (\w+) (\d+), (\d+)/, "$4-$2-$3 ($1)") + "Never use the heading format in your response!." + - "You always have to call the 'web_search' tool to get the information, no need to do a chain of thoughts.", + "Refrain from saying things like 'Certainly! I'll search for information about OpenAI GPT-4o mini using the web search tool.'", tools: { web_search: { description: 'Search the web for information with the given query, max results and search depth.', @@ -82,6 +83,9 @@ export async function POST(req: Request) { } } }, + }, + onFinish: async (event) => { + console.log(event.text); } }); diff --git a/app/page.tsx b/app/page.tsx index c1108c0..ad15c44 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -32,6 +32,7 @@ export default function Home() { const inputRef = useRef(null); const [lastSubmittedQuery, setLastSubmittedQuery] = useState(""); const [hasSubmitted, setHasSubmitted] = useState(false); + const [isAnimating, setIsAnimating] = useState(false); const bottomRef = useRef(null); const [showToolResults, setShowToolResults] = useState<{ [key: number]: boolean }>({}); const [isModelSelectorOpen, setIsModelSelectorOpen] = useState(false); @@ -55,8 +56,6 @@ export default function Home() { { name: 'Quality (Claude)', description: 'High quality generation.', details: '(Anthropic/Claude-3.5-Sonnet)', icon: Sparkles }, ]; - - const renderToolInvocation = (toolInvocation: ToolInvocation, index: number) => { const args = JSON.parse(JSON.stringify(toolInvocation.args)); const result = 'result' in toolInvocation ? JSON.parse(JSON.stringify(toolInvocation.result)) : null; @@ -148,6 +147,9 @@ export default function Home() { .replace(boldRegex, '$1') .replace(italicRegex, '$1'); + // Remove double new lines + content = content.replace("\n\n", "") + // Replace unordered and ordered lists content = content .replace(unorderedListRegex, '
  • $1
  • ') @@ -227,6 +229,7 @@ export default function Home() { setLastSubmittedQuery(input.trim()); handleSubmit(e); setHasSubmitted(true); + setIsAnimating(true); setShowToolResults({}); } else { toast.error("Please enter a search query."); @@ -355,28 +358,54 @@ export default function Home() { animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: 50 }} transition={{ duration: 0.5 }} - className="flex items-center space-x-2 mb-4" + onAnimationComplete={() => setIsAnimating(false)} > -

    {lastSubmittedQuery}

    - - {selectedModel === 'Speed' && } - {selectedModel === 'Quality (GPT)' && } - {selectedModel === 'Quality (Claude)' && } - {selectedModel} - +
    + + {lastSubmittedQuery} + + + + {selectedModel === 'Speed' && } + {selectedModel === 'Quality (GPT)' && } + {selectedModel === 'Quality (Claude)' && } + {selectedModel} + + +
    )} - {messages.length > 0 && ( -
    + + {messages.map((message, index) => ( - + {message.role === 'assistant' && message.content && ( - +

    Answer

    @@ -386,19 +415,24 @@ export default function Home() { )} {message.toolInvocations?.map((toolInvocation: ToolInvocation, toolIndex: number) => ( - + {renderToolInvocation(toolInvocation, toolIndex)} - + ))} - + ))}
    -
    - )} + +
    - {hasSubmitted && ( + {hasSubmitted && !isAnimating && (