index.tsx 3.3 KB

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