Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(ee): add customizable default model adapter base urls (#3542)

Marc Klingenfb8f26a00edc
diff --git a/.env.prod.example b/.env.prod.example
index 31cc87e965..2ce3f6b64e 100644
--- a/.env.prod.example
+++ b/.env.prod.example
@@ -141,6 +141,10 @@ ENCRYPTION_KEY="0000000000000000000000000000000000000000000000000000000000000000
# LANGFUSE_UI_FEEDBACK_HREF=https://feedback.example.com
# LANGFUSE_UI_LOGO_LIGHT_MODE_HREF=https://static.langfuse.com/langfuse-dev/example-logo-light-mode.png
# LANGFUSE_UI_LOGO_DARK_MODE_HREF=https://static.langfuse.com/langfuse-dev/example-logo-dark-mode.png
+# LANGFUSE_UI_DEFAULT_MODEL_ADAPTER=Anthropic # OpenAI, Anthropic, Azure
+# LANGFUSE_UI_DEFAULT_BASE_URL_OPENAI=https://api.openai.com/v1
+# LANGFUSE_UI_DEFAULT_BASE_URL_ANTHROPIC=https://api.anthropic.com
+# LANGFUSE_UI_DEFAULT_BASE_URL_AZURE_OPENAI=https://{instanceName}.openai.azure.com/openai/deployments
### END Enterprise Edition Configuration
diff --git a/web/src/ee/features/ui-customization/uiCustomizationRouter.ts b/web/src/ee/features/ui-customization/uiCustomizationRouter.ts
index bb40e07929..539223beff 100644
--- a/web/src/ee/features/ui-customization/uiCustomizationRouter.ts
+++ b/web/src/ee/features/ui-customization/uiCustomizationRouter.ts
@@ -12,6 +12,10 @@ export const uiCustomizationRouter = createTRPCRouter({
feedbackHref: env.LANGFUSE_UI_FEEDBACK_HREF,
logoLightModeHref: env.LANGFUSE_UI_LOGO_LIGHT_MODE_HREF,
logoDarkModeHref: env.LANGFUSE_UI_LOGO_DARK_MODE_HREF,
+ defaultModelAdapter: env.LANGFUSE_UI_DEFAULT_MODEL_ADAPTER,
+ defaultBaseUrlOpenAI: env.LANGFUSE_UI_DEFAULT_BASE_URL_OPENAI,
+ defaultBaseUrlAnthropic: env.LANGFUSE_UI_DEFAULT_BASE_URL_ANTHROPIC,
+ defaultBaseUrlAzure: env.LANGFUSE_UI_DEFAULT_BASE_URL_AZURE,
};
}),
});
diff --git a/web/src/env.mjs b/web/src/env.mjs
index 095f1a859d..b2b834eb0c 100644
--- a/web/src/env.mjs
+++ b/web/src/env.mjs
@@ -122,6 +122,10 @@ export const env = createEnv({
LANGFUSE_UI_FEEDBACK_HREF: z.string().url().optional(),
LANGFUSE_UI_LOGO_LIGHT_MODE_HREF: z.string().url().optional(),
LANGFUSE_UI_LOGO_DARK_MODE_HREF: z.string().url().optional(),
+ LANGFUSE_UI_DEFAULT_MODEL_ADAPTER: z.enum(["OpenAI", "Anthropic", "Azure"]).optional(),
+ LANGFUSE_UI_DEFAULT_BASE_URL_OPENAI: z.string().url().optional(),
+ LANGFUSE_UI_DEFAULT_BASE_URL_ANTHROPIC: z.string().url().optional(),
+ LANGFUSE_UI_DEFAULT_BASE_URL_AZURE: z.string().url().optional(),
// EE License
LANGFUSE_EE_LICENSE_KEY: z.string().optional(),
ADMIN_API_KEY: z.string().optional(),
@@ -339,6 +343,14 @@ export const env = createEnv({
process.env.LANGFUSE_UI_LOGO_LIGHT_MODE_HREF,
LANGFUSE_UI_LOGO_DARK_MODE_HREF:
process.env.LANGFUSE_UI_LOGO_DARK_MODE_HREF,
+ LANGFUSE_UI_DEFAULT_MODEL_ADAPTER:
+ process.env.LANGFUSE_UI_DEFAULT_MODEL_ADAPTER,
+ LANGFUSE_UI_DEFAULT_BASE_URL_OPENAI:
+ process.env.LANGFUSE_UI_DEFAULT_BASE_URL_OPENAI,
+ LANGFUSE_UI_DEFAULT_BASE_URL_ANTHROPIC:
+ process.env.LANGFUSE_UI_DEFAULT_BASE_URL_ANTHROPIC,
+ LANGFUSE_UI_DEFAULT_BASE_URL_AZURE:
+ process.env.LANGFUSE_UI_DEFAULT_BASE_URL_AZURE,
// EE License
LANGFUSE_EE_LICENSE_KEY: process.env.LANGFUSE_EE_LICENSE_KEY,
ADMIN_API_KEY: process.env.ADMIN_API_KEY,
diff --git a/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx b/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx
index 9e3a129c3e..733822eb40 100644
--- a/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx
+++ b/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx
@@ -1,7 +1,5 @@
-import { PlusIcon, TrashIcon } from "lucide-react";
+import { PlusIcon } from "lucide-react";
import { useState } from "react";
-import { useFieldArray, useForm } from "react-hook-form";
-import { z } from "zod";
import { Button } from "@/src/components/ui/button";
import {
@@ -11,48 +9,10 @@ import {
DialogTitle,
DialogTrigger,
} from "@/src/components/ui/dialog";
-import {
- Form,
- FormControl,
- FormDescription,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@/src/components/ui/form";
-import { Input } from "@/src/components/ui/input";
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "@/src/components/ui/select";
-import { Switch } from "@/src/components/ui/switch";
-import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
-import { api } from "@/src/utils/api";
-import { cn } from "@/src/utils/tailwind";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { LLMAdapter } from "@langfuse/shared";
import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL";
-
-const formSchema = z
- .object({
- secretKey: z.string().min(1),
- provider: z
- .string()
- .min(1, "Please add a provider name that identifies this connection."),
- adapter: z.nativeEnum(LLMAdapter),
- baseURL: z.union([z.literal(""), z.string().url()]),
- withDefaultModels: z.boolean(),
- customModels: z.array(z.object({ value: z.string().min(1) })),
- })
- .refine((data) => data.withDefaultModels || data.customModels.length > 0, {
- message:
- "At least one custom model name is required when default models are disabled.",
- path: ["withDefaultModels"],
- });
+import { useUiCustomization } from "@/src/ee/features/ui-customization/useUiCustomization";
+import { CreateLLMApiKeyForm } from "@/src/features/public-api/components/CreateLLMApiKeyForm";
export function CreateLLMApiKeyDialog({
evalModelsOnly,
@@ -60,113 +20,25 @@ export function CreateLLMApiKeyDialog({
evalModelsOnly?: boolean;
}) {
const projectId = useProjectIdFromURL();
- const capture = usePostHogClientCapture();
- const utils = api.useUtils();
const [open, setOpen] = useState(false);
const hasAccess = useHasProjectAccess({
projectId,
scope: "llmApiKeys:create",
});
-
- const existingKeys = api.llmApiKey.all.useQuery(
- {
- projectId: projectId as string,
- },
- { enabled: Boolean(projectId) },
- );
-
- const mutCreateLlmApiKey = api.llmApiKey.create.useMutation({
- onSuccess: () => utils.llmApiKey.invalidate(),
- });
-
- const mutTestLLMApiKey = api.llmApiKey.test.useMutation();
-
- const form = useForm<z.infer<typeof formSchema>>({
- resolver: zodResolver(formSchema),
- defaultValues: {
- adapter: LLMAdapter.OpenAI,
- provider: "",
- secretKey: "",
- baseURL: "",
- withDefaultModels: true,
- customModels: [],
- },
- });
-
- const currentAdapter = form.watch("adapter");
-
- const { fields, append, remove } = useFieldArray({
- control: form.control,
- name: "customModels",
- });
+ const uiCustomization = useUiCustomization();
+ console.log("uiCustomization", uiCustomization);
if (!hasAccess) return null;
- async function onSubmit(values: z.infer<typeof formSchema>) {
- if (!projectId) return console.error("No project ID found.");
- if (
- existingKeys?.data?.data.map((k) => k.provider).includes(values.provider)
- ) {
- form.setError("provider", {
- type: "manual",
- message: "There already exists an API key for this provider.",
- });
- return;
- }
- capture("project_settings:llm_api_key_create", {
- provider: values.provider,
- });
-
- const newKey = {
- projectId,
- secretKey: values.secretKey,
- provider: values.provider,
- adapter: values.adapter,
- baseURL: values.baseURL || undefined,
- withDefaultModels: values.withDefaultModels,
- customModels: values.customModels
- .map((m) => m.value.trim())
- .filter(Boolean),
- };
-
- try {
- const testResult = await mutTestLLMApiKey.mutateAsync(newKey);
-
- if (!testResult.success) throw new Error(testResult.error);
- } catch (error) {
- console.error(error);
- form.setError("secretKey", {
- type: "manual",
- message:
- error instanceof Error
- ? error.message
- : "Could not verify the API key.",
- });
-
- return;
- }
-
- return mutCreateLlmApiKey
- .mutateAsync(newKey)
- .then(() => {
- form.reset();
- setOpen(false);
- })
- .catch((error) => {
- console.error(error);
- });
- }
-
return (
<Dialog
open={open}
onOpenChange={(isOpen) => {
- form.reset();
setOpen(isOpen);
}}
>
<DialogTrigger asChild>
- <Button variant="secondary" loading={mutCreateLlmApiKey.isLoading}>
+ <Button variant="secondary">
<PlusIcon className="-ml-0.5 mr-1.5 h-5 w-5" aria-hidden="true" />
Add new LLM API key
</Button>
@@ -175,225 +47,14 @@ export function CreateLLMApiKeyDialog({
<DialogHeader>
<DialogTitle>Add new LLM API key</DialogTitle>
</DialogHeader>
- <Form {...form}>
- <form
- className={cn("flex flex-col gap-6 overflow-auto pb-2 pl-1 pr-4")}
- onSubmit={form.handleSubmit(onSubmit)}
- >
- {/* Provider name */}
- <FormField
- control={form.control}
- name="provider"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Provider name</FormLabel>
- <FormDescription>
- Name to identify the key within Langfuse.
- </FormDescription>
- <FormControl>
- <Input {...field} placeholder="OpenAI" />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* LLM adapter */}
- <FormField
- control={form.control}
- name="adapter"
- render={({ field }) => (
- <FormItem>
- <FormLabel>LLM adapter</FormLabel>
- <FormDescription>
- Schema that is accepted at that provider endpoint.
- </FormDescription>
- <Select
- defaultValue={field.value}
- onValueChange={(value) =>
- field.onChange(value as LLMAdapter)
- }
- >
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="Select a LLM provider" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {Object.values(LLMAdapter)
- .filter(
- (provider) =>
- !evalModelsOnly ||
- provider === LLMAdapter.OpenAI ||
- provider === LLMAdapter.Azure,
- )
- .map((provider) => (
- <SelectItem value={provider} key={provider}>
- {provider}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* baseURL */}
- <FormField
- control={form.control}
- name="baseURL"
- render={({ field }) => (
- <FormItem>
- <FormLabel>API Base URL</FormLabel>
- <FormDescription>
- Leave blank to use the default base URL for the given LLM
- adapter.{" "}
- {currentAdapter === LLMAdapter.OpenAI && (
- <span>OpenAI default: https://api.openai.com/v1</span>
- )}
- {currentAdapter === LLMAdapter.Azure && (
- <span>
- Please add the base URL in the following format (or
- compatible API):
- https://&#123;instanceName&#125;.openai.azure.com/openai/deployments
- </span>
- )}
- {currentAdapter === LLMAdapter.Anthropic && (
- <span>
- Anthropic default: https://api.anthropic.com (excluding
- /v1/messages)
- </span>
- )}
- </FormDescription>
-
- <FormControl>
- <Input {...field} placeholder="default" />
- </FormControl>
-
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* API key */}
- <FormField
- control={form.control}
- name="secretKey"
- render={({ field }) => (
- <FormItem>
- <FormLabel>API Key</FormLabel>
- <FormDescription>
- Your API keys are stored encrypted on our servers.
- </FormDescription>
- <FormControl>
- <Input placeholder="sk-proj-...Uwj9" {...field} />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* With default models */}
- <FormField
- control={form.control}
- name="withDefaultModels"
- render={({ field }) => (
- <FormItem>
- <span className="row flex">
- <span className="flex-1">
- <FormLabel>Enable default models</FormLabel>
- <FormDescription>
- Default models for the selected adapter will be
- available in Langfuse features.
- </FormDescription>
- {currentAdapter === LLMAdapter.Azure && (
- <FormDescription className="text-dark-yellow">
- Azure LLM adapter does not support default models.
- Please add a custom model with your deployment name.
- </FormDescription>
- )}
- </span>
-
- <FormControl>
- <Switch
- disabled={currentAdapter === LLMAdapter.Azure}
- checked={
- currentAdapter === LLMAdapter.Azure
- ? false
- : field.value
- }
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </span>
-
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Custom model names */}
- <FormField
- control={form.control}
- name="customModels"
- render={() => (
- <FormItem>
- <FormLabel>Custom models</FormLabel>
- <FormDescription>
- Custom model names accepted by given endpoint.
- </FormDescription>
- {currentAdapter === LLMAdapter.Azure && (
- <FormDescription className="text-dark-yellow">
- {
- "For Azure, the model name should be the same as the deployment name in Azure. For evals, choose a model with function calling capabilities."
- }
- </FormDescription>
- )}
-
- {fields.map((customModel, index) => (
- <span key={index} className="flex flex-row space-x-2">
- <Input
- {...form.register(`customModels.${index}.value`)}
- placeholder={`Custom model name ${index + 1}`}
- />
- <Button
- type="button"
- variant="ghost"
- onClick={() => remove(index)}
- >
- <TrashIcon className="h-4 w-4" />
- </Button>
- </span>
- ))}
-
- <Button
- type="button"
- variant="ghost"
- onClick={() => append({ value: "" })}
- className="w-full"
- >
- <PlusIcon
- className="-ml-0.5 mr-1.5 h-5 w-5"
- aria-hidden="true"
- />
- Add custom model name
- </Button>
- </FormItem>
- )}
- />
-
- <Button
- type="submit"
- className="w-full"
- loading={form.formState.isSubmitting}
- >
- Save new LLM API key
- </Button>
-
- <FormMessage />
- </form>
- </Form>
+ {open && (
+ <CreateLLMApiKeyForm
+ projectId={projectId}
+ evalModelsOnly={evalModelsOnly}
+ onSuccess={() => setOpen(false)}
+ customization={uiCustomization}
+ />
+ )}
</DialogContent>
</Dialog>
);
diff --git a/web/src/features/public-api/components/CreateLLMApiKeyForm.tsx b/web/src/features/public-api/components/CreateLLMApiKeyForm.tsx
new file mode 100644
index 0000000000..a6f1792b30
--- /dev/null
+++ b/web/src/features/public-api/components/CreateLLMApiKeyForm.tsx
@@ -0,0 +1,388 @@
+import { useFieldArray, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { LLMAdapter } from "@langfuse/shared";
+import { PlusIcon, TrashIcon } from "lucide-react";
+import { z } from "zod";
+import { Button } from "@/src/components/ui/button";
+import {
+ Form,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/src/components/ui/form";
+import { Input } from "@/src/components/ui/input";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/src/components/ui/select";
+import { Switch } from "@/src/components/ui/switch";
+import { api } from "@/src/utils/api";
+import { cn } from "@/src/utils/tailwind";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
+import { type useUiCustomization } from "@/src/ee/features/ui-customization/useUiCustomization";
+
+const formSchema = z
+ .object({
+ secretKey: z.string().min(1),
+ provider: z
+ .string()
+ .min(1, "Please add a provider name that identifies this connection."),
+ adapter: z.nativeEnum(LLMAdapter),
+ baseURL: z.union([z.literal(""), z.string().url()]),
+ withDefaultModels: z.boolean(),
+ customModels: z.array(z.object({ value: z.string().min(1) })),
+ })
+ .refine((data) => data.withDefaultModels || data.customModels.length > 0, {
+ message:
+ "At least one custom model name is required when default models are disabled.",
+ path: ["withDefaultModels"],
+ });
+
+export function CreateLLMApiKeyForm({
+ projectId,
+ evalModelsOnly,
+ onSuccess,
+ customization,
+}: {
+ projectId?: string;
+ evalModelsOnly?: boolean;
+ onSuccess: () => void;
+ customization: ReturnType<typeof useUiCustomization>;
+}) {
+ const utils = api.useUtils();
+ const capture = usePostHogClientCapture();
+
+ const existingKeys = api.llmApiKey.all.useQuery(
+ {
+ projectId: projectId as string,
+ },
+ { enabled: Boolean(projectId) },
+ );
+
+ const mutCreateLlmApiKey = api.llmApiKey.create.useMutation({
+ onSuccess: () => utils.llmApiKey.invalidate(),
+ });
+
+ const mutTestLLMApiKey = api.llmApiKey.test.useMutation();
+
+ const defaultAdapter: LLMAdapter = customization?.defaultModelAdapter
+ ? LLMAdapter[customization.defaultModelAdapter]
+ : LLMAdapter.OpenAI;
+
+ const getCustomizedBaseURL = (adapter: LLMAdapter) => {
+ switch (adapter) {
+ case LLMAdapter.OpenAI:
+ return customization?.defaultBaseUrlOpenAI ?? "";
+ case LLMAdapter.Azure:
+ return customization?.defaultBaseUrlAzure ?? "";
+ case LLMAdapter.Anthropic:
+ return customization?.defaultBaseUrlAnthropic ?? "";
+ default:
+ return "";
+ }
+ };
+
+ const form = useForm<z.infer<typeof formSchema>>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ adapter: defaultAdapter,
+ provider: "",
+ secretKey: "",
+ baseURL: getCustomizedBaseURL(defaultAdapter),
+ withDefaultModels: true,
+ customModels: [],
+ },
+ });
+
+ const currentAdapter = form.watch("adapter");
+
+ const { fields, append, remove } = useFieldArray({
+ control: form.control,
+ name: "customModels",
+ });
+
+ async function onSubmit(values: z.infer<typeof formSchema>) {
+ if (!projectId) return console.error("No project ID found.");
+ if (
+ existingKeys?.data?.data.map((k) => k.provider).includes(values.provider)
+ ) {
+ form.setError("provider", {
+ type: "manual",
+ message: "There already exists an API key for this provider.",
+ });
+ return;
+ }
+ capture("project_settings:llm_api_key_create", {
+ provider: values.provider,
+ });
+
+ const newKey = {
+ projectId,
+ secretKey: values.secretKey,
+ provider: values.provider,
+ adapter: values.adapter,
+ baseURL: values.baseURL || undefined,
+ withDefaultModels: values.withDefaultModels,
+ customModels: values.customModels
+ .map((m) => m.value.trim())
+ .filter(Boolean),
+ };
+
+ try {
+ const testResult = await mutTestLLMApiKey.mutateAsync(newKey);
+
+ if (!testResult.success) throw new Error(testResult.error);
+ } catch (error) {
+ console.error(error);
+ form.setError("secretKey", {
+ type: "manual",
+ message:
+ error instanceof Error
+ ? error.message
+ : "Could not verify the API key.",
+ });
+
+ return;
+ }
+
+ return mutCreateLlmApiKey
+ .mutateAsync(newKey)
+ .then(() => {
+ form.reset();
+ onSuccess();
+ })
+ .catch((error) => {
+ console.error(error);
+ });
+ }
+
+ return (
+ <Form {...form}>
+ <form
+ className={cn("flex flex-col gap-6 overflow-auto pb-2 pl-1 pr-4")}
+ onSubmit={form.handleSubmit(onSubmit)}
+ >
+ {/* Provider name */}
+ <FormField
+ control={form.control}
+ name="provider"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Provider name</FormLabel>
+ <FormDescription>
+ Name to identify the key within Langfuse.
+ </FormDescription>
+ <FormControl>
+ <Input {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* LLM adapter */}
+ <FormField
+ control={form.control}
+ name="adapter"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>LLM adapter</FormLabel>
+ <FormDescription>
+ Schema that is accepted at that provider endpoint.
+ </FormDescription>
+ <Select
+ defaultValue={field.value}
+ onValueChange={(value) => {
+ field.onChange(value as LLMAdapter);
+ form.setValue(
+ "baseURL",
+ getCustomizedBaseURL(value as LLMAdapter),
+ );
+ }}
+ >
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="Select a LLM provider" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {Object.values(LLMAdapter)
+ .filter(
+ (provider) =>
+ !evalModelsOnly ||
+ provider === LLMAdapter.OpenAI ||
+ provider === LLMAdapter.Azure,
+ )
+ .map((provider) => (
+ <SelectItem value={provider} key={provider}>
+ {provider}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* baseURL */}
+ <FormField
+ control={form.control}
+ name="baseURL"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>API Base URL</FormLabel>
+ <FormDescription>
+ Leave blank to use the default base URL for the given LLM
+ adapter.{" "}
+ {currentAdapter === LLMAdapter.OpenAI && (
+ <span>OpenAI default: https://api.openai.com/v1</span>
+ )}
+ {currentAdapter === LLMAdapter.Azure && (
+ <span>
+ Please add the base URL in the following format (or
+ compatible API):
+ https://&#123;instanceName&#125;.openai.azure.com/openai/deployments
+ </span>
+ )}
+ {currentAdapter === LLMAdapter.Anthropic && (
+ <span>
+ Anthropic default: https://api.anthropic.com (excluding
+ /v1/messages)
+ </span>
+ )}
+ </FormDescription>
+
+ <FormControl>
+ <Input {...field} placeholder="default" />
+ </FormControl>
+
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* API key */}
+ <FormField
+ control={form.control}
+ name="secretKey"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>API Key</FormLabel>
+ <FormDescription>
+ Your API keys are stored encrypted on our servers.
+ </FormDescription>
+ <FormControl>
+ <Input {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* With default models */}
+ <FormField
+ control={form.control}
+ name="withDefaultModels"
+ render={({ field }) => (
+ <FormItem>
+ <span className="row flex">
+ <span className="flex-1">
+ <FormLabel>Enable default models</FormLabel>
+ <FormDescription>
+ Default models for the selected adapter will be available in
+ Langfuse features.
+ </FormDescription>
+ {currentAdapter === LLMAdapter.Azure && (
+ <FormDescription className="text-dark-yellow">
+ Azure LLM adapter does not support default models. Please
+ add a custom model with your deployment name.
+ </FormDescription>
+ )}
+ </span>
+
+ <FormControl>
+ <Switch
+ disabled={currentAdapter === LLMAdapter.Azure}
+ checked={
+ currentAdapter === LLMAdapter.Azure ? false : field.value
+ }
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </span>
+
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Custom model names */}
+ <FormField
+ control={form.control}
+ name="customModels"
+ render={() => (
+ <FormItem>
+ <FormLabel>Custom models</FormLabel>
+ <FormDescription>
+ Custom model names accepted by given endpoint.
+ </FormDescription>
+ {currentAdapter === LLMAdapter.Azure && (
+ <FormDescription className="text-dark-yellow">
+ {
+ "For Azure, the model name should be the same as the deployment name in Azure. For evals, choose a model with function calling capabilities."
+ }
+ </FormDescription>
+ )}
+
+ {fields.map((customModel, index) => (
+ <span key={index} className="flex flex-row space-x-2">
+ <Input
+ {...form.register(`customModels.${index}.value`)}
+ placeholder={`Custom model name ${index + 1}`}
+ />
+ <Button
+ type="button"
+ variant="ghost"
+ onClick={() => remove(index)}
+ >
+ <TrashIcon className="h-4 w-4" />
+ </Button>
+ </span>
+ ))}
+
+ <Button
+ type="button"
+ variant="ghost"
+ onClick={() => append({ value: "" })}
+ className="w-full"
+ >
+ <PlusIcon
+ className="-ml-0.5 mr-1.5 h-5 w-5"
+ aria-hidden="true"
+ />
+ Add custom model name
+ </Button>
+ </FormItem>
+ )}
+ />
+
+ <Button
+ type="submit"
+ className="w-full"
+ loading={form.formState.isSubmitting}
+ >
+ Save new LLM API key
+ </Button>
+
+ <FormMessage />
+ </form>
+ </Form>
+ );
+}