您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import type { ChatItem } from '../../types'
  4. import { useChatContext } from '../context'
  5. import { useCurrentAnswerIsResponsing } from '../hooks'
  6. import Operation from './operation'
  7. import AgentContent from './agent-content'
  8. import BasicContent from './basic-content'
  9. import SuggestedQuestions from './suggested-questions'
  10. import More from './more'
  11. import { AnswerTriangle } from '@/app/components/base/icons/src/vender/solid/general'
  12. import LoadingAnim from '@/app/components/app/chat/loading-anim'
  13. import Citation from '@/app/components/app/chat/citation'
  14. import { EditTitle } from '@/app/components/app/annotation/edit-annotation-modal/edit-item'
  15. type AnswerProps = {
  16. item: ChatItem
  17. }
  18. const Answer: FC<AnswerProps> = ({
  19. item,
  20. }) => {
  21. const { t } = useTranslation()
  22. const {
  23. config,
  24. answerIcon,
  25. } = useChatContext()
  26. const responsing = useCurrentAnswerIsResponsing(item.id)
  27. const {
  28. content,
  29. citation,
  30. agent_thoughts,
  31. more,
  32. annotation,
  33. } = item
  34. const hasAgentThoughts = !!agent_thoughts?.length
  35. return (
  36. <div className='flex mb-2 last:mb-0'>
  37. <div className='shrink-0 relative w-10 h-10'>
  38. {
  39. answerIcon || (
  40. <div className='flex items-center justify-center w-full h-full rounded-full bg-[#d5f5f6] border-[0.5px] border-black/5 text-xl'>
  41. 🤖
  42. </div>
  43. )
  44. }
  45. {
  46. responsing && (
  47. <div className='absolute -top-[3px] -left-[3px] pl-[6px] flex items-center w-4 h-4 bg-white rounded-full shadow-xs border-[0.5px] border-gray-50'>
  48. <LoadingAnim type='avatar' />
  49. </div>
  50. )
  51. }
  52. </div>
  53. <div className='chat-answer-container grow w-0 group ml-4'>
  54. <div className='relative pr-10'>
  55. <AnswerTriangle className='absolute -left-2 top-0 w-2 h-3 text-gray-100' />
  56. <div className='group relative inline-block px-4 py-3 max-w-full bg-gray-100 rounded-b-2xl rounded-tr-2xl text-sm text-gray-900'>
  57. <Operation item={item} />
  58. {
  59. responsing && !content && !hasAgentThoughts && (
  60. <div className='flex items-center justify-center w-6 h-5'>
  61. <LoadingAnim type='text' />
  62. </div>
  63. )
  64. }
  65. {
  66. content && !hasAgentThoughts && (
  67. <BasicContent item={item} />
  68. )
  69. }
  70. {
  71. hasAgentThoughts && !content && (
  72. <AgentContent item={item} />
  73. )
  74. }
  75. {
  76. annotation?.id && !annotation?.logAnnotation && (
  77. <EditTitle
  78. className='mt-1'
  79. title={t('appAnnotation.editBy', { author: annotation.authorName })}
  80. />
  81. )
  82. }
  83. <SuggestedQuestions item={item} />
  84. {
  85. !!citation?.length && config?.retriever_resource?.enabled && !responsing && (
  86. <Citation data={citation} showHitInfo />
  87. )
  88. }
  89. </div>
  90. </div>
  91. <More more={more} />
  92. </div>
  93. </div>
  94. )
  95. }
  96. export default Answer