3 ms·
I was curious about how they were getting GPT to generate images, the prompting is so simple[1] that GPT still blows my mind: async fetchImage(context) {
by mmh0000 3y ago
I was curious about how they were getting GPT to generate images, the prompting is so simple[1] that GPT still blows my mind:
async fetchImage(context) {
const messages = context || [
{ role: 'system', content: `You are a helpful assistant that generates SVG drawings. You respond only with SVG. You do not respond with text.` },
{ role: 'user', content: `Draw a unicorn in SVG format. Dimensions: 500x500. Respond ONLY with a single SVG string. Do not respond with conversation or codeblocks.` }
]
const response = await this.api.generateCompletion(messages)
if (!isSvg(response.content)) {
console.error('Generated image is not valid SVG:', response.content)
messages.push({ role: 'assistant', content: response.content })
messages.push({ role: 'user', content: `The generated image is not valid SVG. Please try again. Only respond with SVG code. No text.` })
return this.fetchImage(messages)
}
console.log('Generated image:', response.content)
return response
}
[1] https://github.com/adamkdean/gpt-unicorn/blob/master/src/lib/generator.js https://github.com/adamkdean/gpt-unicorn/blob/master/src/lib...