Prompt Library (#1906)

This commit is contained in:
Rizel Scarlett
2025-03-31 07:29:37 -04:00
committed by GitHub
parent 326f087637
commit 54573e4a60
49 changed files with 2295 additions and 206 deletions

View File

@@ -0,0 +1,6 @@
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

View File

@@ -0,0 +1,36 @@
import type { Prompt } from '@site/src/types/prompt';
const promptContext = require.context(
'../pages/prompt-library/data/prompts',
false,
/\.json$/
);
// Convert the modules into an array of prompts
const prompts: Prompt[] = promptContext.keys().map((key) => {
const prompt = promptContext(key);
return prompt.default || prompt; // handle both ESM and CommonJS modules
});
export async function searchPrompts(query: string): Promise<Prompt[]> {
const searchTerms = query.toLowerCase().split(' ').filter(Boolean);
if (!searchTerms.length) {
return prompts;
}
return prompts.filter((prompt) => {
const searchableText = [
prompt.title,
prompt.description,
prompt.example_prompt,
...prompt.extensions.map(ext => ext.name)
].join(' ').toLowerCase();
return searchTerms.every(term => searchableText.includes(term));
});
}
export async function getPromptById(id: string): Promise<Prompt | null> {
return prompts.find(prompt => prompt.id === id) || null;
}