mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Move Chat System Prompt to AI Settings and add Shakespeare context
- Created src/lib/globalChatSystem.ts with comprehensive default prompt - Includes Shakespeare platform overview and architecture - Describes user interface and available actions - Lists helpful resource blog posts for user assistance - Moved Chat System Prompt setting from System Settings to AI Settings - Now under the "System Prompts" section in Advanced settings - Grouped with Project System Prompt for better organization - Updated GlobalChatProvider to use the new default prompt module - Added new translation keys for the reorganized UI: - systemPrompts, systemPromptsDescription - projectSystemPrompt, projectSystemPromptDescription - globalChatSystemPrompt, globalChatSystemPromptDescription - Removed redundant code from SystemSettings.tsx Resources included in the new default prompt: - AI model selection guide - Configuring AI providers - Using local AI models - Editing code in Shakespeare - Deploying and sharing projects - Importing existing projects - Version control with Git - Debugging tips - Better prompting techniques
This commit is contained in:
1 parent
5f76931941
commit
075495fe7c
6 files changed
+324
-78
No files matched your search
@@ -7,16 +7,12 @@ import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||
import { createAIClient } from '@/lib/ai-client';
|
||||
import { defaultGlobalChatSystemPrompt } from '@/lib/globalChatSystem';
|
||||
|
||||
// Maximum context size in characters (approximately 50k tokens worth)
|
||||
// This leaves room for the system prompt and response
|
||||
const MAX_CONTEXT_CHARS = 150000;
|
||||
|
||||
// Default system prompt for global chat
|
||||
const DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT = `You are a helpful AI assistant. You're here to have a friendly conversation and help answer questions on any topic.
|
||||
|
||||
Keep your responses concise but informative. Be friendly and conversational.`;
|
||||
|
||||
interface GlobalChatProviderProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
@@ -102,7 +98,7 @@ export function GlobalChatProvider({ children }: GlobalChatProviderProps) {
|
||||
const client = createAIClient(provider, config.corsProxy, user?.signer);
|
||||
|
||||
// Build messages for API using captured current messages
|
||||
const systemPrompt = config.globalChatSystemPrompt || DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT;
|
||||
const systemPrompt = config.globalChatSystemPrompt || defaultGlobalChatSystemPrompt;
|
||||
|
||||
const apiMessages: OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [
|
||||
{ role: 'system', content: systemPrompt },
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Default system prompt for global chat.
|
||||
* This provides context about Shakespeare to help users with questions about the platform.
|
||||
*/
|
||||
export const defaultGlobalChatSystemPrompt = `You are a helpful AI assistant integrated into Shakespeare, an AI-powered website builder. You're here to have a friendly conversation and help answer questions on any topic.
|
||||
|
||||
Keep your responses concise but informative. Be friendly and conversational.
|
||||
|
||||
# Your Environment
|
||||
|
||||
You are operating within **Shakespeare**, an AI-powered website builder that allows users to create custom applications through natural language conversation.
|
||||
|
||||
Users can add or remove templates in Settings > AI.
|
||||
|
||||
## What Shakespeare Is
|
||||
|
||||
Shakespeare is a web-based development environment where users can build websites and applications by chatting with an AI assistant. The platform combines the power of AI-driven development with a user-friendly interface that requires no coding knowledge from the user.
|
||||
|
||||
**Important Architecture Notes:**
|
||||
|
||||
- **Browser-Based Storage**: All project files are stored locally in the browser's IndexedDB. If users clear browser data, they may lose their projects.
|
||||
- **AI Provider Independence**: Shakespeare connects to various AI providers (OpenAI, Anthropic, Shakespeare AI, etc.). Each provider has its own pricing and authentication.
|
||||
- **Shakespeare AI Credits**: Some AI providers like Shakespeare AI allow users to purchase credits with Bitcoin Lightning, linked to their Nostr identity. These credits are stored on the provider's servers and tied to the user's Nostr pubkey.
|
||||
- **Cross-Browser Access**:
|
||||
- **AI Credits**: Users who buy credits with Nostr-enabled providers (like Shakespeare AI) can access those credits from any browser by logging into the same Nostr account (Settings > Nostr).
|
||||
- **Project Files**: Files are browser-specific. Users can export/import files via Settings > Storage, or sync via Git (Settings > Git) to access projects across browsers.
|
||||
- **No Central Shakespeare Server**: Shakespeare itself is just client-side software running in the browser. It doesn't store user data or AI credits centrally.
|
||||
|
||||
## User Interface
|
||||
|
||||
The Shakespeare interface consists of several key areas:
|
||||
|
||||
1. **Homepage** (\`/\`): A simple interface with:
|
||||
- A large textarea where users can describe what they want to build
|
||||
- A submit button to create new projects from their description
|
||||
- A left sidebar containing the list of existing projects for easy access
|
||||
|
||||
2. **Project View** (\`/projects/:projectId\`): A split-pane interface with:
|
||||
- **Left Pane**: AI chat interface where users converse with the AI
|
||||
- **Right Pane**: Toggles between two views:
|
||||
- **Preview Mode**: Live preview of the website being built
|
||||
- **Code View**: File explorer and code editor with syntax highlighting
|
||||
|
||||
3. **Settings** (\`/settings\`): Accessible from the sidebar menu, includes:
|
||||
- **Preferences** (\`/settings/preferences\`): Theme and language settings
|
||||
- **AI Settings** (\`/settings/ai\`): Configure AI providers, API keys, project templates, MCP servers, and plugins
|
||||
- **Git Settings** (\`/settings/git\`): Configure Git credentials for version control
|
||||
- **Deploy Settings** (\`/settings/deploy\`): Configure deployment providers (Shakespeare, Netlify, Vercel, nsite)
|
||||
- **Nostr Settings** (\`/settings/nostr\`): Manage Nostr accounts, relay connections, and ngit servers
|
||||
- **Storage Settings** (\`/settings/storage\`): Export/import project files, manage browser storage
|
||||
- **System Settings** (\`/settings/system\`): Advanced configuration (ESM CDN, CORS proxy, service worker, etc.)
|
||||
- **About** (\`/settings/about\`): License information and project details
|
||||
|
||||
## User Actions
|
||||
|
||||
Users interact with Shakespeare by:
|
||||
|
||||
1. **Creating Projects**: Describing what they want to build in natural language
|
||||
2. **Chatting with AI**: Requesting features, modifications, and improvements through conversation
|
||||
3. **Manual Code Editing**: Switching to code view to make direct file edits when desired
|
||||
4. **Previewing Changes**: Viewing their website in real-time as it's being built
|
||||
5. **Project Management**: Organizing and accessing multiple projects from the homepage
|
||||
6. **Deploying Projects**: Publishing their creations to public URLs (requires Nostr login)
|
||||
|
||||
## Helpful Resources
|
||||
|
||||
When users ask questions about Shakespeare, you may recommend these helpful blog posts and guides:
|
||||
|
||||
- **Choosing AI Models**: Learn how to select the best AI model for your project
|
||||
- https://soapbox.pub/blog/shakespeare-ai-model-selection
|
||||
|
||||
- **Configuring AI Providers**: Set up and configure different AI providers
|
||||
- https://soapbox.pub/blog/shakespeare-configuring-ai-providers
|
||||
|
||||
- **Using Local AI Models**: Run AI models locally on your own hardware
|
||||
- https://soapbox.pub/blog/shakespeare-local-ai-model
|
||||
|
||||
- **Editing Code**: Tips for manually editing code in Shakespeare
|
||||
- https://soapbox.pub/blog/shakespeare-editing-code
|
||||
|
||||
- **Deploying & Sharing Projects**: How to deploy and share your projects
|
||||
- https://soapbox.pub/blog/shakespeare-deploying-sharing-projects
|
||||
|
||||
- **Importing Existing Projects**: Bring existing projects into Shakespeare
|
||||
- https://soapbox.pub/blog/shakespeare-importing-existing-projects
|
||||
|
||||
- **Version Control with Git**: Using Git for version control in Shakespeare
|
||||
- https://soapbox.pub/blog/shakespeare-version-control
|
||||
|
||||
- **Debugging**: Troubleshooting and debugging your projects
|
||||
- https://soapbox.pub/blog/debugging-in-shakespeare
|
||||
|
||||
- **Better Prompting**: Tips for writing better prompts to get better results
|
||||
- https://soapbox.pub/blog/how-to-prompt-better-projects
|
||||
|
||||
When a user's question relates to one of these topics, provide a helpful answer and include the relevant link(s) so they can learn more.`;
|
||||
@@ -63,7 +63,13 @@
|
||||
"shareErrorReports": "Share error reports",
|
||||
"shareErrorReportsDescription": "Help improve this app by automatically sending crash and error reports.",
|
||||
"systemPrompt": "System Prompt",
|
||||
"systemPrompts": "System Prompts",
|
||||
"systemPromptDescription": "AI system prompt controlling the assistant's behavior and knowledge.",
|
||||
"systemPromptsDescription": "Configure the AI system prompts for project development and global chat.",
|
||||
"projectSystemPrompt": "Project System Prompt",
|
||||
"projectSystemPromptDescription": "System prompt used when the AI works on your projects. Supports Nunjucks templating for dynamic content.",
|
||||
"globalChatSystemPrompt": "Chat System Prompt",
|
||||
"globalChatSystemPromptDescription": "System prompt for the global chat assistant. This prompt provides context about Shakespeare and helpful resources.",
|
||||
"english": "English",
|
||||
"portuguese": "Portuguese",
|
||||
"chinese": "Chinese",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Check, Bot, ArrowLeft, Trash2, GripVertical, ChevronDown, RotateCcw, FileText, Plus, Edit } from 'lucide-react';
|
||||
import { Check, Bot, ArrowLeft, Trash2, GripVertical, ChevronDown, RotateCcw, FileText, Plus, Edit, MessageCircle } from 'lucide-react';
|
||||
import {
|
||||
DndContext,
|
||||
closestCenter,
|
||||
@@ -44,6 +44,7 @@ import { MCPServersSection } from '@/components/MCPServersSection';
|
||||
import { PluginsSection } from '@/components/PluginsSection';
|
||||
import { ProjectTemplatesSection } from '@/components/ProjectTemplatesSection';
|
||||
import { defaultSystemPrompt } from '@/lib/system';
|
||||
import { defaultGlobalChatSystemPrompt } from '@/lib/globalChatSystem';
|
||||
|
||||
interface SortableProviderItemProps {
|
||||
provider: AIProvider;
|
||||
@@ -217,12 +218,20 @@ export function AISettings() {
|
||||
const [activeCreditsDialog, setActiveCreditsDialog] = useState<string | null>(null);
|
||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||
const [systemPromptInput, setSystemPromptInput] = useState(config.systemPrompt || defaultSystemPrompt);
|
||||
const [chatSystemPromptInput, setChatSystemPromptInput] = useState(
|
||||
config.globalChatSystemPrompt || defaultGlobalChatSystemPrompt
|
||||
);
|
||||
|
||||
// Check if system prompt differs from default
|
||||
const isSystemPromptModified = useMemo(() =>
|
||||
(config.systemPrompt || defaultSystemPrompt) !== (defaultConfig.systemPrompt || defaultSystemPrompt),
|
||||
[config, defaultConfig]);
|
||||
|
||||
// Check if chat system prompt differs from default
|
||||
const isChatSystemPromptModified = useMemo(() =>
|
||||
(config.globalChatSystemPrompt || defaultGlobalChatSystemPrompt) !== defaultGlobalChatSystemPrompt,
|
||||
[config]);
|
||||
|
||||
const restoreSystemPrompt = () => {
|
||||
const defaultValue = defaultSystemPrompt;
|
||||
setSystemPromptInput(defaultValue);
|
||||
@@ -232,6 +241,14 @@ export function AISettings() {
|
||||
});
|
||||
};
|
||||
|
||||
const restoreChatSystemPrompt = () => {
|
||||
setChatSystemPromptInput(defaultGlobalChatSystemPrompt);
|
||||
updateConfig((current) => {
|
||||
const { globalChatSystemPrompt, ...rest } = current;
|
||||
return rest;
|
||||
});
|
||||
};
|
||||
|
||||
const sensors = useSensors(
|
||||
useSensor(PointerSensor),
|
||||
useSensor(KeyboardSensor, {
|
||||
@@ -684,28 +701,34 @@ export function AISettings() {
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<FileText className="h-5 w-5 text-primary" />
|
||||
<h3 className="text-lg font-semibold">{t('systemPrompt')}</h3>
|
||||
{isSystemPromptModified && (
|
||||
<h3 className="text-lg font-semibold">{t('systemPrompts')}</h3>
|
||||
{(isSystemPromptModified || isChatSystemPromptModified) && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('systemPromptDescription')}
|
||||
{t('systemPromptsDescription')}
|
||||
</p>
|
||||
</div>
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<Accordion type="single" collapsible className="w-full space-y-2">
|
||||
<AccordionItem value="system-prompt" className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Edit className="h-4 w-4" />
|
||||
<span className="font-medium">{t('systemPrompt')}</span>
|
||||
<span className="font-medium">{t('projectSystemPrompt')}</span>
|
||||
{isSystemPromptModified && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-2">
|
||||
<p className="text-xs text-muted-foreground mb-2">
|
||||
{t('projectSystemPromptDescription')}
|
||||
</p>
|
||||
<Textarea
|
||||
id="system-prompt"
|
||||
placeholder="Enter EJS template..."
|
||||
placeholder="Enter Nunjucks template..."
|
||||
value={systemPromptInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
@@ -730,6 +753,48 @@ export function AISettings() {
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
<AccordionItem value="chat-system-prompt" className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<MessageCircle className="h-4 w-4" />
|
||||
<span className="font-medium">{t('globalChatSystemPrompt')}</span>
|
||||
{isChatSystemPromptModified && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-2">
|
||||
<p className="text-xs text-muted-foreground mb-2">
|
||||
{t('globalChatSystemPromptDescription')}
|
||||
</p>
|
||||
<Textarea
|
||||
id="chat-system-prompt"
|
||||
placeholder="Enter system prompt..."
|
||||
value={chatSystemPromptInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setChatSystemPromptInput(value);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
globalChatSystemPrompt: value,
|
||||
}));
|
||||
}}
|
||||
className="flex-1 font-mono text-xs min-h-[300px]"
|
||||
/>
|
||||
{isChatSystemPromptModified && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={restoreChatSystemPrompt}
|
||||
className="w-full"
|
||||
>
|
||||
<RotateCcw className="h-4 w-4 mr-2" />
|
||||
{t('restoreToDefault')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2, RotateCcw, Cog, Globe, Image, Code, Monitor, Award, Bug, FolderTree, Terminal as TerminalIcon, MessageCircle } from "lucide-react";
|
||||
import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2, RotateCcw, Cog, Globe, Image, Code, Monitor, Award, Bug, FolderTree, Terminal as TerminalIcon } from "lucide-react";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { useIsMobile } from "@/hooks/useIsMobile";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
@@ -14,11 +13,6 @@ import { useOffline } from "@/hooks/useOffline";
|
||||
import { useToast } from "@/hooks/useToast";
|
||||
import { Terminal } from "@/components/Terminal";
|
||||
|
||||
// Default system prompt for global chat
|
||||
const DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT = `You are a helpful AI assistant. You're here to have a friendly conversation and help answer questions on any topic.
|
||||
|
||||
Keep your responses concise but informative. Be friendly and conversational.`;
|
||||
|
||||
export function SystemSettings() {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsMobile();
|
||||
@@ -38,9 +32,6 @@ export function SystemSettings() {
|
||||
const [fsPathPluginsInput, setFsPathPluginsInput] = useState(config.fsPathPlugins);
|
||||
const [fsPathTemplatesInput, setFsPathTemplatesInput] = useState(config.fsPathTemplates);
|
||||
const [sentryDsnInput, setSentryDsnInput] = useState(config.sentryDsn);
|
||||
const [chatSystemPromptInput, setChatSystemPromptInput] = useState(
|
||||
config.globalChatSystemPrompt || DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT
|
||||
);
|
||||
|
||||
// Check which settings differ from defaults
|
||||
const isModified = useMemo(() => ({
|
||||
@@ -56,7 +47,6 @@ export function SystemSettings() {
|
||||
fsPathPlugins: config.fsPathPlugins !== defaultConfig.fsPathPlugins,
|
||||
fsPathTemplates: config.fsPathTemplates !== defaultConfig.fsPathTemplates,
|
||||
sentryDsn: config.sentryDsn !== defaultConfig.sentryDsn,
|
||||
globalChatSystemPrompt: (config.globalChatSystemPrompt || DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT) !== DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT,
|
||||
}), [config, defaultConfig]);
|
||||
|
||||
// Restore functions - clear the value from config to use the default
|
||||
@@ -166,14 +156,6 @@ export function SystemSettings() {
|
||||
});
|
||||
};
|
||||
|
||||
const restoreChatSystemPrompt = () => {
|
||||
setChatSystemPromptInput(DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT);
|
||||
updateConfig((current) => {
|
||||
const { globalChatSystemPrompt, ...rest } = current;
|
||||
return rest;
|
||||
});
|
||||
};
|
||||
|
||||
// Service Worker state
|
||||
const [swState, setSwState] = useState<string>('');
|
||||
const [isUpdatingSW, setIsUpdatingSW] = useState(false);
|
||||
@@ -970,52 +952,6 @@ export function SystemSettings() {
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* Chat System Prompt Configuration */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="chat-system-prompt">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<MessageCircle className="h-4 w-4 text-muted-foreground" />
|
||||
<h4 className="text-sm font-medium">{t('globalChatSystemPrompt')}</h4>
|
||||
{isModified.globalChatSystemPrompt && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="py-1 space-y-2">
|
||||
<Textarea
|
||||
placeholder="Enter system prompt..."
|
||||
value={chatSystemPromptInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setChatSystemPromptInput(value);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
globalChatSystemPrompt: value,
|
||||
}));
|
||||
}}
|
||||
className="font-mono text-xs min-h-[150px]"
|
||||
/>
|
||||
{isModified.globalChatSystemPrompt && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={restoreChatSystemPrompt}
|
||||
className="w-full"
|
||||
>
|
||||
<RotateCcw className="h-4 w-4 mr-2" />
|
||||
{t('restoreToDefault')}
|
||||
</Button>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('globalChatSystemPromptDescription')}
|
||||
</p>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* Terminal */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="terminal">
|
||||
|
||||
Reference in new issue
Block a user