index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/header/account-setting/model-provider-page/model-icon'
  8. import ModelName from '@/app/components/header/account-setting/model-provider-page/model-name'
  9. import { Google, WebReader, Wikipedia } from '@/app/components/base/icons/src/public/plugins'
  10. import ConfigDetail from '@/app/components/explore/universal-chat/config-view/detail'
  11. import type { DataSet } from '@/models/datasets'
  12. import { useAgentThoughtCurrentProviderAndModelAndModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
  13. export type ISummaryProps = {
  14. modelId: string
  15. providerName: string
  16. plugins: Record<string, boolean>
  17. dataSets: DataSet[]
  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 {
  46. currentModel: currModel,
  47. currentProvider,
  48. } = useAgentThoughtCurrentProviderAndModelAndModelList(
  49. { provider: providerName, model: modelId },
  50. )
  51. // current_datetime is not configable and do not have icon
  52. const pluginIds = Object.keys(plugins).filter(key => plugins[key] && key !== 'current_datetime')
  53. const [isShowConfig, { setFalse: hideConfig, toggle: toggleShowConfig }] = useBoolean(false)
  54. const configContentRef = React.useRef(null)
  55. useClickAway(() => {
  56. hideConfig()
  57. }, configContentRef)
  58. return (
  59. <div ref={configContentRef} className='relative'>
  60. <div onClick={toggleShowConfig} className={cn(getColorInfo(modelId), 'flex items-center px-1 h-8 rounded-lg border cursor-pointer')}>
  61. <ModelIcon
  62. provider={currentProvider}
  63. modelName={currModel?.model}
  64. className='!w-6 !h-6'
  65. />
  66. <div className='ml-2 text-[13px] font-medium text-gray-900'>
  67. <ModelName
  68. modelItem={currModel!}
  69. />
  70. </div>
  71. {
  72. pluginIds.length > 0 && (
  73. <div className='ml-1.5 flex items-center'>
  74. <div className='mr-1 h-3 w-[1px] bg-[#000] opacity-[0.05]'></div>
  75. <div className='flex space-x-1'>
  76. {pluginIds.map(pluginId => (
  77. <div
  78. key={pluginId}
  79. className={`flex items-center justify-center w-6 h-6 rounded-md ${s.border} bg-white`}
  80. >
  81. {getPlugIcon(pluginId)}</div>
  82. ))}
  83. </div>
  84. </div>
  85. )
  86. }
  87. </div>
  88. {isShowConfig && (
  89. <ConfigDetail
  90. modelId={modelId}
  91. providerName={providerName}
  92. plugins={plugins}
  93. dataSets={dataSets}
  94. />
  95. )}
  96. </div>
  97. )
  98. }
  99. export default React.memo(Summary)