fix(prompts): Update prompts in prompts.csv and scripts.
This commit is contained in:
+1470
-281
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to generate contributor commits from prompts.csv
|
||||
# Fetches latest prompts from prompts.chat/prompts.csv
|
||||
# Rebuilds prompts.csv line-by-line, with each line committed by its contributor
|
||||
# This creates git history showing each contributor adding their prompt
|
||||
|
||||
set -e
|
||||
|
||||
@@ -10,15 +10,19 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
CSV_FILE="$PROJECT_DIR/prompts.csv"
|
||||
CSV_BACKUP="$PROJECT_DIR/prompts.csv.backup"
|
||||
REMOTE_CSV_URL="https://prompts.chat/prompts.csv"
|
||||
|
||||
if [ ! -f "$CSV_FILE" ]; then
|
||||
echo "Error: prompts.csv not found at $CSV_FILE"
|
||||
# Fetch latest prompts.csv from prompts.chat
|
||||
echo "Fetching latest prompts.csv from $REMOTE_CSV_URL..."
|
||||
if ! curl -fsSL "$REMOTE_CSV_URL" -o "$CSV_FILE"; then
|
||||
echo "Error: Failed to fetch prompts.csv from $REMOTE_CSV_URL"
|
||||
echo "Make sure prompts.chat is running and the endpoint is available."
|
||||
exit 1
|
||||
fi
|
||||
echo "Successfully fetched prompts.csv"
|
||||
|
||||
# Backup original file
|
||||
# Backup the fetched file
|
||||
cp "$CSV_FILE" "$CSV_BACKUP"
|
||||
echo "Backed up prompts.csv to prompts.csv.backup"
|
||||
|
||||
# Count total lines (excluding header)
|
||||
total=$(tail -n +2 "$CSV_BACKUP" | wc -l | tr -d ' ')
|
||||
@@ -27,7 +31,7 @@ echo "Found $total prompts to process"
|
||||
# Start fresh - write only header
|
||||
head -1 "$CSV_BACKUP" > "$CSV_FILE"
|
||||
git add "$CSV_FILE"
|
||||
git commit -m "Initialize prompts.csv with header" --allow-empty
|
||||
git commit -m "Initialize prompts.csv with header" --allow-empty 2>/dev/null || true
|
||||
|
||||
echo ""
|
||||
echo "Creating commits for each prompt line..."
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { db } from "@/lib/db";
|
||||
|
||||
function escapeCSVField(field: string): string {
|
||||
if (!field) return "";
|
||||
|
||||
const needsQuoting = /[,"\n\r]/.test(field) || field !== field.trim();
|
||||
|
||||
if (needsQuoting) {
|
||||
const escaped = field.replace(/"/g, '""');
|
||||
return `"${escaped}"`;
|
||||
}
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const prompts = await db.prompt.findMany({
|
||||
where: {
|
||||
isPrivate: false,
|
||||
deletedAt: null,
|
||||
},
|
||||
include: {
|
||||
category: {
|
||||
select: {
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
author: {
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: { createdAt: "asc" },
|
||||
});
|
||||
|
||||
const headers = ["act", "prompt", "for_devs", "type", "contributor"];
|
||||
const rows = prompts.map((prompt) => {
|
||||
const act = escapeCSVField(prompt.title);
|
||||
const promptContent = escapeCSVField(prompt.content);
|
||||
const forDevs = prompt.category?.slug === "coding" ? "TRUE" : "FALSE";
|
||||
const type = prompt.type;
|
||||
const contributor = escapeCSVField(prompt.author.username);
|
||||
|
||||
return [act, promptContent, forDevs, type, contributor].join(",");
|
||||
});
|
||||
|
||||
const csvContent = [headers.join(","), ...rows].join("\n");
|
||||
|
||||
return new NextResponse(csvContent, {
|
||||
headers: {
|
||||
"Content-Type": "text/csv; charset=utf-8",
|
||||
"Cache-Control": "public, max-age=3600",
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("prompts.csv error:", error);
|
||||
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { InfinitePromptList } from "@/components/prompts/infinite-prompt-list";
|
||||
import { PromptFilters } from "@/components/prompts/prompt-filters";
|
||||
import { db } from "@/lib/db";
|
||||
import { isAISearchEnabled, semanticSearch } from "@/lib/ai/embeddings";
|
||||
import config from "@/../prompts.config";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Prompts",
|
||||
@@ -171,12 +172,25 @@ export default async function PromptsPage({ searchParams }: PromptsPageProps) {
|
||||
<h1 className="text-lg font-semibold">{t("title")}</h1>
|
||||
<span className="text-xs text-muted-foreground">{tSearch("found", { count: total })}</span>
|
||||
</div>
|
||||
<Button size="sm" className="h-8 text-xs" asChild>
|
||||
<Link href="/prompts/new">
|
||||
<Plus className="h-3.5 w-3.5 mr-1" />
|
||||
{t("create")}
|
||||
</Link>
|
||||
</Button>
|
||||
<div className="flex items-center gap-2">
|
||||
{!config.homepage?.useCloneBranding && (
|
||||
<Button size="sm" variant="outline" className="h-8 text-xs" asChild>
|
||||
<a
|
||||
href="https://huggingface.co/datasets/fka/awesome-chatgpt-prompts/viewer"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
🤗 HF Data Studio
|
||||
</a>
|
||||
</Button>
|
||||
)}
|
||||
<Button size="sm" className="h-8 text-xs" asChild>
|
||||
<Link href="/prompts/new">
|
||||
<Plus className="h-3.5 w-3.5 mr-1" />
|
||||
{t("create")}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col lg:flex-row gap-6">
|
||||
|
||||
Reference in New Issue
Block a user