Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a markdown pre-processor for templating prompts at runtime #10

Merged
merged 5 commits into from
Feb 28, 2024

Conversation

extremeheat
Copy link
Owner

@extremeheat extremeheat commented Feb 28, 2024

Add a templating system, which is described in doc (and now used internally for Google AI Studio Playground chat handling).

To insert variables, you use %%%(VARIABLE_NAME)%%%. To insert a string based on a specific condition, you use %%%[...] if CONDITION%%% or with an else clause, %%%[...] if BOOLEAN_VAR else [...]%%%. Note that the square brackets work like quotation mark strings in programming languages, so you can escape them with a backslash, like \].

There are also if statements, which can be used to conditionally include or exclude parts of the markdown.

For example, the line:

Your name is %%%(NAME)%%%, and you answer questions for the user%%%[, based on your prompt] if HAS_PROMPT%%%.
You are running over %%%[the Google AI Studio playground] if IS_AI_STUDIO else [the %%%(LLM_NAME)%%% API]%%%.

Would be loaded in JS like this:

const { importPromptSync } = require('langxlang')
const prompt = importPromptSync('path-to-prompt.md', { NAME: 'Omega', HAS_PROMPT: true, IS_AI_STUDIO: false, LLM_NAME: 'Gemini 1.5 Pro' })

And would result in:

Your name is Omega, and you answer questions for the user, based on your prompt.
You are running over the Gemini 1.5 Pro API.

@extremeheat extremeheat merged commit 382d5c3 into main Feb 28, 2024
1 check passed
@extremeheat extremeheat deleted the mdp branch February 28, 2024 23:35
@extremeheat
Copy link
Owner Author

/makerelease

@github-actions github-actions bot mentioned this pull request Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant