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

feat(js/ai/prompt): added prepare fn option to definePrompt #1779

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented Feb 1, 2025

(from discord)

const kbRetriever = defineFirestoreRetriever(const retriever = defineFirestoreRetriever(ai, {
  name: 'exampleRetriever',
  firestore,
});

const ragPrompt = ai.definePrompt({
  prepare: async (input, {context}) => ({
    context: {...context, userInfo: await fetchUserInfo(context.auth.uid)},
    docs: await kbRetriever({query: input.query}),
  })
})

Checklist (if applicable):

@pavelgj pavelgj requested a review from mbleigh February 1, 2025 15:01
@pavelgj pavelgj changed the title feat(js/ai/prompt): added prepare fn option feat(js/ai/prompt): added prepare fn option to definePrompt Feb 1, 2025
Comment on lines +213 to +214
* A function that can be passes to the prompt that can produce additional propmpt render options
* like context, docs, or any other propmpt option really:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* A function that can be passes to the prompt that can produce additional propmpt render options
* like context, docs, or any other propmpt option really:
* A function that can validate, fetch, and populate additional information necessary for the prompt to execute.
* The `prepare` function can be used to retrieve documents, add personalized user information to the context,
* or generally perform any other work necessary to configure the prompt based on runtime input.

@@ -125,6 +125,7 @@ export interface PromptConfig<
toolChoice?: ToolChoice;
use?: ModelMiddleware[];
context?: ActionContext;
prepare?: PromptPrepare<I, O, CustomOptions>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should mark this with @beta in docs and add an assertUnstable to the code that handles it. The main concern I have about marking this stable is that I wonder if it should be allowed to manipulate the input, not just context, and that would cause weirdness with types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants