agent-selector.tsx 831 B

12345678910111213141516171819202122232425262728293031
  1. import { ChatContext } from '@/app/chat-context';
  2. import { apiInterceptors, getDbgptsList } from '@/client/api';
  3. import { useRequest } from 'ahooks';
  4. import { Select } from 'antd';
  5. import { useContext } from 'react';
  6. import { useTranslation } from 'react-i18next';
  7. function AgentSelector() {
  8. const { t } = useTranslation();
  9. const { agent, setAgent } = useContext(ChatContext);
  10. const { data = [] } = useRequest(async () => {
  11. const [, res] = await apiInterceptors(getDbgptsList());
  12. return res ?? [];
  13. });
  14. return (
  15. <Select
  16. className='w-60'
  17. value={agent}
  18. placeholder={t('Select_Plugins')}
  19. options={data.map(item => ({ label: item.app_name, value: item.app_code }))}
  20. allowClear
  21. onChange={val => {
  22. setAgent?.(val);
  23. }}
  24. />
  25. );
  26. }
  27. export default AgentSelector;