index.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import cn from 'classnames'
  5. import { useBoolean, useClickAway } from 'ahooks'
  6. import s from './style.module.css'
  7. import ModelIcon from '@/app/components/app/configuration/config-model/model-icon'
  8. import { Google, WebReader, Wikipedia } from '@/app/components/base/icons/src/public/plugins'
  9. import ConfigDetail from '@/app/components/explore/universal-chat/config-view/detail'
  10. import type { ProviderEnum } from '@/app/components/header/account-setting/model-page/declarations'
  11. import ModelName from '@/app/components/app/configuration/config-model/model-name'
  12. export type ISummaryProps = {
  13. modelId: string
  14. providerName: ProviderEnum
  15. plugins: Record<string, boolean>
  16. dataSets: any[]
  17. }
  18. const getColorInfo = (modelId: string) => {
  19. if (modelId === 'gpt-4')
  20. return s.gpt4
  21. if (modelId === 'claude-2')
  22. return s.claude
  23. return s.gpt3
  24. }
  25. const getPlugIcon = (pluginId: string) => {
  26. const className = 'w-4 h-4'
  27. switch (pluginId) {
  28. case 'google_search':
  29. return <Google className={className} />
  30. case 'web_reader':
  31. return <WebReader className={className} />
  32. case 'wikipedia':
  33. return <Wikipedia className={className} />
  34. default:
  35. return null
  36. }
  37. }
  38. const Summary: FC<ISummaryProps> = ({
  39. modelId,
  40. providerName,
  41. plugins,
  42. dataSets,
  43. }) => {
  44. // current_datetime is not configable and do not have icon
  45. const pluginIds = Object.keys(plugins).filter(key => plugins[key] && key !== 'current_datetime')
  46. const [isShowConfig, { setFalse: hideConfig, toggle: toggleShowConfig }] = useBoolean(false)
  47. const configContentRef = React.useRef(null)
  48. useClickAway(() => {
  49. hideConfig()
  50. }, configContentRef)
  51. return (
  52. <div ref={configContentRef} className='relative'>
  53. <div onClick={toggleShowConfig} className={cn(getColorInfo(modelId), 'flex items-center px-1 h-8 rounded-lg border cursor-pointer')}>
  54. <ModelIcon providerName={providerName} modelId={modelId} className='!w-6 !h-6' />
  55. <div className='ml-2 text-[13px] font-medium text-gray-900'><ModelName modelId={modelId} /></div>
  56. {
  57. pluginIds.length > 0 && (
  58. <div className='ml-1.5 flex items-center'>
  59. <div className='mr-1 h-3 w-[1px] bg-[#000] opacity-[0.05]'></div>
  60. <div className='flex space-x-1'>
  61. {pluginIds.map(pluginId => (
  62. <div
  63. key={pluginId}
  64. className={`flex items-center justify-center w-6 h-6 rounded-md ${s.border} bg-white`}
  65. >
  66. {getPlugIcon(pluginId)}</div>
  67. ))}
  68. </div>
  69. </div>
  70. )
  71. }
  72. </div>
  73. {isShowConfig && (
  74. <ConfigDetail
  75. modelId={modelId}
  76. providerName={providerName}
  77. plugins={plugins}
  78. dataSets={dataSets}
  79. />
  80. )}
  81. </div>
  82. )
  83. }
  84. export default React.memo(Summary)