Skip to content

Commit c2163af

Browse files
committed
fix: render n prompt metadata along with generateoptions
1 parent a0f812a commit c2163af

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

js/ai/src/generate.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ export interface GenerateOptions<
170170
context?: ActionContext;
171171
/** Abort signal for the generate request. */
172172
abortSignal?: AbortSignal;
173+
/**
174+
* Additional metadata describing the GenerateOptions, used by tooling. If
175+
* this is an instance of a rendered dotprompt, will contain any prompt
176+
* metadata contained in the original frontmatter.
177+
**/
178+
metadata?: Record<string, any>;
173179
}
174180

175181
export async function toGenerateRequest(

js/ai/src/prompt.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ function definePromptAsync<
330330
...resolvedOptions?.config,
331331
...renderOptions?.config,
332332
},
333+
metadata: resolvedOptions.metadata?.metadata
334+
? {
335+
prompt: resolvedOptions.metadata?.metadata,
336+
}
337+
: undefined,
333338
});
334339
// if config is empty and it was not explicitly passed in, we delete it, don't want {}
335340
if (Object.keys(opts.config).length === 0 && !renderOptions?.config) {
@@ -842,6 +847,7 @@ function loadPrompt(
842847
...promptMetadata,
843848
template: parsedPrompt.template,
844849
},
850+
metadata: { ...promptMetadata.raw?.['metadata'] },
845851
},
846852
maxTurns: promptMetadata.raw?.['maxTurns'],
847853
toolChoice: promptMetadata.raw?.['toolChoice'],

0 commit comments

Comments
 (0)