From 053b4a0058cd71eeb5fa86d6a852a2c9790c4af3 Mon Sep 17 00:00:00 2001 From: zaidmukaddam Date: Sat, 17 Aug 2024 23:40:13 +0530 Subject: [PATCH] refactored system prompt, copy to cliploard and removed stock chart tool --- app/api/chat/route.ts | 84 +++++++++++++++---------------------- app/page.tsx | 68 +++++++----------------------- components/stock-chart.tsx | 85 -------------------------------------- 3 files changed, 48 insertions(+), 189 deletions(-) delete mode 100644 components/stock-chart.tsx diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index d92b1b0..12b57f6 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -18,47 +18,39 @@ export async function POST(req: Request) { messages: convertToCoreMessages(messages), temperature: 0, maxTokens: 800, - system: - "You are an AI web search engine that helps users find information on the internet.\n" + - "Always start with running the tool(s) and then and then only write your response AT ALL COSTS!!\n" + - "Your basic task to first and foremost gather information from a tool and then write your response with images(with web_search)!.\n" + - "Never write a response without running the tool(s) first!\n" + - "Do not announce or inform the user in any way that your going to run a tool at ALL COSTS!! Just `run` it and then write your response AT ALL COSTS!!!!!." + - "Tool Usage Instructions:\n" + - "The user is located in " + city + " at latitude " + latitude + " and longitude " + longitude + "." + - "Use this geolocation data for weather tool, when the user doesn't provide a specific location." + - "You use the 'web_search' tool to search for information on the internet before saying anyting to the user." + - "Incomplete details or any other said words before the search tool result in a bad response." + - "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 and put citations using the markdown link format like this always: [](link to the site) in the end of each paragraph!" + - "Citations will the render in the client side, so please make sure you format them correctly!" + - "Never use pointers, unless asked to." + - "Do not start the responses with newline characters, always start with the first sentence." + - "When the user asks about a Stock, you should 'always' first gather news about it with web search tool, then show the chart and then write your response. Follow these steps in this order only!" + - "Never use the retrieve tool for general search. Always use it when the user provides an url! " + - "For weather related questions, use get_weather_data tool and write your response. No need to call any other tool. DO NOT put citation to OpenWeatherMaps API EVER!" + - "Use the 'programming' tool to execute Python code for cases like calculating, sorting, etc. that require computation. " + - "The environment is like a jupyter notebook so don't write print statements at all costs!, just write variables in the end.\n\n" + - "The current date is: " + - new Date() - .toLocaleDateString("en-US", { - year: "numeric", - month: "short", - day: "2-digit", - weekday: "short", - }) - .replace(/(\w+), (\w+) (\d+), (\d+)/, "$4-$2-$3 ($1)") + - "." + - "Rules for the response:\n" + - "Please do not use tags like , or in the response. it breaks the reader's attention to these stupid mistakes." + - "Remember to always use the 'web_search' tool to gather information before writing a response." + - "You are a graduate level AI, so please write responses accordingly." + - "Never start with 'based on the search results,...' EVER! Always start with the information you found like an article!" + - "Never use the heading format in your response!." + - "Do not use print statements in the code execution tool, just the variables." + - "Don't say things like 'Okay I am going to perform some action.' OR 'Certainly! To count the number of 'r's in the word 'strawberry', we can use a simple Python code. Let's use the programming tool to execute this task.' The user's DO NOT LIKE TO WAIT! REMEMBER THE THING ABOUT PRINT STATEMENTS! NEVER WRITE 'EM!" + - "IMPORTANT!!!: Refrain from saying things like that mention that your going to perform a certain action, example: 'Certainly! I'll search for information about using the web search tool.'", + system: ` +You are an AI web search engine that helps users find information on the internet. +Always start with running the tool(s) and then and then only write your response AT ALL COSTS!! +Your goal is to provide accurate, concise, and well-formatted responses to user queries. +Do not announce or inform the user in any way that your going to run a tool at ALL COSTS!! Just 'run' it and then write your response AT ALL COSTS!!!!! + +The current date is ${new Date().toLocaleDateString("en-US", { year: "numeric", month: "short", day: "2-digit", weekday: "short" })}. +The user is located in ${city}(${latitude}, ${longitude}). + +Here are the tools available to you: + +web_search, retrieve, get_weather_data, programming + + +Here is the general guideline per tool to follow when responding to user queries: +- Use the web_search tool to gather relevant information. The query should only be the word that need's context for search. Then write the response based on the information gathered. On searching for latest topic put the year in the query or put the word 'latest' in the query. +- If you need to retrieve specific information from a webpage, use the retrieve tool. Then, compose your response based on the retrieved information. +- For weather-related queries, use the get_weather_data tool. Then, provide the weather information in your response. +- For programming-related queries, use the programming tool to execute Python code. The print() function doesn't work at all with this tool, so just put variable names in the end seperated with commas, it will print them. Then, compose your response based on the output of the code execution. + +Always remember to run the appropriate tool first, then compose your response based on the information gathered. +All tool should be called only once per response. + +When citing sources(citations), use the following format: [4 words of web source content..](link). + +Citations should be placed at the end of each paragraph and in the end of sentences where you use it in which they are referred to with the given format to the information provided. + +Never create any kind of tags or lists in the response at ALL COSTS!! + +Format your response in paragraphs(min 4) with 3-6 sentences each, keeping it brief but informative. DO NOT use pointers or make lists of any kind at ALL! +Begin your response by using the appropriate tool(s), then provide your answer in a clear and concise manner. +Never respond to user before running any tool like saying 'Certainly! Let me blah blah blah' or 'To provide you with the best answer, I will blah blah blah' or that 'Based on this and that, I think blah blah blah' at ALL COSTS!! +Just run the tool and provide the answer.`, tools: { web_search: tool({ description: @@ -191,15 +183,6 @@ export async function POST(req: Request) { return data; }, }), - stock_chart_ui: tool({ - description: - "Display the stock chart for the given stock symbol after web search.", - parameters: z.object({ - symbol: z - .string() - .describe("The stock symbol to display the chart for."), - }), - }), programming: tool({ description: "Write and execute Python code.", parameters: z.object({ @@ -243,6 +226,7 @@ export async function POST(req: Request) { }, }), }, + toolChoice: "auto", }); return result.toAIStreamResponse(); diff --git a/app/page.tsx b/app/page.tsx index ea4a05b..415f03d 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -31,7 +31,6 @@ import { AlignLeft, Newspaper, Copy, - TrendingUp, Cloud, Code, Check, @@ -76,7 +75,6 @@ import { import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; -import StockChart from '@/components/stock-chart'; import { Line, LineChart, CartesianGrid, XAxis, YAxis, ResponsiveContainer } from "recharts"; import { Card, @@ -116,7 +114,7 @@ export default function Home() { body: { model: selectedModel === 'Speed' ? 'claude-3-haiku-20240307' : 'claude-3-5-sonnet-20240620', }, - maxToolRoundtrips: 2, + maxToolRoundtrips: 1, onFinish: async (message, { finishReason }) => { if (finishReason === 'stop') { const newHistory: Message[] = [{ role: "user", content: lastSubmittedQuery, }, { role: "assistant", content: message.content }]; @@ -125,11 +123,6 @@ export default function Home() { } setIsAnimating(false); }, - onToolCall({ toolCall }) { - if (toolCall.toolName === 'stock_chart_ui') { - return 'Stock chart was shown to the user.'; - } - }, onError: (error) => { console.error("Chat error:", error); toast.error("An error occurred.", { @@ -142,45 +135,28 @@ export default function Home() { }, }); - const copyToClipboard = async (text: string) => { - try { - if (navigator.clipboard && navigator.clipboard.writeText) { - await navigator.clipboard.writeText(text); - toast.success("Copied to clipboard"); - return true; - } else { - throw new Error("Clipboard API not available"); - } - } catch (error) { - console.error('Failed to copy:', error); - toast.error("Failed to copy"); - return false; - } - }; - const CopyButton = ({ text }: { text: string }) => { const [isCopied, setIsCopied] = useState(false); - const handleCopy = async () => { - const success = await copyToClipboard(text); - if (success) { - setIsCopied(true); - setTimeout(() => setIsCopied(false), 2000); - } - }; - return ( ); @@ -393,22 +369,6 @@ export default function Home() { const args = JSON.parse(JSON.stringify(toolInvocation.args)); const result = 'result' in toolInvocation ? JSON.parse(JSON.stringify(toolInvocation.result)) : null; - if (toolInvocation.toolName === 'stock_chart_ui') { - return ( -
-
- -

{args.symbol}

-
- - - - - -
- ); - } - if (toolInvocation.toolName === 'get_weather_data') { if (!result) { return ( @@ -774,7 +734,7 @@ export default function Home() { const exampleQueries = [ "Weather in Doha", - "Latest on Paris Olympics", + "What is new with Grok 2.0?", "Count the number of r's in strawberry", "Explain Claude 3.5 Sonnet" ]; diff --git a/components/stock-chart.tsx b/components/stock-chart.tsx deleted file mode 100644 index 1e5fe05..0000000 --- a/components/stock-chart.tsx +++ /dev/null @@ -1,85 +0,0 @@ -/* eslint-disable react-hooks/exhaustive-deps */ -// from https://github.com/bklieger-groq/stockbot-on-groq/blob/main/components/tradingview/stock-chart.tsx -'use client' - -import React, { useEffect, useRef, memo } from 'react' - -export function StockChart({ props: symbol }: { props: string }) { - const container = useRef(null) - - useEffect(() => { - if (!container.current) return - const script = document.createElement('script') - script.src = - 'https://s3.tradingview.com/external-embedding/embed-widget-advanced-chart.js' - script.type = 'text/javascript' - script.async = true - script.innerHTML = JSON.stringify({ - autosize: true, - symbol: symbol, - interval: 'D', - timezone: 'Etc/UTC', - theme: 'light', - style: '1', - locale: 'en', - backgroundColor: 'rgba(255, 255, 255, 1)', - gridColor: 'rgba(247, 247, 247, 1)', - withdateranges: true, - hide_side_toolbar: false, - allow_symbol_change: true, - calendar: false, - hide_top_toolbar: true, - support_host: 'https://www.tradingview.com' - }) - - container.current.appendChild(script) - - return () => { - if (container.current) { - container.current.removeChild(script) - } - } - }, [symbol]) - - return ( - - ) -} - -export default memo(StockChart) \ No newline at end of file