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.

2.3 KB
Raw Blame
import type { ModelProviderSummaryResponse } from '@dify/contracts/api/console/workspaces/types.gen'
import type { FC } from 'react'
import { cn } from '@langgenius/dify-ui/cn'
import { useResolvedTheme } from '@/features/theme/hooks'
import { renderI18nObject } from '@/i18n/metadata'
import { useLanguage } from '../hooks'

type ProviderIconProps = {
  provider: Pick<
    ModelProviderSummaryResponse,
    'provider' | 'icon_small' | 'icon_small_dark' | 'label'
  >
  className?: string
}
const ProviderIcon: FC<ProviderIconProps> = ({ provider, className }) => {
  const theme = useResolvedTheme()
  const language = useLanguage()
  const lightIconUrl = provider.icon_small ? renderI18nObject(provider.icon_small, language) : ''
  const darkIconUrl = provider.icon_small_dark
    ? renderI18nObject(provider.icon_small_dark, language)
    : ''
  const iconUrl = theme === 'dark' ? darkIconUrl || lightIconUrl : lightIconUrl

  if (provider.provider === 'langgenius/anthropic/anthropic') {
    return (
      <div className={cn('py-1.75', className)}>
        <span
          aria-hidden
          className="i-custom-public-llm-anthropic-light h-2.5 w-22.5 not-dark:hidden"
        />
        <span aria-hidden className="i-custom-public-llm-anthropic-dark h-2.5 w-22.5 dark:hidden" />
      </div>
    )
  }

  if (provider.provider === 'langgenius/openai/openai') {
    return (
      <div className={className}>
        <span
          aria-hidden
          className="i-custom-vender-other-openai h-6 w-[calc(1.5rem*80/22)] text-text-inverted-dimmed"
        />
      </div>
    )
  }

  return (
    <div className={cn('inline-flex items-center gap-2', className)}>
      {iconUrl ? (
        <img
          alt=""
          className="size-6"
          decoding="async"
          height={24}
          loading="lazy"
          src={iconUrl}
          width={24}
        />
      ) : (
        <div className="flex size-6 items-center justify-center rounded-md border-[0.5px] border-components-panel-border-subtle bg-background-default-subtle">
          <span aria-hidden className="i-custom-vender-other-group size-4 text-text-tertiary" />
        </div>
      )}
      <div className="system-md-semibold text-text-primary">
        {renderI18nObject(provider.label, language)}
      </div>
    </div>
  )
}

export default ProviderIcon