index.tsx 2.5 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. const pluginIds = Object.keys(plugins).filter(key => plugins[key])
  41. const [isShowConfig, { setFalse: hideConfig, toggle: toggleShowConfig }] = useBoolean(false)
  42. const configContentRef = React.useRef(null)
  43. useClickAway(() => {
  44. hideConfig()
  45. }, configContentRef)
  46. return (
  47. <div ref={configContentRef} className='relative'>
  48. <div onClick={toggleShowConfig} className={cn(getColorInfo(modelId), 'flex items-center px-1 h-8 rounded-lg border cursor-pointer')}>
  49. <ModelIcon modelId={modelId} className='!w-6 !h-6' />
  50. <div className='ml-2 text-[13px] font-medium text-gray-900'>{modelId}</div>
  51. {
  52. pluginIds.length > 0 && (
  53. <div className='ml-1.5 flex items-center'>
  54. <div className='mr-1 h-3 w-[1px] bg-[#000] opacity-[0.05]'></div>
  55. <div className='flex space-x-1'>
  56. {pluginIds.map(pluginId => (
  57. <div
  58. key={pluginId}
  59. className={`flex items-center justify-center w-6 h-6 rounded-md ${s.border} bg-white`}
  60. >
  61. {getPlugIcon(pluginId)}</div>
  62. ))}
  63. </div>
  64. </div>
  65. )
  66. }
  67. </div>
  68. {isShowConfig && (
  69. <ConfigDetail
  70. modelId={modelId} plugins={plugins} dataSets={dataSets}
  71. />
  72. )}
  73. </div>
  74. )
  75. }
  76. export default React.memo(Summary)