mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Expose model and provider to system prompt
This commit is contained in:
5 files changed
+104
-4
No files matched your search
@@ -68,7 +68,7 @@ describe('ModelInput', () => {
|
||||
|
||||
it('accepts modelFilter prop', () => {
|
||||
const onChange = vi.fn();
|
||||
const modelFilter = (model: { modalities?: string[] }) => model.modalities?.includes('image');
|
||||
const modelFilter = (model: { modalities?: string[] }) => model.modalities?.includes('image') ?? false;
|
||||
render(
|
||||
<TestApp>
|
||||
<ModelInput
|
||||
|
||||
@@ -276,6 +276,18 @@ export class SessionManager {
|
||||
// Template metadata not available
|
||||
}
|
||||
|
||||
// Build model and provider info objects
|
||||
const modelInfo = {
|
||||
id: model,
|
||||
fullId: providerModel,
|
||||
};
|
||||
|
||||
const providerInfo = {
|
||||
id: provider.id,
|
||||
name: provider.name,
|
||||
baseURL: provider.baseURL,
|
||||
};
|
||||
|
||||
const systemPrompt = await makeSystemPrompt({
|
||||
cwd: `${config.fsPathProjects}/${projectId}`,
|
||||
fs: this.fs,
|
||||
@@ -288,6 +300,8 @@ export class SessionManager {
|
||||
repositoryUrl,
|
||||
template: config.systemPrompt,
|
||||
projectTemplate,
|
||||
model: modelInfo,
|
||||
provider: providerInfo,
|
||||
});
|
||||
|
||||
// Helper function to filter out unsupported image formats (keep only JPG/JPEG/PNG)
|
||||
|
||||
@@ -73,6 +73,15 @@ describe('makeSystemPrompt', () => {
|
||||
cwd: '/projects/test-project',
|
||||
config: testConfig,
|
||||
defaultConfig: testConfig,
|
||||
model: {
|
||||
id: 'gpt-4',
|
||||
fullId: 'openai/gpt-4',
|
||||
},
|
||||
provider: {
|
||||
id: 'openai',
|
||||
name: 'OpenAI',
|
||||
baseURL: 'https://api.openai.com/v1',
|
||||
},
|
||||
};
|
||||
|
||||
// Mock getAllSkills to return empty array by default
|
||||
@@ -607,4 +616,65 @@ Skills: {{ skills.length }}`;
|
||||
expect(result).not.toContain('**(CURRENT TEMPLATE)**');
|
||||
});
|
||||
});
|
||||
|
||||
describe('model and provider information', () => {
|
||||
it('should include model and provider information in the system prompt', async () => {
|
||||
const result = await makeSystemPrompt(baseOpts);
|
||||
|
||||
expect(result).toContain('**AI Model**: openai/gpt-4 (OpenAI)');
|
||||
});
|
||||
|
||||
it('should include model information with different provider', async () => {
|
||||
const model = {
|
||||
id: 'claude-3-opus',
|
||||
fullId: 'anthropic/claude-3-opus',
|
||||
};
|
||||
|
||||
const provider = {
|
||||
id: 'anthropic',
|
||||
name: 'Anthropic',
|
||||
baseURL: 'https://api.anthropic.com/v1',
|
||||
};
|
||||
|
||||
const result = await makeSystemPrompt({
|
||||
...baseOpts,
|
||||
model,
|
||||
provider,
|
||||
});
|
||||
|
||||
expect(result).toContain('**AI Model**: anthropic/claude-3-opus (Anthropic)');
|
||||
});
|
||||
|
||||
it('should make model and provider objects accessible in custom templates', async () => {
|
||||
const model = {
|
||||
id: 'claude-3-opus',
|
||||
fullId: 'anthropic/claude-3-opus',
|
||||
};
|
||||
|
||||
const provider = {
|
||||
id: 'anthropic',
|
||||
name: 'Anthropic',
|
||||
baseURL: 'https://api.anthropic.com/v1',
|
||||
};
|
||||
|
||||
const customTemplate = `Model ID: {{ model.id }}
|
||||
Model Full ID: {{ model.fullId }}
|
||||
Provider Name: {{ provider.name }}
|
||||
Provider ID: {{ provider.id }}
|
||||
Provider Base URL: {{ provider.baseURL }}`;
|
||||
|
||||
const result = await makeSystemPrompt({
|
||||
...baseOpts,
|
||||
model,
|
||||
provider,
|
||||
template: customTemplate,
|
||||
});
|
||||
|
||||
expect(result).toContain('Model ID: claude-3-opus');
|
||||
expect(result).toContain('Model Full ID: anthropic/claude-3-opus');
|
||||
expect(result).toContain('Provider Name: Anthropic');
|
||||
expect(result).toContain('Provider ID: anthropic');
|
||||
expect(result).toContain('Provider Base URL: https://api.anthropic.com/v1');
|
||||
});
|
||||
});
|
||||
});
|
||||
+18
-2
@@ -8,6 +8,17 @@ import { JSRuntimeFS } from "./JSRuntime";
|
||||
import { getAllSkills } from "./plugins";
|
||||
import type { AppConfig } from "@/contexts/AppContext";
|
||||
|
||||
export interface ModelInfo {
|
||||
id: string;
|
||||
fullId: string;
|
||||
}
|
||||
|
||||
export interface ProviderInfo {
|
||||
id: string;
|
||||
name: string;
|
||||
baseURL: string;
|
||||
}
|
||||
|
||||
export interface MakeSystemPromptOpts {
|
||||
tools: OpenAI.Chat.Completions.ChatCompletionTool[];
|
||||
mode: "init" | "agent";
|
||||
@@ -20,6 +31,8 @@ export interface MakeSystemPromptOpts {
|
||||
repositoryUrl?: string;
|
||||
template?: string;
|
||||
projectTemplate?: { name: string; description: string; url: string };
|
||||
model: ModelInfo;
|
||||
provider: ProviderInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,6 +45,7 @@ export const defaultSystemPrompt = `{% if mode === "init" %}You are Shakespeare,
|
||||
|
||||
You are operating within **Shakespeare**, an AI-powered website builder that allows users to create custom applications through natural language conversation.
|
||||
|
||||
- **AI Model**: {{ model.fullId }}
|
||||
- **Current Date**: {{ date }}
|
||||
- **Current Page**: {{ location.href }}
|
||||
- **Current Working Directory**: {{ cwd }}
|
||||
@@ -170,7 +184,7 @@ When a project is first created, you (the AI) choose an appropriate template fro
|
||||
Shakespeare supports AI-powered image generation. Users can configure an image model in **Settings > AI** under the "Advanced" section.
|
||||
|
||||
**Important Notes:**
|
||||
- Models that support image generation can use either the chat completions endpoint (for models with "image" output modality) or the dedicated images generation endpoint
|
||||
- Not all models support image generation
|
||||
- If users experience issues with image generation, they should try selecting a different image model in Settings > AI
|
||||
- Recommended models include gpt-image-1 and gemini-3-pro-image
|
||||
- The generate_image tool will only be available once a compatible image model is configured
|
||||
@@ -236,7 +250,7 @@ Note: the badge should be displayed at its natural size. It is recommended to om
|
||||
{{ AGENTS }}{% endif %}`;
|
||||
|
||||
export async function makeSystemPrompt(opts: MakeSystemPromptOpts): Promise<string> {
|
||||
const { tools, mode, fs, cwd, config, defaultConfig, user, metadata, repositoryUrl, template, projectTemplate } = opts;
|
||||
const { tools, mode, fs, cwd, config, defaultConfig, user, metadata, repositoryUrl, template, projectTemplate, model, provider } = opts;
|
||||
|
||||
// Add current date
|
||||
const date = new Date().toLocaleDateString("en-US", {
|
||||
@@ -318,6 +332,8 @@ export async function makeSystemPrompt(opts: MakeSystemPromptOpts): Promise<stri
|
||||
README: readmeText,
|
||||
AGENTS: agentsText,
|
||||
projectTemplate,
|
||||
model,
|
||||
provider,
|
||||
};
|
||||
|
||||
// Render the template with the context
|
||||
|
||||
@@ -13,7 +13,7 @@ interface ProviderModel {
|
||||
}
|
||||
|
||||
export class ViewAvailableModelsTool implements Tool<Record<string, never>> {
|
||||
readonly description = 'View all available AI models across all configured providers, including their capabilities. This tool MUST be called before attempting to configure an image model, as it shows which models support image generation and displays the currently configured model (if any) to understand user preferences.';
|
||||
readonly description = 'View all available AI models across all configured providers, including their capabilities. This tool MUST be called before attempting to configure an image model, as it shows which models support image generation.';
|
||||
|
||||
readonly inputSchema = z.object({});
|
||||
|
||||
|
||||
Reference in new issue
Block a user