Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Added currentDate variable to Dynamic Prompt (#1648)
Browse files* Added ability to include the current date in the assistant dynamic prompt
* feat: rename tag to {{today}}
---------
Co-authored-by: Nathan Sarrazin <[email protected]>
src/lib/components/AssistantSettings.svelte
CHANGED
|
@@ -96,7 +96,7 @@
|
|
| 96 |
: false;
|
| 97 |
|
| 98 |
let tools = assistant?.tools ?? [];
|
| 99 |
-
const regex = /{{\s?(get|post|url)
|
| 100 |
|
| 101 |
$: templateVariables = [...systemPrompt.matchAll(regex)];
|
| 102 |
$: selectedModel = models.find((m) => m.id === modelId);
|
|
@@ -565,7 +565,8 @@
|
|
| 565 |
<p class="mb-2 text-xs font-normal text-gray-500">
|
| 566 |
Allow the use of template variables {"{{get=https://example.com/path}}"}
|
| 567 |
to insert dynamic content into your prompt by making GET requests to specified URLs on each
|
| 568 |
-
inference. You can also send the user's message as the body of a POST request, using {"{{post=https://example.com/path}}"}
|
|
|
|
| 569 |
</p>
|
| 570 |
</label>
|
| 571 |
|
|
|
|
| 96 |
: false;
|
| 97 |
|
| 98 |
let tools = assistant?.tools ?? [];
|
| 99 |
+
const regex = /{{\s?(get|post|url|today)(=.*?)?\s?}}/g;
|
| 100 |
|
| 101 |
$: templateVariables = [...systemPrompt.matchAll(regex)];
|
| 102 |
$: selectedModel = models.find((m) => m.id === modelId);
|
|
|
|
| 565 |
<p class="mb-2 text-xs font-normal text-gray-500">
|
| 566 |
Allow the use of template variables {"{{get=https://example.com/path}}"}
|
| 567 |
to insert dynamic content into your prompt by making GET requests to specified URLs on each
|
| 568 |
+
inference. You can also send the user's message as the body of a POST request, using {"{{post=https://example.com/path}}"}.
|
| 569 |
+
Use {"{{today}}"} to include the current date.
|
| 570 |
</p>
|
| 571 |
</label>
|
| 572 |
|
src/lib/server/textGeneration/assistant.ts
CHANGED
|
@@ -5,6 +5,14 @@ import type { Assistant } from "$lib/types/Assistant";
|
|
| 5 |
import type { ObjectId } from "mongodb";
|
| 6 |
|
| 7 |
export async function processPreprompt(preprompt: string, user_message: string | undefined) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
const requestRegex = /{{\s?(get|post|url)=(.*?)\s?}}/g;
|
| 9 |
|
| 10 |
for (const match of preprompt.matchAll(requestRegex)) {
|
|
|
|
| 5 |
import type { ObjectId } from "mongodb";
|
| 6 |
|
| 7 |
export async function processPreprompt(preprompt: string, user_message: string | undefined) {
|
| 8 |
+
// Replace {{today}} with formatted date
|
| 9 |
+
const today = new Intl.DateTimeFormat("en-US", {
|
| 10 |
+
weekday: "long",
|
| 11 |
+
day: "numeric",
|
| 12 |
+
month: "long",
|
| 13 |
+
year: "numeric",
|
| 14 |
+
}).format(new Date());
|
| 15 |
+
preprompt = preprompt.replaceAll("{{today}}", today);
|
| 16 |
const requestRegex = /{{\s?(get|post|url)=(.*?)\s?}}/g;
|
| 17 |
|
| 18 |
for (const match of preprompt.matchAll(requestRegex)) {
|
src/routes/settings/(nav)/assistants/[assistantId]/+page.svelte
CHANGED
|
@@ -259,7 +259,7 @@
|
|
| 259 |
>
|
| 260 |
{#if assistant?.dynamicPrompt}
|
| 261 |
{#each prepromptTags as tag}
|
| 262 |
-
{#if tag.startsWith("{{") && tag.endsWith("}}") && (tag.includes("get=") || tag.includes("post=") || tag.includes("url="))}
|
| 263 |
{@const url = tag.match(/(?:get|post|url)=(.*?)}}/)?.[1] ?? ""}
|
| 264 |
<a
|
| 265 |
target="_blank"
|
|
|
|
| 259 |
>
|
| 260 |
{#if assistant?.dynamicPrompt}
|
| 261 |
{#each prepromptTags as tag}
|
| 262 |
+
{#if (tag.startsWith("{{") && tag.endsWith("}}") && (tag.includes("get=") || tag.includes("post=") || tag.includes("url="))) || tag.includes("today")}
|
| 263 |
{@const url = tag.match(/(?:get|post|url)=(.*?)}}/)?.[1] ?? ""}
|
| 264 |
<a
|
| 265 |
target="_blank"
|