index.tsx 3.2 KB

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