Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.6 KB
Raw Blame
'use client'

import { cn } from '@langgenius/dify-ui/cn'
import { SegmentedControl, SegmentedControlItem } from '@langgenius/dify-ui/segmented-control'
import { useTranslation } from 'react-i18next'

const retrievalModes = ['fast', 'deep', 'research'] as const

export type RetrievalMode = (typeof retrievalModes)[number]

export function RetrievalModeSegmentedControl({
  'aria-label': ariaLabel,
  'aria-labelledby': ariaLabelledBy,
  appearance = 'default',
  className,
  disabled = false,
  value,
  onChange,
}: {
  'aria-label'?: string
  'aria-labelledby'?: string
  appearance?: 'composer' | 'default'
  className?: string
  disabled?: boolean
  value: RetrievalMode
  onChange: (value: RetrievalMode) => void
}) {
  const { t } = useTranslation(['knowledgeSpace'])

  return (
    <SegmentedControl<RetrievalMode>
      aria-label={ariaLabel}
      aria-labelledby={ariaLabelledBy}
      className={cn(
        appearance === 'composer' && 'flex min-w-46.5 gap-0.5 bg-background-section-burn',
        className,
      )}
      value={value}
      onValueChange={onChange}
    >
      {retrievalModes.map((mode) => (
        <SegmentedControlItem<RetrievalMode>
          key={mode}
          value={mode}
          disabled={disabled}
          className={cn(
            appearance === 'composer' &&
              'grow border-0 px-2.5 py-1.25 system-sm-regular text-text-tertiary capitalize data-checked:bg-components-panel-bg data-checked:font-medium data-checked:text-text-primary',
          )}
        >
          {t(($) => $[`settings.retrievalMode.${mode}`], { ns: 'knowledgeSpace' })}
        </SegmentedControlItem>
      ))}
    </SegmentedControl>
  )
}