mirror of
https://github.com/mirego/accent.git
synced 2024-10-26 18:39:53 +03:00
Add usePlatform for prompts config
This commit is contained in:
parent
edec1f74bb
commit
f3954c127a
@ -49,6 +49,11 @@ config :accent, Accent.MachineTranslations,
|
||||
"deepl" => %{"key" => get_env("DEEPL_TRANSLATIONS_KEY")}
|
||||
}
|
||||
|
||||
config :accent, Accent.Prompts,
|
||||
default_providers_config: %{
|
||||
"openai" => %{"key" => get_env("OPENAI_API_KEY")}
|
||||
}
|
||||
|
||||
config :accent, LanguageTool, languages: get_env("LANGUAGE_TOOL_LANGUAGES", :comma_separated_list)
|
||||
|
||||
providers = []
|
||||
|
@ -11,7 +11,8 @@ defmodule Accent.PromptConfigManager do
|
||||
"config" => %{
|
||||
"key" => params[:config_key]
|
||||
},
|
||||
"provider" => params[:provider]
|
||||
"provider" => params[:provider],
|
||||
"use_platform" => params[:use_platform]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ defmodule Accent.GraphQL.Mutations.Prompt do
|
||||
arg(:project_id, non_null(:id))
|
||||
arg(:provider, non_null(:string))
|
||||
arg(:config_key, :string)
|
||||
arg(:use_platform, non_null(:boolean))
|
||||
|
||||
resolve(project_authorize(:save_project_prompt_config, &Resolver.save_config/3, :project_id))
|
||||
end
|
||||
|
@ -29,6 +29,8 @@ defmodule Accent.GraphQL.Types.Project do
|
||||
|
||||
object :prompt_config do
|
||||
field(:provider, non_null(:string))
|
||||
field(:use_platform, non_null(:boolean))
|
||||
field(:use_config_key, non_null(:boolean))
|
||||
end
|
||||
|
||||
object :project do
|
||||
@ -50,7 +52,7 @@ defmodule Accent.GraphQL.Types.Project do
|
||||
%{
|
||||
provider: project.machine_translations_config["provider"],
|
||||
enabled_actions: project.machine_translations_config["enabled_actions"] || [],
|
||||
use_platform: project.machine_translations_config["use_platform"],
|
||||
use_platform: project.machine_translations_config["use_platform"] || false,
|
||||
use_config_key: not is_nil(project.machine_translations_config["config"]["key"])
|
||||
}}
|
||||
else
|
||||
@ -64,7 +66,9 @@ defmodule Accent.GraphQL.Types.Project do
|
||||
if project.prompt_config do
|
||||
{:ok,
|
||||
%{
|
||||
provider: project.prompt_config["provider"]
|
||||
provider: project.prompt_config["provider"],
|
||||
use_platform: project.prompt_config["use_platform"] || false,
|
||||
use_config_key: not is_nil(project.prompt_config["config"]["key"])
|
||||
}}
|
||||
else
|
||||
{:ok, nil}
|
||||
|
@ -87,15 +87,15 @@ defmodule Accent.MachineTranslations do
|
||||
|
||||
defp provider_from_config(nil), do: %Provider.NotImplemented{}
|
||||
|
||||
defp provider_from_config(machine_translations_config) do
|
||||
defp provider_from_config(config) do
|
||||
struct_module =
|
||||
case machine_translations_config["provider"] do
|
||||
case config["provider"] do
|
||||
"google_translate" -> Provider.GoogleTranslate
|
||||
"deepl" -> Provider.Deepl
|
||||
_ -> Provider.NotImplemented
|
||||
end
|
||||
|
||||
struct!(struct_module, config: fetch_config(machine_translations_config))
|
||||
struct!(struct_module, config: fetch_config(config))
|
||||
end
|
||||
|
||||
defp fetch_config(%{"provider" => provider, "use_platform" => true}) do
|
||||
|
@ -17,6 +17,8 @@ defmodule Accent.Prompts do
|
||||
Provider.enabled?(provider)
|
||||
end
|
||||
|
||||
defp provider_from_config(nil), do: %Provider.NotImplemented{}
|
||||
|
||||
defp provider_from_config(config) do
|
||||
struct_module =
|
||||
case config["provider"] do
|
||||
@ -24,6 +26,12 @@ defmodule Accent.Prompts do
|
||||
_ -> Provider.NotImplemented
|
||||
end
|
||||
|
||||
struct!(struct_module, config: config)
|
||||
struct!(struct_module, config: fetch_config(config))
|
||||
end
|
||||
|
||||
defp fetch_config(%{"provider" => provider, "use_platform" => true}) do
|
||||
Map.get(Application.get_env(:accent, __MODULE__)[:default_providers_config], provider)
|
||||
end
|
||||
|
||||
defp fetch_config(%{"config" => config}), do: config
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ defmodule Accent.Prompts.Provider.OpenAI do
|
||||
def enabled?(_), do: true
|
||||
|
||||
def completions(provider, prompt, user_input) do
|
||||
config = provider.config["config"]
|
||||
config = provider.config
|
||||
|
||||
params = %{
|
||||
messages: [
|
||||
|
@ -13,9 +13,11 @@ interface Args {
|
||||
onSave: ({
|
||||
provider,
|
||||
configKey,
|
||||
usePlatform
|
||||
}: {
|
||||
provider: string;
|
||||
configKey: string | null;
|
||||
usePlatform: boolean;
|
||||
}) => Promise<any>;
|
||||
}
|
||||
|
||||
@ -26,7 +28,7 @@ const LOGOS = {
|
||||
openai: 'assets/prompts_providers/openai.svg',
|
||||
};
|
||||
|
||||
export default class ProjectSettingsMachineTranslations extends Component<Args> {
|
||||
export default class ProjectSettingsPromptsConfig extends Component<Args> {
|
||||
@service('global-state')
|
||||
globalState: GlobalState;
|
||||
|
||||
@ -37,10 +39,10 @@ export default class ProjectSettingsMachineTranslations extends Component<Args>
|
||||
intl: IntlService;
|
||||
|
||||
@tracked
|
||||
provider = this.args.project.promptsConfig?.provider || 'openai';
|
||||
provider = this.args.project.promptConfig?.provider || 'openai';
|
||||
|
||||
@tracked
|
||||
usePlatform = this.args.project.promptsConfig?.usePlatform || false;
|
||||
usePlatform = this.args.project.promptConfig?.usePlatform || false;
|
||||
|
||||
@tracked
|
||||
configKey: any;
|
||||
@ -86,10 +88,19 @@ export default class ProjectSettingsMachineTranslations extends Component<Args>
|
||||
this.configKey = (event.target as HTMLInputElement).value;
|
||||
}
|
||||
|
||||
@action
|
||||
onUsePlatformChange(event: InputEvent) {
|
||||
const checked = (event.target as HTMLInputElement).checked;
|
||||
|
||||
if (checked) this.configKey = null;
|
||||
this.usePlatform = checked;
|
||||
}
|
||||
|
||||
submit = dropTask(async () => {
|
||||
await this.args.onSave({
|
||||
provider: this.provider,
|
||||
configKey: this.configKey,
|
||||
usePlatform: this.usePlatform
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -414,6 +414,7 @@
|
||||
"title": "AI Assistant",
|
||||
"help": "Instructions will be available on all string inputs to help you improve your content. The clearer the instructions you give to the assistant, to better the output will be.",
|
||||
"new_button": "Add a new instruction",
|
||||
"use_platform_label": "Use the platform config if available",
|
||||
"config_key_help_present": "Config key has been set, but the value will never be exposed via the API.",
|
||||
"config_key_help_not_present": "Once saved, the config key will never be shown.",
|
||||
"delete_confirm": "Are you sure you want to delete this instruction?"
|
||||
|
@ -403,6 +403,7 @@
|
||||
"prompts": {
|
||||
"title": "Assistant IA",
|
||||
"help": "Des instructions seront disponibles sur chaque entrée de chaîne pour vous aider à améliorer votre contenu. Plus les instructions que vous donnez à l’assistant sont claires, meilleur sera le résultat.",
|
||||
"use_platform_label": "Utilisez la configuration de la plate-forme si disponible",
|
||||
"new_button": "Ajouter une nouvelle instruction",
|
||||
"config_key_help_present": "La clé de configuration a été définie, mais la valeur ne sera jamais exposée via l’API.",
|
||||
"config_key_help_not_present": "Une fois enregistrée, la clé de configuration ne sera jamais affichée.",
|
||||
|
@ -7,8 +7,8 @@ export default gql`
|
||||
id
|
||||
machineTranslationsConfig {
|
||||
provider
|
||||
usePlatform
|
||||
enabledActions
|
||||
usePlatform
|
||||
useConfigKey
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ export default gql`
|
||||
|
||||
promptConfig {
|
||||
provider
|
||||
usePlatform
|
||||
useConfigKey
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ export interface SaveProjectPromptConfigVariables {
|
||||
projectId: string;
|
||||
provider: string;
|
||||
configKey: string;
|
||||
usePlatform: boolean;
|
||||
}
|
||||
|
||||
export interface SaveProjectPromptConfigResponse {
|
||||
@ -18,11 +19,13 @@ export default gql`
|
||||
mutation ProjectPromptConfigSave(
|
||||
$provider: String!
|
||||
$configKey: String
|
||||
$usePlatform: Boolean!
|
||||
$projectId: ID!
|
||||
) {
|
||||
saveProjectPromptConfig(
|
||||
provider: $provider
|
||||
configKey: $configKey
|
||||
usePlatform: $usePlatform
|
||||
projectId: $projectId
|
||||
) {
|
||||
project {
|
||||
|
@ -10,7 +10,7 @@
|
||||
display: none;
|
||||
padding: 2px 6px;
|
||||
border-radius: var(--border-radius);
|
||||
margin: 0 15px 10px;
|
||||
margin: 0 5px 5px;
|
||||
|
||||
background: var(--background-light);
|
||||
}
|
||||
|
@ -12,6 +12,10 @@
|
||||
}
|
||||
|
||||
.revert-button {
|
||||
position: absolute;
|
||||
right: 8px;
|
||||
top: -30px;
|
||||
|
||||
:global(.label) {
|
||||
padding-left: 3px;
|
||||
padding-right: 3px;
|
||||
@ -27,6 +31,11 @@
|
||||
flex-direction: column;
|
||||
|
||||
&[data-dir='rtl'] {
|
||||
.revert-button {
|
||||
right: auto;
|
||||
left: 8px;
|
||||
}
|
||||
|
||||
.item-details__column {
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
@ -24,13 +24,12 @@
|
||||
}
|
||||
|
||||
.prompt-button-quick-access[data-rtl] {
|
||||
left: 36px;
|
||||
right: auto;
|
||||
transform: translateX(36px);
|
||||
}
|
||||
|
||||
.prompt-button-quick-access {
|
||||
opacity: 1;
|
||||
right: 36px;
|
||||
transform: translateX(-36px);
|
||||
padding: 0 10px;
|
||||
pointer-events: all;
|
||||
}
|
||||
|
@ -65,6 +65,22 @@
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.options {
|
||||
margin: 10px 0 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.option-checkbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
@ -15,15 +15,28 @@
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<p local-class='config-key-help'>
|
||||
{{#if @project.promptConfig}}
|
||||
{{t 'components.project_settings.prompts.config_key_help_present'}}
|
||||
<div local-class='options'>
|
||||
<label local-class='option-checkbox'>
|
||||
<input value={{this.usePlatform}} type='checkbox' checked={{this.usePlatform}} {{on 'change' (fn this.onUsePlatformChange)}} />
|
||||
{{t 'components.project_settings.prompts.use_platform_label'}}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{{#unless this.usePlatform}}
|
||||
<p local-class='config-key-help'>
|
||||
{{#if @project.promptConfig.useConfigKey}}
|
||||
{{t 'components.project_settings.prompts.config_key_help_present'}}
|
||||
{{else}}
|
||||
{{t 'components.project_settings.prompts.config_key_help_not_present'}}
|
||||
{{/if}}
|
||||
</p>
|
||||
</p>
|
||||
|
||||
<textarea placeholder={{this.configKeyPlaceholder}} local-class='textInput' rows='1' {{on 'change' (fn this.onConfigKeyChange)}}>{{this.configKey}}</textarea>
|
||||
<textarea
|
||||
placeholder={{this.configKeyPlaceholder}}
|
||||
local-class='textInput'
|
||||
{{on 'change' (fn this.onConfigKeyChange)}}
|
||||
>{{this.configKey}}</textarea>
|
||||
{{/unless}}
|
||||
|
||||
<div local-class='actions'>
|
||||
{{#if @project.promptConfig}}
|
||||
|
Loading…
Reference in New Issue
Block a user