Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python
1.7 KB
Raw Blame
import { useFormContext } from "react-hook-form";
import { LabelWrapper } from "@/components/label-wrapper";
import { Input } from "@/components/ui/input";

export interface AnthropicSettingsFormData {
  apiKey: string;
}

export function AnthropicSettingsForm({
  modelsError,
  isLoadingModels,
}: {
  modelsError?: Error | null;
  isLoadingModels?: boolean;
}) {
  const {
    register,
    formState: { errors },
  } = useFormContext<AnthropicSettingsFormData>();

  const apiKeyError = modelsError?.message || errors.apiKey?.message;

  return (
    <div className="min-w-0 space-y-4">
      <div className="min-w-0 space-y-2">
        <LabelWrapper
          label="Anthropic API key"
          helperText="The API key for your Anthropic account"
          required
          id="api-key"
        >
          <Input
            {...register("apiKey", {
              required: "API key is required",
            })}
            className={apiKeyError ? "border-destructive!" : ""}
            id="api-key"
            type="password"
            autoComplete="new-password"
            placeholder="sk-ant-..."
          />
        </LabelWrapper>
        {apiKeyError && (
          <p
            data-testid="provider-connection-error"
            className="text-sm text-destructive min-w-0 wrap-anywhere"
          >
            {apiKeyError}
          </p>
        )}
        {isLoadingModels && (
          <p className="text-sm text-muted-foreground">Validating API key...</p>
        )}
      </div>
      <p className="text-sm text-muted-foreground">
        Configure language models in the Settings page after saving your API
        key. Note: Anthropic does not provide embedding models.
      </p>
    </div>
  );
}