-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
168 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,62 @@ | ||
--- | ||
title: Prompt ($) | ||
sidebar: | ||
order: 2 | ||
description: Learn how to use the tagged template literal for dynamic prompt generation in GenAI scripts. | ||
keywords: tagged template, prompt expansion, dynamic prompts, JavaScript templates, GenAI scripting | ||
order: 2 | ||
description: Learn how to use the tagged template literal for dynamic prompt | ||
generation in GenAI scripts. | ||
keywords: tagged template, prompt expansion, dynamic prompts, JavaScript | ||
templates, GenAI scripting | ||
genaiscript: | ||
model: openai:gpt-3.5-turbo | ||
|
||
--- | ||
|
||
The `$` is a JavaScript [tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) that expands the string into the final prompt. | ||
|
||
```javascript title="example.genai.js" | ||
... | ||
```js title="example.genai.js" assistant=false user=true | ||
$`You are a helpful assistant.` | ||
``` | ||
|
||
```txt title="Final prompt" | ||
<!-- genaiscript output start --> | ||
|
||
<details open> | ||
<summary>👤 user</summary> | ||
|
||
|
||
```markdown wrap | ||
You are a helpful assistant. | ||
``` | ||
|
||
|
||
</details> | ||
|
||
<!-- genaiscript output end --> | ||
|
||
|
||
|
||
|
||
## Inline expressions | ||
|
||
You can weave expressions in the template using `${...}`. Expression can be promises and will be awaited when rendering the final prompt. | ||
|
||
```js title="example.genai.js" | ||
```js title="example.genai.js" assistant=false user=true | ||
$`Today is ${new Date().toDateString()}.` | ||
``` | ||
|
||
```txt title="Final prompt" | ||
Today is Fri Mar 01 2024. | ||
<!-- genaiscript output start --> | ||
|
||
<details open> | ||
<summary>👤 user</summary> | ||
|
||
|
||
```markdown wrap | ||
Today is Thu Jun 13 2024. | ||
``` | ||
|
||
|
||
</details> | ||
|
||
<!-- genaiscript output end --> | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters