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

Allow adding variant via prompttemplate files #14509

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ export class FrontendPromptCustomizationServiceImpl implements PromptCustomizati
return this.templates.get(id);
}

getCustomPromptTemplateIDs(): string[] {
return Array.from(this.templates.keys());
}

async editTemplate(id: string, defaultContent?: string): Promise<void> {
const editorUri = await this.getTemplateURI(id);
if (! await this.fileService.exists(editorUri)) {
Expand Down
12 changes: 11 additions & 1 deletion packages/ai-core/src/common/prompt-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export interface PromptCustomizationService {
*/
getCustomizedPromptTemplate(id: string): string | undefined

getCustomPromptTemplateIDs(): string[];
/**
* Edit the template. If the content is specified, is will be
* used to customize the template. Otherwise, the behavior depends
Expand Down Expand Up @@ -314,9 +315,18 @@ export class PromptServiceImpl implements PromptService {
delete this._prompts[id];
}
getVariantIds(id: string): string[] {
return Object.values(this._prompts)
const allCustomPromptTemplateIds = this.customizationService?.getCustomPromptTemplateIDs() || [];
const knownPromptIds = Object.keys(this._prompts);

// We filter out known IDs from the custom prompt template IDs, these are no variants, but customizations. Then we retain IDs that start with the main ID
const customVariantIds = allCustomPromptTemplateIds.filter(customId =>
!knownPromptIds.includes(customId) && customId.startsWith(id)
);
const variantIds = Object.values(this._prompts)
.filter(prompt => prompt.variantOf === id)
.map(variant => variant.id);

return [...variantIds, ...customVariantIds];
}
storePromptTemplate(promptTemplate: PromptTemplate): void {
this._prompts[promptTemplate.id] = promptTemplate;
Expand Down
Loading