index.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. export type ISummaryProps = {
  11. modelId: string
  12. plugins: Record<string, boolean>
  13. dataSets: any[]
  14. }
  15. const getColorInfo = (modelId: string) => {
  16. if (modelId === 'gpt-4')
  17. return s.gpt4
  18. if (modelId === 'claude-2')
  19. return s.claude
  20. return s.gpt3
  21. }
  22. const getPlugIcon = (pluginId: string) => {
  23. const className = 'w-4 h-4'
  24. switch (pluginId) {
  25. case 'google_search':
  26. return <Google className={className} />
  27. case 'web_reader':
  28. return <WebReader className={className} />
  29. case 'wikipedia':
  30. return <Wikipedia className={className} />
  31. default:
  32. return null
  33. }
  34. }
  35. const Summary: FC<ISummaryProps> = ({
  36. modelId,
  37. plugins,
  38. dataSets,
  39. }) => {
  40. // current_datetime is not configable and do not have icon
  41. const pluginIds = Object.keys(plugins).filter(key => plugins[key] && key !== 'current_datetime')
  42. const [isShowConfig, { setFalse: hideConfig, toggle: toggleShowConfig }] = useBoolean(false)
  43. const configContentRef = React.useRef(null)
  44. useClickAway(() => {
  45. hideConfig()
  46. }, configContentRef)
  47. return (
  48. <div ref={configContentRef} className='relative'>
  49. <div onClick={toggleShowConfig} className={cn(getColorInfo(modelId), 'flex items-center px-1 h-8 rounded-lg border cursor-pointer')}>
  50. <ModelIcon modelId={modelId} className='!w-6 !h-6' />
  51. <div className='ml-2 text-[13px] font-medium text-gray-900'>{modelId}</div>
  52. {
  53. pluginIds.length > 0 && (
  54. <div className='ml-1.5 flex items-center'>
  55. <div className='mr-1 h-3 w-[1px] bg-[#000] opacity-[0.05]'></div>
  56. <div className='flex space-x-1'>
  57. {pluginIds.map(pluginId => (
  58. <div
  59. key={pluginId}
  60. className={`flex items-center justify-center w-6 h-6 rounded-md ${s.border} bg-white`}
  61. >
  62. {getPlugIcon(pluginId)}</div>
  63. ))}
  64. </div>
  65. </div>
  66. )
  67. }
  68. </div>
  69. {isShowConfig && (
  70. <ConfigDetail
  71. modelId={modelId} plugins={plugins} dataSets={dataSets}
  72. />
  73. )}
  74. </div>
  75. )
  76. }
  77. export default React.memo(Summary)