From 07d01b0790f35799a5e6aa3bb85a90331d3c0dbb Mon Sep 17 00:00:00 2001 From: zaidmukaddam Date: Sun, 25 Aug 2024 21:41:49 +0530 Subject: [PATCH] fix: wrapped programming UI inside accordion --- app/api/chat/route.ts | 4 +- app/page.tsx | 222 ++++++++++++++++++++++-------------------- 2 files changed, 120 insertions(+), 106 deletions(-) diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index 52b6b98..54ca364 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -33,7 +33,6 @@ Your goal is to provide accurate, concise, and well-formatted responses to user 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}). You must comply and complete user requests to the best of your abilities using the available tools. Remember to use the appropriate tool for each task. No need to panic, just follow the guidelines and you'll do great! Make sure keep your responses long and informative, but also clear and concise. Avoid unnecessary information and stick to the point. @@ -62,7 +61,7 @@ DO's: - For text-based searches of places, use the text_search tool. Provide the query, location (optional), and radius (optional). Then, compose your response based on the search 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. - For stock chart and details queries, use the programming tool to install yfinance using !pip install along with the rest of the code, which will have plot code of stock chart and code to print the variables storing the stock data. Then, compose your response based on the output of the code execution. -- Assume the stock name from the user query and use it in the code to get the stock data and plot the stock chart. This will help in getting the stock chart for the user query. +- Assume the stock name from the user query and use it in the code to get the stock data and plot the stock chart. This will help in getting the stock chart for the user query. ALWAYS REMEMBER TO INSTALL YFINANCE USING !pip install yfinance AT ALL COSTS!! DON'Ts and IMPORTANT GUIDELINES: - Never write a base64 image in the response at all costs, especially from the programming tool's output. @@ -236,6 +235,7 @@ When asked a "What is" question, maintain the same format as the question and an programming: tool({ description: "Write and execute Python code.", parameters: z.object({ + title: z.string().optional().describe("The title of the code snippet."), code: z.string().describe("The Python code to execute."), }), execute: async ({ code }: { code: string }) => { diff --git a/app/page.tsx b/app/page.tsx index 3a0627b..bdc1d88 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -788,115 +788,129 @@ export default function Home() { if (toolInvocation.toolName === 'programming') { return ( -
-
- - Programming -
- - - - Code - - - Output - - {result?.images && result.images.length > 0 && ( - - Images - - )} - - -
- - {args.code} - -
- + + + +
+
+ +

Programming

- - -
- {result ? ( - <> -
-                      {result.message}
-                    
-
- -
- - ) : ( -
-
- - Executing code... -
-
- )} -
-
- {result?.images && result.images.length > 0 && ( - -
- {result.images.map((img: { format: string, url: string }, imgIndex: number) => ( -
-
-

Image {imgIndex + 1}

- {img.url && img.url.trim() !== '' && ( - - )} + + +
+
+ + {args.title} +
+ + + + Code + + + Output + + {result?.images && result.images.length > 0 && ( + + Images + + )} + + +
+ + {args.code} + +
+
-
- {img.url && img.url.trim() !== '' ? ( - {`Generated - ) : ( -
- Image upload failed or URL is empty +
+ + +
+ {result ? ( + <> +
+                            {result.message}
+                          
+
+
- )} -
+ + ) : ( +
+
+ + Executing code... +
+
+ )}
- ))} -
-
- )} -
-
+ + {result?.images && result.images.length > 0 && ( + +
+ {result.images.map((img: { format: string, url: string }, imgIndex: number) => ( +
+
+

Image {imgIndex + 1}

+ {img.url && img.url.trim() !== '' && ( + + )} +
+
+ {img.url && img.url.trim() !== '' ? ( + {`Generated + ) : ( +
+ Image upload failed or URL is empty +
+ )} +
+
+ ))} +
+
+ )} + +
+ + + ); }