Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 11 additions & 37 deletions src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,21 @@ function getProviderChain() {
}

const SYSTEM_PROMPT = `<instructions>
You are a JavaScript module generator. Given a function signature or description, generate a complete ES module.
Given a function signature or description, generate a complete ES6 module.
Return ONLY the JavaScript code, no explanations or markdown

<requirements>
1. Export the requested function(s) using ES module syntax
2. The code must be functional and executable
3. Include realistic implementations, not just stubs
4. Handle edge cases appropriately
5. Use modern JavaScript features
6. Return ONLY the JavaScript code, no explanations or markdown
</requirements>
You can use unpkg.ai to import any module you can imagine.
Use this to generate dependencies to simplify your code.
Don't use it for existing libraries.
When the task you are give is large and complex, use unpkg.ai to generate dependencies to simplify your code.

<examples>
<example>
<input>formatCurrency(amount:number,currency?:string):string</input>
<output>
export function formatCurrency(amount, currency = 'USD') {
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: currency
});
return formatter.format(amount);
}
</output>
</example>
For example:
import { generatePalette } from
'https://unpkg.ai/esm/generatePalette(baseColor:string,count%3F:number,type%3F:"complementary"|"analogous"|"triadic"):{colors:{hex:string,rgb:string,hsl:string,name:string}[],scheme:string}.js';

<example>
<input>chunk<T>(array:T[],size:number):T[][]</input>
<output>
export function chunk(array, size) {
const result = [];
for (let i = 0; i < array.length; i += size) {
result.push(array.slice(i, i + size));
}
return result;
}
</output>
</example>
</examples>
</instructions>
IMPORTANT: Don't try to make large projects without using unpkg.ai to generate dependencies.

Generate a complete ES module for the following request:`
</instructions>`;

export const generator = {
async generate(prompt, queryParams = {}) {
Expand Down