mirror of
https://github.com/aljazceru/goose.git
synced 2026-01-10 01:44:27 +01:00
Prompt Library (#1906)
This commit is contained in:
6
documentation/src/utils/cn.ts
Normal file
6
documentation/src/utils/cn.ts
Normal 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));
|
||||
}
|
||||
36
documentation/src/utils/prompts.ts
Normal file
36
documentation/src/utils/prompts.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user