Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration option for keypathValidate and prompt settings #1213

Open
lebmouse opened this issue Sep 25, 2024 · 0 comments
Open

Add configuration option for keypathValidate and prompt settings #1213

lebmouse opened this issue Sep 25, 2024 · 0 comments

Comments

@lebmouse
Copy link

Is your feature related to a specific framework or general for this extension?
General. This feature request is aimed at making the keypathValidate function and prompt settings more configurable, and is not tied to a specific framework.

Is your feature request related to a problem? Please describe.
Currently, the keypathValidate function uses a hardcoded regex pattern for validation. This limits flexibility when different key path patterns are needed across various projects or environments. Additionally, having prompt settings that are also configurable would enhance the overall usability and adaptability of the extension.

Describe the solution you'd like
I would like to introduce configuration options for the keypathValidate function, allowing users to define their own regex patterns through settings. This would enable different projects to have custom key path validation rules without modifying the core code. Additionally, providing configurable prompt settings would allow for more personalized user interactions.

Additional context
This feature would significantly increase the versatility of the extension, making it more adaptable to various use cases and project requirements. It would also simplify maintenance by centralizing configuration options instead of relying on code changes.

// keypathValidate.ts
import { Config } from '~/core'
export function keypathValidate(keypath: string) {
  return !!keypath.math(Config.keypathValidate ? new RegExp(Config.keypathValidate) :  keypath.match(/^[\w\d\-_][\w\d\-_[\]. ]*$/))
}

// openapi.ts

systemPrompt = Config.openaiApiSystemPrompt ?? 'You are a professional translation engine. Please translate text without explanation.'
...
generateUserPrompts(options: TranslateOptions): string {
    const sourceLang = options.from
    const targetLang = options.to
    const message = options.text

    let generatedUserPrompt = `translate from ${sourceLang} to ${targetLang}:\n\n${message}`

    if (Config.openaiApiPrompt && sourceLang && targetLang && message)
      generatedUserPrompt = Config.openaiApiPrompt.replaceAll('{sourceLang}', sourceLang).replaceAll('{targetLang}', targetLang).replaceAll('{message}', message)

    return generatedUserPrompt
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant