Spaces:
Paused
Paused
Download src/lib/server/textGeneration/utils/toolPrompt.ts from Mike0021/chat-ui-agent-demo: direct link, hf CLI and curl.
- Browser
- Download file 3.32 kB
-
https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/server/textGeneration/utils/toolPrompt.ts
- Command line
-
hf download hf://spaces/Mike0021/chat-ui-agent-demo/src/lib/server/textGeneration/utils/toolPrompt.ts
-
curl -L -o toolPrompt.ts https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/server/textGeneration/utils/toolPrompt.ts
3.32 kB
| import type { OpenAiTool } from "$lib/server/mcp/tools"; | |
| export function buildToolPreprompt(tools: OpenAiTool[], timezone?: string): string { | |
| if (!Array.isArray(tools) || tools.length === 0) return ""; | |
| const names = tools | |
| .map((t) => (t?.function?.name ? String(t.function.name) : "")) | |
| .filter((s) => s.length > 0); | |
| if (names.length === 0) return ""; | |
| const now = new Date(); | |
| const dateTimeOptions: Intl.DateTimeFormatOptions = { | |
| year: "numeric", | |
| month: "long", | |
| day: "numeric", | |
| weekday: "long", | |
| hour: "2-digit", | |
| minute: "2-digit", | |
| ...(timezone ? { timeZone: timezone } : {}), | |
| }; | |
| const currentDateTime = now.toLocaleString("en-US", dateTimeOptions); | |
| const isoDate = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`; | |
| const locationLine = timezone ? ` User's timezone: ${timezone}.` : ""; | |
| return [ | |
| `You have access to these tools: ${names.join(", ")}.`, | |
| `Current date and time: ${currentDateTime} (${isoDate}).${locationLine}`, | |
| `IMPORTANT: Do NOT call a tool unless the user's request requires capabilities you lack (e.g., real-time data, image generation, code execution) or external information you do not have. For tasks like writing code, creative writing, math, or building apps, respond directly without tools. When in doubt, do not use a tool.`, | |
| `PARALLEL TOOL CALLS: When multiple tool calls are needed and they are independent of each other (i.e., one does not need the result of another), call them all at once in a single response instead of one at a time. Only chain tool calls sequentially when a later call depends on an earlier call's output.`, | |
| `SEARCH: Use 3-6 precise keywords. For historical events, include the year the event occurred. For recent or current topics, use today's year (${now.getFullYear()}). When a tool accepts date-range parameters (e.g., startPublishedDate, endPublishedDate), always use today's date (${isoDate}) as the end date unless the user specifies otherwise. For multi-part questions, search each part separately. If the results only partially cover the question, run a follow-up search or crawl the most relevant result URL instead of answering from memory.`, | |
| `GROUNDING: When you answer from tool results, the results are your only source of facts. Do not supplement them with specifics from your own knowledge — details not present in the results are likely wrong, even when they sound plausible. If a fact is missing, search again or say you could not verify it. Attribute key facts to their sources with markdown links to the result URLs. If results conflict, say so. Never fabricate URLs, citations, or facts.`, | |
| `INTERACTIVE APPS: When asked to build an interactive application, game, or visualization without a specific language/framework preference, create a single self-contained HTML file with embedded CSS and JavaScript.`, | |
| `If a tool generates an image, you can inline it directly: .`, | |
| `If a tool needs an image, set its image field ("input_image", "image", or "image_url") to a reference like "image_1", "image_2", etc. (ordered by when the user uploaded them).`, | |
| `Default to image references; only use a full http(s) URL when the tool description explicitly asks for one, or reuse a URL a previous tool returned.`, | |
| ].join(" "); | |
| } | |