From 223af1d3f60a1cc5932b84505de6e3d4885143bc Mon Sep 17 00:00:00 2001 From: Mamadou DICKO <63923024+mamadoudicko@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:42:19 +0100 Subject: [PATCH] feat: add api brain creation frontend (#1631) Issue: https://github.com/StanGirard/quivr/issues/1607 Demo: https://github.com/StanGirard/quivr/assets/63923024/a087d856-e201-4b88-80b3-b001d7bb6b16 --- backend/models/ApiBrainDefinition.py | 2 +- frontend/lib/api/brain/types.ts | 35 +++++- .../AddBrainModal/AddBrainModal.tsx | 17 ++- .../AddBrainConfig/AddBrainConfig.tsx | 26 ++-- .../ApiRequestDefinition.tsx | 112 ++++++++++++------ .../components/BrainDefinitionTabTrigger.tsx | 29 +++++ .../ParamsDefinition/ParamsDefinition.tsx | 72 +++++++++++ .../components/ParamDefinitionRow.tsx | 79 ++++++++++++ .../components/ParamsDefinition/config.ts | 8 ++ .../hooks/useParamsDefinition.ts | 55 +++++++++ .../components/ParamsDefinition/types.ts | 8 ++ ...inDefinitionSchemaToParameterDefinition.ts | 23 ++++ ...terDefinitionToApiBrainDefinitionSchema.ts | 34 ++++++ .../SecretsDefinition/SecretsDefinition.tsx | 66 +++++++++++ .../components/SecretDefinitionRow.tsx | 81 +++++++++++++ .../components/SecretsDefinition/config.ts | 11 ++ .../hooks/useSecretsDefinition.ts | 67 +++++++++++ .../components/SecretsDefinition/types.ts | 12 ++ ...retDefinitionToApiBrainSecretDefinition.ts | 31 +++++ ...sDefinitionsAndValuesToSecretDefinition.ts | 29 +++++ .../ApiRequestDefinition/components/styles.ts | 1 + ...onTabs.tsx => useApiRequestDefinition.tsx} | 4 +- .../components/ApiRequestDefinition/styles.ts | 1 + .../tabs/HeadersDefinition.tsx | 3 - .../tabs/ParamsDefinition.tsx | 3 - .../tabs/SearchParamsDefinition.tsx | 3 - .../components/ApiRequestDefinition/types.ts | 2 +- .../AddBrainConfig/hooks/useAddBrainConfig.ts | 39 +++--- .../components/AddBrainConfig/types.ts | 7 ++ frontend/lib/config/defaultBrainConfig.ts | 13 ++ .../BrainProvider/hooks/useBrainProvider.ts | 5 +- frontend/lib/helpers/defineMaxTokens.ts | 4 +- frontend/lib/types/brainConfig.ts | 4 +- frontend/public/locales/en/brain.json | 10 +- .../locales/en/external_api_definition.json | 6 +- frontend/public/locales/es/brain.json | 10 +- .../locales/es/external_api_definition.json | 6 +- frontend/public/locales/fr/brain.json | 10 +- .../locales/fr/external_api_definition.json | 6 +- frontend/public/locales/pt-br/brain.json | 10 +- .../pt-br/external_api_definition.json | 6 +- frontend/public/locales/ru/brain.json | 10 +- .../locales/ru/external_api_definition.json | 6 +- frontend/public/locales/zh-cn/brain.json | 10 +- .../zh-cn/external_api_definition.json | 6 +- 45 files changed, 881 insertions(+), 101 deletions(-) create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/BrainDefinitionTabTrigger.tsx create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/ParamsDefinition.tsx create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/components/ParamDefinitionRow.tsx create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/config.ts create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/hooks/useParamsDefinition.ts create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/types.ts create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/utils/mapApiBrainDefinitionSchemaToParameterDefinition.ts create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/utils/mapParameterDefinitionToApiBrainDefinitionSchema.ts create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/SecretsDefinition.tsx create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/components/SecretDefinitionRow.tsx create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/config.ts create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/hooks/useSecretsDefinition.ts create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/types.ts create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/utils/mapSecretDefinitionToApiBrainSecretDefinition.ts create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/utils/mapSecretsDefinitionsAndValuesToSecretDefinition.ts create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/styles.ts rename frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/hooks/{useApiDefinitionTabs.tsx => useApiRequestDefinition.tsx} (63%) create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/styles.ts delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/HeadersDefinition.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/ParamsDefinition.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/SearchParamsDefinition.tsx create mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainConfig/types.ts diff --git a/backend/models/ApiBrainDefinition.py b/backend/models/ApiBrainDefinition.py index d291678ed..3690511f3 100644 --- a/backend/models/ApiBrainDefinition.py +++ b/backend/models/ApiBrainDefinition.py @@ -23,7 +23,7 @@ class ApiBrainDefinitionSchema(BaseModel, extra=Extra.forbid): required: list[str] = [] -class ApiBrainDefinitionSecret(BaseModel): +class ApiBrainDefinitionSecret(BaseModel, extra=Extra.forbid): name: str type: str diff --git a/frontend/lib/api/brain/types.ts b/frontend/lib/api/brain/types.ts index 46877ac0b..83c6e0aea 100644 --- a/frontend/lib/api/brain/types.ts +++ b/frontend/lib/api/brain/types.ts @@ -1,20 +1,51 @@ import { BrainRoleType } from "@/lib/components/BrainUsers/types"; -import { BrainStatus, BrainType } from "@/lib/types/brainConfig"; +import { BrainStatus, BrainType, Model } from "@/lib/types/brainConfig"; + +export type ApiBrainDefinitionSchemaPropertyType = "string" | "number"; + +export type ApiBrainDefinitionSchemaProperty = { + type: ApiBrainDefinitionSchemaPropertyType; + description: string; + name: string; +}; +export const allowedRequestMethods = ["GET", "POST", "PUT", "DELETE"]; + +export type AllowedRequestMethod = (typeof allowedRequestMethods)[number]; + +export type ApiBrainDefinitionSchema = { + properties: ApiBrainDefinitionSchemaProperty[]; + required: string[]; +}; export type SubscriptionUpdatableProperties = { role: BrainRoleType | null; }; +export type ApiBrainDefinitionSecret = { + name: string; + type: ApiBrainDefinitionSchemaPropertyType; +}; + +export type ApiBrainDefinition = { + method: AllowedRequestMethod; + url: string; + search_params: ApiBrainDefinitionSchema; + params: ApiBrainDefinitionSchema; + secrets?: ApiBrainDefinitionSecret[]; +}; + export type CreateBrainInput = { name: string; description?: string; status?: BrainStatus; - model?: string; + model?: Model; temperature?: number; max_tokens?: number; openai_api_key?: string; prompt_id?: string | null; brain_type?: BrainType; + brain_definition?: ApiBrainDefinition; + brain_secrets_values?: Record; }; export type UpdateBrainInput = Partial; diff --git a/frontend/lib/components/AddBrainModal/AddBrainModal.tsx b/frontend/lib/components/AddBrainModal/AddBrainModal.tsx index c5da1053e..90fd069cc 100644 --- a/frontend/lib/components/AddBrainModal/AddBrainModal.tsx +++ b/frontend/lib/components/AddBrainModal/AddBrainModal.tsx @@ -1,9 +1,9 @@ import { FormProvider, useForm } from "react-hook-form"; -import { defaultBrainConfig } from "@/lib/config/defaultBrainConfig"; -import { BrainConfig } from "@/lib/types/brainConfig"; +import { addBrainDefaultValues } from "@/lib/config/defaultBrainConfig"; import { AddBrainConfig } from "./components/AddBrainConfig/AddBrainConfig"; +import { CreateBrainProps } from "./components/AddBrainConfig/types"; type AddBrainModalProps = { triggerClassName?: string; @@ -12,8 +12,17 @@ type AddBrainModalProps = { export const AddBrainModal = ({ triggerClassName, }: AddBrainModalProps): JSX.Element => { - const methods = useForm({ - defaultValues: defaultBrainConfig, + const defaultValues: CreateBrainProps = { + ...addBrainDefaultValues, + prompt: { + title: "", + content: "", + }, + setDefault: true, + }; + + const methods = useForm({ + defaultValues, }); return ( diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/AddBrainConfig.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/AddBrainConfig.tsx index 54744004a..1d07e0cad 100644 --- a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/AddBrainConfig.tsx +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/AddBrainConfig.tsx @@ -11,6 +11,7 @@ import { Modal } from "@/lib/components/ui/Modal"; import { defineMaxTokens } from "@/lib/helpers/defineMaxTokens"; import { cn } from "@/lib/utils"; +import { ApiRequestDefinition } from "./components/ApiRequestDefinition"; import { PublicAccessConfirmationModal } from "./components/PublicAccessConfirmationModal"; import { useAddBrainConfig } from "./hooks/useAddBrainConfig"; import { useAddBrainConfigLabels } from "./hooks/useAddBrainConfigLabels"; @@ -105,22 +106,25 @@ export const AddBrainConfig = ({ /> {brainApiIsOn && ( -
- -
+ <> +
+ +
+ + )}
@@ -163,7 +167,7 @@ export const AddBrainConfig = ({ min="10" max={defineMaxTokens(model)} value={maxTokens} - {...register("maxTokens")} + {...register("max_tokens")} />
diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/ApiRequestDefinition.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/ApiRequestDefinition.tsx index c2bb2fd3a..15d6f7c33 100644 --- a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/ApiRequestDefinition.tsx +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/ApiRequestDefinition.tsx @@ -1,53 +1,95 @@ -import { Content, Root } from "@radix-ui/react-tabs"; +import { Content, List, Root } from "@radix-ui/react-tabs"; +import { Fragment } from "react"; +import { useFormContext } from "react-hook-form"; +import { useTranslation } from "react-i18next"; -import { BrainType } from "@/lib/types/brainConfig"; +import { allowedRequestMethods, CreateBrainInput } from "@/lib/api/brain/types"; -import { useApiDefinitionTabs } from "./hooks/useApiDefinitionTabs"; -import { HeadersDefinition } from "./tabs/HeadersDefinition"; -import { ParamsDefinition } from "./tabs/ParamsDefinition"; -import { SearchParamsDefinition } from "./tabs/SearchParamsDefinition"; -export const ApiRequestDefinition = (brainType: { - brainType: BrainType; -}): JSX.Element => { - const { selectedTab, setSelectedTab } = useApiDefinitionTabs(); - console.log(brainType); +import { BrainDefinitionTabTrigger } from "./components/BrainDefinitionTabTrigger"; +import { ParamsDefinition } from "./components/ParamsDefinition/ParamsDefinition"; +import { SecretsDefinition } from "./components/SecretsDefinition/SecretsDefinition"; +import { useApiRequestDefinition } from "./hooks/useApiRequestDefinition"; - setSelectedTab("searchParams"); +export const ApiRequestDefinition = (): JSX.Element => { + const { selectedTab, setSelectedTab } = useApiRequestDefinition(); + const { t } = useTranslation(["external_api_definition"]); + + const { watch, register } = useFormContext(); + + const brainType = watch("brain_type"); + + if (brainType !== "api") { + return ; + } + + const allowedMethodsOptions = allowedRequestMethods.map((method) => ({ + label: method, + value: method, + })); return ( - -
+ <> +
-
- - - - - - - - - -
- + + + + + + +
+ + + + + + + + + +
+
+ ); }; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/BrainDefinitionTabTrigger.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/BrainDefinitionTabTrigger.tsx new file mode 100644 index 000000000..155d0f6f6 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/BrainDefinitionTabTrigger.tsx @@ -0,0 +1,29 @@ +import { Trigger } from "@radix-ui/react-tabs"; + +import { ApiTab } from "../types"; + +type BrainDefinitionTabTriggerProps = { + label: string; + value: ApiTab; + selected: boolean; + onChange: (value: ApiTab) => unknown; +}; + +export const BrainDefinitionTabTrigger = ({ + label, + value, + selected, + onChange, +}: BrainDefinitionTabTriggerProps): JSX.Element => { + return ( + onChange(value)} + > + {label} + + ); +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/ParamsDefinition.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/ParamsDefinition.tsx new file mode 100644 index 000000000..521c411ee --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/ParamsDefinition.tsx @@ -0,0 +1,72 @@ +import { useFieldArray } from "react-hook-form"; +import { useTranslation } from "react-i18next"; +import { MdAdd } from "react-icons/md"; +import { TiInfoOutline } from "react-icons/ti"; + +import Button from "@/lib/components/ui/Button"; + +import { ParamDefinitionRow } from "./components/ParamDefinitionRow"; +import { defaultParamDefinitionRow } from "./config"; +import { useParamsDefinition } from "./hooks/useParamsDefinition"; +import { tabDescriptionStyle } from "../../styles"; + +type ParamsDefinitionProps = { + name: string; + description: string; +}; + +const paramsNameStyle = "flex flex-1 justify-center"; + +export const ParamsDefinition = ({ + name, + description, +}: ParamsDefinitionProps): JSX.Element => { + const { t } = useTranslation(["brain"]); + const { control, register } = useParamsDefinition({ + name, + }); + + const { fields, append, remove } = useFieldArray({ + control, + name, + }); + + return ( +
+
+ +

{description}

+
+ +
+
+
{t("api_brain.name")}
+
{t("api_brain.description")}
+
{t("api_brain.type")}
+
{t("api_brain.required")}
+
+
+ {fields.map((field, index) => ( + + ))} +
+ +
+
+ ); +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/components/ParamDefinitionRow.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/components/ParamDefinitionRow.tsx new file mode 100644 index 000000000..deae1c6d3 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/components/ParamDefinitionRow.tsx @@ -0,0 +1,79 @@ +import { UseFormRegister } from "react-hook-form"; +import { useTranslation } from "react-i18next"; +import { MdCancel } from "react-icons/md"; + +import { paramsNameStyle } from "../../styles"; +import { ParameterDefinition } from "../types"; + +type ParamControl = { + [name: string]: ParameterDefinition[]; +}; + +type ParamDefinitionRowProps = { + register: UseFormRegister; + index: number; + remove: (index: number) => void; + name: string; +}; + +export const ParamDefinitionRow = ({ + index, + remove, + register, + name, +}: ParamDefinitionRowProps): JSX.Element => { + const { t } = useTranslation(["brain"]); + + return ( +
+
+ +
+
+ +
+
+ +
+
+ +
+ + +
+ ); +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/config.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/config.ts new file mode 100644 index 000000000..a86b59fcc --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/config.ts @@ -0,0 +1,8 @@ +import { ParameterDefinition } from "./types"; + +export const defaultParamDefinitionRow: ParameterDefinition = { + name: "", + type: "string", + required: false, + description: "", +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/hooks/useParamsDefinition.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/hooks/useParamsDefinition.ts new file mode 100644 index 000000000..c239ac3e5 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/hooks/useParamsDefinition.ts @@ -0,0 +1,55 @@ +import { useEffect } from "react"; +import { useForm, useFormContext, useWatch } from "react-hook-form"; + +import { ApiBrainDefinitionSchema } from "@/lib/api/brain/types"; + +import { defaultParamDefinitionRow } from "../config"; +import { ParameterDefinition } from "../types"; +import { mapApiBrainDefinitionSchemaToParameterDefinition } from "../utils/mapApiBrainDefinitionSchemaToParameterDefinition"; +import { mapParameterDefinitionToApiBrainDefinitionSchema } from "../utils/mapParameterDefinitionToApiBrainDefinitionSchema"; + +type UseParamsDefinitionProps = { + name: string; +}; + +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types +export const useParamsDefinition = ({ name }: UseParamsDefinitionProps) => { + const { watch, register } = useFormContext(); + const existingParams = watch(name) as ApiBrainDefinitionSchema; + const existingProperties = + mapApiBrainDefinitionSchemaToParameterDefinition(existingParams); + + const { control } = useForm<{ + [name: string]: ParameterDefinition[]; + }>({ + defaultValues: { + [name]: + existingProperties.length > 0 + ? existingProperties + : [defaultParamDefinitionRow], + }, + }); + + const params = useWatch({ + control, + name, + }); + + const { setValue } = useFormContext(); + + useEffect(() => { + const paramsWithValues = params.filter( + (param) => param.name !== "" && param.description !== "" + ); + + setValue( + name, + mapParameterDefinitionToApiBrainDefinitionSchema(paramsWithValues) + ); + }, [params, name, setValue]); + + return { + control, + register, + }; +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/types.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/types.ts new file mode 100644 index 000000000..e816f3d84 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/types.ts @@ -0,0 +1,8 @@ +import { ApiBrainDefinitionSchemaPropertyType } from "@/lib/api/brain/types"; + +export type ParameterDefinition = { + name: string; + type: ApiBrainDefinitionSchemaPropertyType; + required: boolean; + description: string; +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/utils/mapApiBrainDefinitionSchemaToParameterDefinition.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/utils/mapApiBrainDefinitionSchemaToParameterDefinition.ts new file mode 100644 index 000000000..9728f2348 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/utils/mapApiBrainDefinitionSchemaToParameterDefinition.ts @@ -0,0 +1,23 @@ +import { ApiBrainDefinitionSchema } from "@/lib/api/brain/types"; + +import { ParameterDefinition } from "../types"; + +export const mapApiBrainDefinitionSchemaToParameterDefinition = ( + schema?: ApiBrainDefinitionSchema +): ParameterDefinition[] => { + if (schema === undefined) { + return []; + } + const { properties, required } = schema; + + return properties.map((property) => { + const { name, type, description } = property; + + return { + name, + type: type === "string" ? "string" : "number", + required: required.includes(name), + description, + }; + }); +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/utils/mapParameterDefinitionToApiBrainDefinitionSchema.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/utils/mapParameterDefinitionToApiBrainDefinitionSchema.ts new file mode 100644 index 000000000..289522de0 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/ParamsDefinition/utils/mapParameterDefinitionToApiBrainDefinitionSchema.ts @@ -0,0 +1,34 @@ +import { + ApiBrainDefinitionSchema, + ApiBrainDefinitionSchemaProperty, +} from "@/lib/api/brain/types"; + +import { ParameterDefinition } from "../types"; + +export const mapParameterDefinitionToApiBrainDefinitionSchema = ( + params: ParameterDefinition[] +): ApiBrainDefinitionSchema => { + const properties: ApiBrainDefinitionSchemaProperty[] = []; + const required: string[] = []; + + params.forEach((param) => { + const { name, type, required: isRequired, description } = param; + + const property: ApiBrainDefinitionSchemaProperty = { + name, + type: type === "string" ? "string" : "number", + description, + }; + + properties.push(property); + + if (isRequired) { + required.push(name); + } + }); + + return { + properties, + required, + }; +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/SecretsDefinition.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/SecretsDefinition.tsx new file mode 100644 index 000000000..8df8b0a69 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/SecretsDefinition.tsx @@ -0,0 +1,66 @@ +import { useFieldArray } from "react-hook-form"; +import { useTranslation } from "react-i18next"; +import { MdAdd } from "react-icons/md"; +import { TiInfoOutline } from "react-icons/ti"; + +import Button from "@/lib/components/ui/Button"; + +import { SecretDefinitionRow } from "./components/SecretDefinitionRow"; +import { + brainSecretsSchemaDefinitionKeyInForm, + defaultSecretDefinitionRow, +} from "./config"; +import { useSecretsDefinition } from "./hooks/useSecretsDefinition"; +import { tabDescriptionStyle } from "../../styles"; + +const paramsNameStyle = "flex flex-1 justify-center"; + +export const SecretsDefinition = (): JSX.Element => { + const { t } = useTranslation(["brain", "external_api_definition"]); + + const { control, register } = useSecretsDefinition(); + + const { fields, append, remove } = useFieldArray({ + control, + name: brainSecretsSchemaDefinitionKeyInForm, + }); + + return ( +
+
+ +

+ {t("secretsTabDescription", { ns: "external_api_definition" })} +

+
+
+
+
{t("api_brain.name")}
+
{t("api_brain.description")}
+
{t("api_brain.type")}
+
{t("api_brain.value")}
+
+
+ {fields.map((field, index) => ( + + ))} +
+ +
+
+ ); +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/components/SecretDefinitionRow.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/components/SecretDefinitionRow.tsx new file mode 100644 index 000000000..ffd83115d --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/components/SecretDefinitionRow.tsx @@ -0,0 +1,81 @@ +import { UseFormRegister } from "react-hook-form"; +import { useTranslation } from "react-i18next"; +import { MdCancel } from "react-icons/md"; + +import { paramsNameStyle } from "../../styles"; +import { brainSecretsSchemaDefinitionKeyInForm } from "../config"; +import { SecretDefinition } from "../types"; + +type SecretControl = { + [name: string]: SecretDefinition[]; +}; + +type SecretDefinitionRowProps = { + register: UseFormRegister; + index: number; + remove: (index: number) => void; +}; + +export const SecretDefinitionRow = ({ + index, + remove, + register, +}: SecretDefinitionRowProps): JSX.Element => { + const { t } = useTranslation(["brain"]); + + return ( +
+
+ +
+
+ +
+
+ +
+
+ +
+ + +
+ ); +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/config.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/config.ts new file mode 100644 index 000000000..e0fb126d7 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/config.ts @@ -0,0 +1,11 @@ +import { SecretDefinition } from "./types"; + +export const defaultSecretDefinitionRow: SecretDefinition = { + name: "", + type: "string", + value: "", + description: "", +}; + +export const brainSecretsSchemaDefinitionKeyInForm = "brain_definition.secrets"; +export const brainSecretsValueKeyInForm = "brain_secrets_values"; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/hooks/useSecretsDefinition.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/hooks/useSecretsDefinition.ts new file mode 100644 index 000000000..a6d6b4aa1 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/hooks/useSecretsDefinition.ts @@ -0,0 +1,67 @@ +import { useEffect } from "react"; +import { useForm, useFormContext, useWatch } from "react-hook-form"; + +import { + brainSecretsSchemaDefinitionKeyInForm, + brainSecretsValueKeyInForm, + defaultSecretDefinitionRow, +} from "../config"; +import { SecretDefinition, SecretRelatedFields } from "../types"; +import { mapSecretDefinitionToApiBrainSecretsDefinitionsAndValue } from "../utils/mapSecretDefinitionToApiBrainSecretDefinition"; +import { mapSecretsDefinitionsAndValuesToSecretDefinition } from "../utils/mapSecretsDefinitionsAndValuesToSecretDefinition"; + +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types +export const useSecretsDefinition = () => { + const { getValues: getContextValues } = useFormContext<{ + [brainSecretsSchemaDefinitionKeyInForm]: SecretDefinition[]; + [brainSecretsValueKeyInForm]: Record; + }>(); + const { setValue } = useFormContext(); + + const { register, control } = useForm({ + defaultValues: { + [brainSecretsSchemaDefinitionKeyInForm]: [defaultSecretDefinitionRow], + }, + }); + + useEffect(() => { + const existingSecretsDefinitionsSchemas = getContextValues( + brainSecretsSchemaDefinitionKeyInForm + ); + const existingSecretsValues = getContextValues(brainSecretsValueKeyInForm); + + const secretDefinition = mapSecretsDefinitionsAndValuesToSecretDefinition( + existingSecretsDefinitionsSchemas, + existingSecretsValues + ); + if (secretDefinition.length === 0) { + return; + } + setValue(brainSecretsSchemaDefinitionKeyInForm, secretDefinition); + }, [getContextValues, setValue]); + + const secretsDefinitionSchemas = useWatch({ + control, + name: brainSecretsSchemaDefinitionKeyInForm, + }) as SecretDefinition[] | undefined; + + useEffect(() => { + if (secretsDefinitionSchemas === undefined) { + return; + } + const paramsWithValues = secretsDefinitionSchemas.filter( + (param) => param.name !== "" && param.description !== "" + ); + + const { secrets, brain_secrets_values } = + mapSecretDefinitionToApiBrainSecretsDefinitionsAndValue(paramsWithValues); + + setValue(brainSecretsSchemaDefinitionKeyInForm, secrets); + setValue(brainSecretsValueKeyInForm, brain_secrets_values); + }, [secretsDefinitionSchemas, setValue]); + + return { + control, + register, + }; +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/types.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/types.ts new file mode 100644 index 000000000..28afea2e5 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/types.ts @@ -0,0 +1,12 @@ +import { ApiBrainDefinitionSchemaPropertyType } from "@/lib/api/brain/types"; + +export type SecretDefinition = { + name: string; + type: ApiBrainDefinitionSchemaPropertyType; + description: string; + value: string; +}; + +export type SecretRelatedFields = { + [name: string]: SecretDefinition[]; +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/utils/mapSecretDefinitionToApiBrainSecretDefinition.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/utils/mapSecretDefinitionToApiBrainSecretDefinition.ts new file mode 100644 index 000000000..b61337fd6 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/utils/mapSecretDefinitionToApiBrainSecretDefinition.ts @@ -0,0 +1,31 @@ +import { ApiBrainDefinitionSecret } from "@/lib/api/brain/types"; + +import { SecretDefinition } from "../types"; + +export type ApiBrainSecretsDefinitionsAndValues = { + secrets: ApiBrainDefinitionSecret[]; + brain_secrets_values: Record; +}; + +export const mapSecretDefinitionToApiBrainSecretsDefinitionsAndValue = ( + secretDefinitions: SecretDefinition[] +): ApiBrainSecretsDefinitionsAndValues => { + const secrets: ApiBrainDefinitionSecret[] = secretDefinitions.map( + (secretDefinition) => { + const { name, type } = secretDefinition; + + return { name, type }; + } + ); + + const brain_secrets_values: Record = secretDefinitions.reduce( + (acc, secretDefinition) => { + const { name, value } = secretDefinition; + + return { ...acc, [name]: value }; + }, + {} + ); + + return { secrets, brain_secrets_values }; +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/utils/mapSecretsDefinitionsAndValuesToSecretDefinition.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/utils/mapSecretsDefinitionsAndValuesToSecretDefinition.ts new file mode 100644 index 000000000..d2a905175 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/SecretsDefinition/utils/mapSecretsDefinitionsAndValuesToSecretDefinition.ts @@ -0,0 +1,29 @@ +import { ApiBrainDefinition } from "@/lib/api/brain/types"; + +import { defaultSecretDefinitionRow } from "../config"; +import { SecretDefinition } from "../types"; + +export const mapSecretsDefinitionsAndValuesToSecretDefinition = ( + apiBrainDefinition?: ApiBrainDefinition, + brainSecretsValue?: Record +): SecretDefinition[] => { + if ( + apiBrainDefinition === undefined || + brainSecretsValue === undefined || + apiBrainDefinition.secrets === undefined || + apiBrainDefinition.secrets.length === 0 + ) { + return [defaultSecretDefinitionRow]; + } + + const secrets = apiBrainDefinition.secrets; + + const secretDefinition: SecretDefinition[] = secrets.map((secret) => { + const { name, type } = secret; + const value = brainSecretsValue[name] ?? ""; + + return { name, type, description: "", value }; + }); + + return secretDefinition; +}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/styles.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/styles.ts new file mode 100644 index 000000000..44c839645 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/components/styles.ts @@ -0,0 +1 @@ +export const paramsNameStyle = "flex flex-1 justify-center"; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/hooks/useApiDefinitionTabs.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/hooks/useApiRequestDefinition.tsx similarity index 63% rename from frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/hooks/useApiDefinitionTabs.tsx rename to frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/hooks/useApiRequestDefinition.tsx index 854da6de9..8f0fd8c93 100644 --- a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/hooks/useApiDefinitionTabs.tsx +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/hooks/useApiRequestDefinition.tsx @@ -3,8 +3,8 @@ import { useState } from "react"; import { ApiTab } from "../types"; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export const useApiDefinitionTabs = () => { - const [selectedTab, setSelectedTab] = useState("searchParams"); +export const useApiRequestDefinition = () => { + const [selectedTab, setSelectedTab] = useState("params"); return { selectedTab, diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/styles.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/styles.ts new file mode 100644 index 000000000..d39e7d9d1 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/styles.ts @@ -0,0 +1 @@ +export const tabDescriptionStyle = "flex items-center text-gray-500 my-3"; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/HeadersDefinition.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/HeadersDefinition.tsx deleted file mode 100644 index d422d1b1d..000000000 --- a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/HeadersDefinition.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export const HeadersDefinition = (): JSX.Element => { - return <>; -}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/ParamsDefinition.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/ParamsDefinition.tsx deleted file mode 100644 index 55871763f..000000000 --- a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/ParamsDefinition.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export const ParamsDefinition = (): JSX.Element => { - return <>; -}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/SearchParamsDefinition.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/SearchParamsDefinition.tsx deleted file mode 100644 index 58cb50a3b..000000000 --- a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/tabs/SearchParamsDefinition.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export const SearchParamsDefinition = (): JSX.Element => { - return <>; -}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/types.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/types.ts index 698393d87..0fb7dd5cf 100644 --- a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/types.ts +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/components/ApiRequestDefinition/types.ts @@ -1,3 +1,3 @@ -export const apiTabs = ["searchParams", "headers", "params"] as const; +export const apiTabs = ["params", "searchParams", "secrets"] as const; export type ApiTab = (typeof apiTabs)[number]; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/hooks/useAddBrainConfig.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/hooks/useAddBrainConfig.ts index b3d781146..641f89446 100644 --- a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/hooks/useAddBrainConfig.ts +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/hooks/useAddBrainConfig.ts @@ -10,12 +10,12 @@ import { useBrainApi } from "@/lib/api/brain/useBrainApi"; import { usePromptApi } from "@/lib/api/prompt/usePromptApi"; import { USER_DATA_KEY } from "@/lib/api/user/config"; import { useUserApi } from "@/lib/api/user/useUserApi"; -import { defaultBrainConfig } from "@/lib/config/defaultBrainConfig"; import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext"; import { defineMaxTokens } from "@/lib/helpers/defineMaxTokens"; import { getAccessibleModels } from "@/lib/helpers/getAccessibleModels"; import { useToast } from "@/lib/hooks"; -import { BrainConfig } from "@/lib/types/brainConfig"; + +import { CreateBrainProps } from "../types"; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export const useAddBrainConfig = () => { @@ -38,17 +38,6 @@ export const useAddBrainConfig = () => { queryFn: getUser, }); - const defaultValues = { - ...defaultBrainConfig, - name: "", - description: "", - setDefault: false, - prompt: { - title: "", - content: "", - }, - }; - const { register, getValues, @@ -56,14 +45,14 @@ export const useAddBrainConfig = () => { watch, setValue, formState: { dirtyFields }, - } = useFormContext(); + } = useFormContext(); - const openAiKey = watch("openAiKey"); + const openAiKey = watch("openai_api_key"); const model = watch("model"); const temperature = watch("temperature"); - const maxTokens = watch("maxTokens"); + const maxTokens = watch("max_tokens"); const status = watch("status"); - const brainType = watch("brainType"); + const brainType = watch("brain_type"); const accessibleModels = getAccessibleModels({ openAiKey, @@ -77,7 +66,9 @@ export const useAddBrainConfig = () => { }, [dirtyFields.status, status]); useEffect(() => { - setValue("maxTokens", Math.min(maxTokens, defineMaxTokens(model))); + if (maxTokens !== undefined && model !== undefined) { + setValue("max_tokens", Math.min(maxTokens, defineMaxTokens(model))); + } }, [maxTokens, model, setValue]); const getCreatingBrainPromptId = async (): Promise => { @@ -91,7 +82,13 @@ export const useAddBrainConfig = () => { }; const handleSubmit = async () => { - const { name, description, setDefault } = getValues(); + const { + name, + description, + setDefault, + brain_definition, + brain_secrets_values, + } = getValues(); if (name.trim() === "" || isPending) { publish({ @@ -117,6 +114,8 @@ export const useAddBrainConfig = () => { prompt_id, status, brain_type: brainType, + brain_definition, + brain_secrets_values, }); if (createdBrainId === undefined) { @@ -135,7 +134,7 @@ export const useAddBrainConfig = () => { } setIsShareModalOpen(false); - reset(defaultValues); + reset(); publish({ variant: "success", text: t("brainCreated", { ns: "brain" }), diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainConfig/types.ts b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/types.ts new file mode 100644 index 000000000..691ce05e8 --- /dev/null +++ b/frontend/lib/components/AddBrainModal/components/AddBrainConfig/types.ts @@ -0,0 +1,7 @@ +import { CreateBrainInput } from "@/lib/api/brain/types"; +import { CreatePromptProps } from "@/lib/api/prompt/prompt"; + +export type CreateBrainProps = CreateBrainInput & { + prompt: CreatePromptProps; + setDefault: boolean; +}; diff --git a/frontend/lib/config/defaultBrainConfig.ts b/frontend/lib/config/defaultBrainConfig.ts index 16db83cbb..56d201337 100644 --- a/frontend/lib/config/defaultBrainConfig.ts +++ b/frontend/lib/config/defaultBrainConfig.ts @@ -1,5 +1,18 @@ +import { CreateBrainInput } from "../api/brain/types"; import { BrainConfig } from "../types/brainConfig"; +export const addBrainDefaultValues: CreateBrainInput = { + model: "gpt-3.5-turbo", + temperature: 0, + max_tokens: 500, + openai_api_key: undefined, + prompt_id: undefined, + status: "private", + name: "", + description: "", + brain_type: "doc", +}; + export const defaultBrainConfig: BrainConfig = { model: "gpt-3.5-turbo", temperature: 0, diff --git a/frontend/lib/context/BrainProvider/hooks/useBrainProvider.ts b/frontend/lib/context/BrainProvider/hooks/useBrainProvider.ts index fc73539c1..ca9c0ea99 100644 --- a/frontend/lib/context/BrainProvider/hooks/useBrainProvider.ts +++ b/frontend/lib/context/BrainProvider/hooks/useBrainProvider.ts @@ -51,7 +51,10 @@ export const useBrainProvider = () => { try { setCurrentBrainId(createdBrain.id); - void track("BRAIN_CREATED"); + void track("BRAIN_CREATED", { + brainType: brain.brain_type, + }); + void fetchAllBrains(); return createdBrain.id; diff --git a/frontend/lib/helpers/defineMaxTokens.ts b/frontend/lib/helpers/defineMaxTokens.ts index 60b1cd527..985fac007 100644 --- a/frontend/lib/helpers/defineMaxTokens.ts +++ b/frontend/lib/helpers/defineMaxTokens.ts @@ -1,6 +1,8 @@ import { Model, PaidModels } from "../types/brainConfig"; -export const defineMaxTokens = (model: Model | PaidModels): number => { +export const defineMaxTokens = ( + model: Model | PaidModels | undefined +): number => { //At the moment is evaluating only models from OpenAI switch (model) { case "gpt-3.5-turbo": diff --git a/frontend/lib/types/brainConfig.ts b/frontend/lib/types/brainConfig.ts index b9cb41434..1302efa8b 100644 --- a/frontend/lib/types/brainConfig.ts +++ b/frontend/lib/types/brainConfig.ts @@ -6,6 +6,8 @@ export const brainTypes = ["doc", "api"] as const; export type BrainType = (typeof brainTypes)[number]; +export type Model = (typeof freeModels)[number]; + export type BrainConfig = { model: Model; temperature: number; @@ -57,5 +59,3 @@ export const freeModels = [ export const paidModels = [...openAiPaidModels] as const; export type PaidModels = (typeof paidModels)[number]; - -export type Model = (typeof freeModels)[number]; diff --git a/frontend/public/locales/en/brain.json b/frontend/public/locales/en/brain.json index ce68b60c0..a864edbfa 100644 --- a/frontend/public/locales/en/brain.json +++ b/frontend/public/locales/en/brain.json @@ -49,5 +49,13 @@ "myBrains": "My Brains", "knowledge_source_doc": "Documents", "knowledge_source_api": "API", - "knowledge_source_label": "Knowledge source" + "knowledge_source_label": "Knowledge source", + "api_brain":{ + "name": "Name", + "description": "Description", + "type": "Type", + "required": "Required", + "addRow": "Add row", + "value": "Value" + } } diff --git a/frontend/public/locales/en/external_api_definition.json b/frontend/public/locales/en/external_api_definition.json index bbd9ac46d..55e212061 100644 --- a/frontend/public/locales/en/external_api_definition.json +++ b/frontend/public/locales/en/external_api_definition.json @@ -6,5 +6,9 @@ "params": "Params", "key": "Key", "type": "Type (string or number)", - "description": "Description" + "description": "Description", + "secrets": "Secrets", + "paramsTabDescription": "These values are sent as the request body.", + "searchParamsTabDescription": "These values are sent as the query string.", + "secretsTabDescription": "These values are sent as header keys" } diff --git a/frontend/public/locales/es/brain.json b/frontend/public/locales/es/brain.json index 6103d669d..885e344ac 100644 --- a/frontend/public/locales/es/brain.json +++ b/frontend/public/locales/es/brain.json @@ -49,5 +49,13 @@ "myBrains": "Mis cerebros", "knowledge_source_doc": "Documentos", "knowledge_source_api": "API", - "knowledge_source_label": "Fuente de conocimiento" + "knowledge_source_label": "Fuente de conocimiento", + "api_brain":{ + "name": "Nombre", + "description": "Descripción", + "type": "Tipo", + "required": "Requerido", + "addRow": "Agregar fila", + "value": "Valor" + } } diff --git a/frontend/public/locales/es/external_api_definition.json b/frontend/public/locales/es/external_api_definition.json index bbd9ac46d..af1364d37 100644 --- a/frontend/public/locales/es/external_api_definition.json +++ b/frontend/public/locales/es/external_api_definition.json @@ -6,5 +6,9 @@ "params": "Params", "key": "Key", "type": "Type (string or number)", - "description": "Description" + "description": "Description", + "secrets": "Secretos", + "paramsTabDescription": "Estos valores se envían como cuerpo de la solicitud.", + "searchParamsTabDescription": "Estos valores se envían como cadena de consulta.", + "secretsTabDescription": "Estos valores se envían como claves de encabezado." } diff --git a/frontend/public/locales/fr/brain.json b/frontend/public/locales/fr/brain.json index 81681e5cb..1e4154ad6 100644 --- a/frontend/public/locales/fr/brain.json +++ b/frontend/public/locales/fr/brain.json @@ -49,5 +49,13 @@ "myBrains": "Mes cerveaux", "knowledge_source_doc": "Documents", "knowledge_source_api": "API", - "knowledge_source_label": "Source de connaissance" + "knowledge_source_label": "Source de connaissance", + "api_brain":{ + "name": "Nom", + "description": "Description", + "type": "Type", + "required": "Requis", + "addRow": "Ajouter une ligne", + "value": "Valeur" + } } diff --git a/frontend/public/locales/fr/external_api_definition.json b/frontend/public/locales/fr/external_api_definition.json index bbd9ac46d..482d380f5 100644 --- a/frontend/public/locales/fr/external_api_definition.json +++ b/frontend/public/locales/fr/external_api_definition.json @@ -6,5 +6,9 @@ "params": "Params", "key": "Key", "type": "Type (string or number)", - "description": "Description" + "description": "Description", + "secrets": "Secrets", + "paramsTabDescription": "Ces valeurs sont envoyées sous forme de corps de requête.", + "searchParamsTabDescription": "Ces valeurs sont envoyées sous forme de chaîne de requête.", + "secretsTabDescription": "Ces valeurs sont envoyées sous forme de clés d'en-tête." } diff --git a/frontend/public/locales/pt-br/brain.json b/frontend/public/locales/pt-br/brain.json index 533ca8ca8..9565adfa7 100644 --- a/frontend/public/locales/pt-br/brain.json +++ b/frontend/public/locales/pt-br/brain.json @@ -49,5 +49,13 @@ "myBrains": "Meus cérebros", "knowledge_source_doc": "Documentos", "knowledge_source_api": "API", - "knowledge_source_label": "Fonte de conhecimento" + "knowledge_source_label": "Fonte de conhecimento", + "api_brain":{ + "name": "Name", + "description": "Description", + "type": "Type", + "required": "Required", + "addRow": "Add row", + "value": "Value" + } } diff --git a/frontend/public/locales/pt-br/external_api_definition.json b/frontend/public/locales/pt-br/external_api_definition.json index bbd9ac46d..fdc0b0186 100644 --- a/frontend/public/locales/pt-br/external_api_definition.json +++ b/frontend/public/locales/pt-br/external_api_definition.json @@ -6,5 +6,9 @@ "params": "Params", "key": "Key", "type": "Type (string or number)", - "description": "Description" + "description": "Description", + "secrets": "Secrets", + "paramsTabDescription": "Estes valores são enviados como corpo da solicitação.", + "searchParamsTabDescription": "Estes valores são enviados como string de consulta.", + "secretsTabDescription": "Estes valores são enviados como chaves de cabeçalho" } diff --git a/frontend/public/locales/ru/brain.json b/frontend/public/locales/ru/brain.json index d3c160739..c50c7d453 100644 --- a/frontend/public/locales/ru/brain.json +++ b/frontend/public/locales/ru/brain.json @@ -49,5 +49,13 @@ "myBrains": "Мои мозги", "knowledge_source_doc": "Документы", "knowledge_source_api": "API", - "knowledge_source_label": "Источник знаний" + "knowledge_source_label": "Источник знаний", + "api_brain":{ + "name": "Название", + "description": "Описание", + "type": "Тип", + "required": "Обязательно", + "addRow": "Добавить строку", + "value": "Значение" + } } diff --git a/frontend/public/locales/ru/external_api_definition.json b/frontend/public/locales/ru/external_api_definition.json index bbd9ac46d..aacac9580 100644 --- a/frontend/public/locales/ru/external_api_definition.json +++ b/frontend/public/locales/ru/external_api_definition.json @@ -6,5 +6,9 @@ "params": "Params", "key": "Key", "type": "Type (string or number)", - "description": "Description" + "description": "Description", + "secrets": "секреты", + "paramsTabDescription": "Эти значения отправляются в теле запроса.", + "searchParamsTabDescription": "Эти значения отправляются в виде строки запроса.", + "secretsTabDescription": "Эти значения отправляются в виде ключей заголовка." } diff --git a/frontend/public/locales/zh-cn/brain.json b/frontend/public/locales/zh-cn/brain.json index 578c71ab7..6ca9b25c0 100644 --- a/frontend/public/locales/zh-cn/brain.json +++ b/frontend/public/locales/zh-cn/brain.json @@ -49,5 +49,13 @@ "myBrains": "我的大脑", "knowledge_source_doc": "文档", "knowledge_source_api": "API", - "knowledge_source_label": "知识来源" + "knowledge_source_label": "知识来源", + "api_brain":{ + "name": "名称", + "description": "描述", + "type": "类型", + "required": "必填", + "addRow": "添加行", + "value": "值" + } } diff --git a/frontend/public/locales/zh-cn/external_api_definition.json b/frontend/public/locales/zh-cn/external_api_definition.json index bbd9ac46d..0b7b8c4c2 100644 --- a/frontend/public/locales/zh-cn/external_api_definition.json +++ b/frontend/public/locales/zh-cn/external_api_definition.json @@ -6,5 +6,9 @@ "params": "Params", "key": "Key", "type": "Type (string or number)", - "description": "Description" + "description": "Description", + "secrets": "秘密", + "paramsTabDescription": "这些值作为请求体发送。", + "searchParamsTabDescription": "这些值作为查询字符串发送。", + "secretsTabDescription": "这些值作为头部键发送。" }