Too many tokens used in input #7956
Closed
mazierovictor
started this conversation in
General
Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
-
Enabling artifacts adds instructions, unless you use "Prompt Personalizado" where you can explain how to use artifacts yourself: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've been analyzing the logs of a simple Hello using an agent, it consumed 5,619 tokens.
Below is the log from the OpenAI API platform.
system
Your artifact content here
::: a. Example of correct format: :::artifact{identifier="example-artifact" type="text/plain" title="Example Artifact"}This is the content of the artifact. It can span multiple lines.
::: b. Common mistakes to avoid: - Don't split the opening ::: line - Don't add extra backticks outside the artifact structure - Don't omit the closing ::: 2. Assign an identifier to theidentifier
attribute. For updates, reuse the prior identifier. For new artifacts, the identifier should be descriptive and relevant to the content, using kebab-case (e.g., "example-code-snippet"). This identifier will be used consistently throughout the artifact's lifecycle, even when updating or iterating on the artifact. 3. Include atitle
attribute to provide a brief title or description of the content. 4. Add atype
attribute to specify the type of content the artifact represents. Assign one of the following values to thetype
attribute: - HTML: "text/html" - The user interface can render single file HTML pages placed within the artifact tags. HTML, JS, and CSS should be in a single file when using thetext/html
type. - Images from the web are not allowed, but you can use placeholder images by specifying the width and height like so<img src="/api/placeholder/400/320" alt="placeholder" />
- The only place external scripts can be imported from is https://cdnjs.cloudflare.com - SVG: "image/svg+xml" - The user interface will render the Scalable Vector Graphics (SVG) image within the artifact tags. - The assistant should specify the viewbox of the SVG rather than defining a width/height - Mermaid Diagrams: "application/vnd.mermaid" - The user interface will render Mermaid diagrams placed within the artifact tags. - React Components: "application/vnd.react" - Use this for displaying either: React elements, e.g.<strong>Hello World!</strong>
, React pure functional components, e.g.() => <strong>Hello World!</strong>
, React functional components with Hooks, or React component classes - When creating a React component, ensure it has no required props (or provide default values for all props) and use a default export. - Use Tailwind classes for styling. DO NOT USE ARBITRARY VALUES (e.g.h-[600px]
). - Base React is available to be imported. To use hooks, first import it at the top of the artifact, e.g.import { useState } from "react"
- The [email protected] library is available to be imported. e.g.import { Camera } from "lucide-react"
&<Camera color="red" size={48} />
- The recharts charting library is available to be imported, e.g.import { LineChart, XAxis, ... } from "recharts"
&<LineChart ...><XAxis dataKey="name"> ...
- The three.js library is available to be imported, e.g.import * as THREE from "three";
- The date-fns library is available to be imported, e.g.import { compareAsc, format } from "date-fns";
- The react-day-picker library is available to be imported, e.g.import { DayPicker } from "react-day-picker";
- The assistant can use prebuilt components from theshadcn/ui
library after it is imported:import { Alert, AlertDescription, AlertTitle, AlertDialog, AlertDialogAction } from '/components/ui/alert';
. If using components from the shadcn/ui library, the assistant mentions this to the user and offers to help them install the components if necessary. - Components MUST be imported from/components/ui/name
and NOT from/components/name
or@/components/ui/name
. - NO OTHER LIBRARIES (e.g. zod, hookform) ARE INSTALLED OR ABLE TO BE IMPORTED. - Images from the web are not allowed, but you can use placeholder images by specifying the width and height like so<img src="/api/placeholder/400/320" alt="placeholder" />
- When iterating on code, ensure that the code is complete and functional without any snippets, placeholders, or ellipses. - If you are unable to follow the above requirements for any reason, don't use artifacts and use regular code blocks instead, which will not attempt to render the component. 5. Include the complete and updated content of the artifact, without any truncation or minimization. Don't use "// rest of the code remains the same...". 6. If unsure whether the content qualifies as an artifact, if an artifact should be updated, or which type to assign to an artifact, err on the side of not creating an artifact. 7. NEVER use triple backticks to enclose the artifact, ONLY the content within the artifact. Here are some examples of correct usage of artifacts: ## Examples ### Example 1 This example demonstrates how to create a Mermaid artifact for a simple flow chart. User: Can you create a simple flow chart showing the process of making tea using Mermaid? Assistant: Sure! Here's a simple flow chart depicting the process of making tea using Mermaid syntax: :::artifact{identifier="tea-making-flowchart" type="application/vnd.mermaid" title="Flow chart: Making Tea"}mermaid graph TD A[Start] --> B{Water boiled?} B -->|Yes| C[Add tea leaves to cup] B -->|No| D[Boil water] D --> B C --> E[Pour boiling water into cup] E --> F[Steep tea for desired time] F --> G[Remove tea leaves] G --> H[Add milk or sugar, if desired] H --> I[Enjoy your tea!] I --> J[End]
::: This flow chart uses Mermaid syntax to visualize the steps involved in making a cup of tea. Here's a brief explanation of the process: 1. Start 2. Check if water is boiled 3. If not boiled, boil the water 4. Once water is boiled, add tea leaves to the cup 5. Pour boiling water into the cup 6. Steep the tea for the desired time 7. Remove the tea leaves 8. Optionally add milk or sugar 9. Enjoy your tea! 10. End This chart provides a clear visual representation of the tea-making process. You can easily modify or expand this chart if you want to add more details or steps to the process. Let me know if you'd like any changes or have any questions! --- ### Example 2 User: Create a simple React counter component Assistant: Here's a simple React counter component: :::artifact{identifier="react-counter" type="application/vnd.react" title="React Counter"}import { useState } from 'react'; export default function Counter() { const [count, setCount] = useState(0); return ( <div className="p-4"> <p className="mb-2">Count: {count}</p> <button className="bg-blue-500 text-white px-4 py-2 rounded" onClick={() => setCount(count + 1)}> Increment </button> </div> ); }
::: This component creates a simple counter with an increment button. --- ### Example 3 User: Create a basic HTML structure for a blog post Assistant: Here's a basic HTML structure for a blog post: :::artifact{identifier="blog-post-html" type="text/html" title="Blog Post HTML"}<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Blog Post</title> <style> body { font-family: Arial, sans-serif; line-height: 1.6; max-width: 800px; margin: 0 auto; padding: 20px; } h1 { color: #333; } p { margin-bottom: 15px; } </style> </head> <body> <header> <h1>My First Blog Post</h1> </header> <main> <article> <p>This is the content of my blog post. It's short and sweet!</p> </article> </main> <footer> <p>© 2023 My Blog</p> </footer> </body> </html>
::: This HTML structure provides a simple layout for a blog post. ---## Additional Artifact Instructions for React Components: "application/vnd.react" There are some prestyled components (primitives) available for use. Please use your best judgement to use any of these components if the app calls for one. Here are the components that are available, along with how to import them, and how to use them: # Avatar ## Import Instructions import { Avatar, AvatarFallback, AvatarImage } from "/components/ui/avatar" ## Usage Instructions CN # Button ## Import Instructions import { Button } from "/components/ui/button" ## Usage Instructions Button # Card ## Import Instructions import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "/components/ui/card" ## Usage Instructions Card Title Card DescriptionCard Content
Card Footer
# Checkbox ## Import Instructions import { Checkbox } from "/components/ui/checkbox" ## Usage Instructions # Input ## Import Instructions import { Input } from "/components/ui/input" ## Usage Instructions # Label ## Import Instructions import { Label } from "/components/ui/label" ## Usage Instructions Your email address # RadioGroup ## Import Instructions import { Label } from "/components/ui/label" import { RadioGroup, RadioGroupItem } from "/components/ui/radio-group" ## Usage InstructionsAdd to library
user
Olá
Output
12t
assistant
Olá, Victor! Como posso ajudar você hoje? 😊
My question is, how can I reduce this absurd amount of tokens?
Beta Was this translation helpful? Give feedback.
All reactions