netzo / fresh-netzo

Full-stack Deno Fresh meta-framework for building business web apps like internal tools, dashboards, admin panels and automated workflows.
https://netzo.io
MIT License
51 stars 3 forks source link

[cli] add `add --prompt` flag for prompt-based code generation #34

Closed miguelrk closed 8 months ago

miguelrk commented 1 year ago

TLDR: the add command (static generation) should allow receiving optional instructions for customization (prompt-based generation). This should be implemented as an optional --prompt flag, which sends code+prompt as text for LLM API to process. User should then be able to preview the result, confirm it, keep prompting for updates, or cancel it altogether.

Initial idea taken from @feathershq/pinion (when reading thread) which could also be used (in combination with unjs/giget) for generating/scaffolding files more easily based on template-literal syntax. Some examples of how this could work:

E.g. generating a new model based on an example

import { generator, fromFile, toFile, prompt, gpt } from '@feathershq/pinion'

export const generate = generator()
  .then(prompt([{
    type: 'input',
    name: 'name',
    message: 'What is the name of your model?'
  }])
  .then(gpt(
    ({ name }) => `generate model for ${name} based on the following example`,
    fromFile('examples/model.ts'),
    toFile(({ name }) => `models/${name}.ts`)
  ))

E.g. combining static templates with prompts:

import { generator, fromFile, toFile, prompt, gpt } from '@feathershq/pinion'

const readme = ({ name, description }) => `
# ${name}

This is my awesome app that does:

${description}

Copyright ${new Date().getFullYear()} Feathers Contributors
`

export const generate = generator()
  .then(prompt([{
    type: 'input',
    name: 'name',
    message: 'What is the name of your app?'
  }, {
    type: 'input',
    name: 'description',
    message: 'Write a short description'
  }]))
  .then(renderTemplate(readme, toFile('readme.md')))
  .then(gpt('translate to German', fromFile('readme.md'), toFile('readme.de.md')))
  .then(gpt('translate values to German', fromFile('i18n.en.json'), toFile('i18n.de.json')))
miguelrk commented 8 months ago

Closed by https://github.com/netzo/netzo/pull/165 for now. This could be considered in the future. See also https://github.com/netzo/netzo/issues/26.