Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { IModalManagerChildrenProps } from '@/components/modal-manager';
  2. import { useTranslate } from '@/hooks/common-hooks';
  3. import { Form, Input, Modal } from 'antd';
  4. import { useEffect } from 'react';
  5. import { ApiKeyPostBody } from '../../interface';
  6. interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
  7. loading: boolean;
  8. initialValue: string;
  9. llmFactory: string;
  10. onOk: (postBody: ApiKeyPostBody) => void;
  11. showModal?(): void;
  12. }
  13. type FieldType = {
  14. api_key?: string;
  15. base_url?: string;
  16. group_id?: string;
  17. };
  18. const modelsWithBaseUrl = ['OpenAI', 'Azure-OpenAI'];
  19. const ApiKeyModal = ({
  20. visible,
  21. hideModal,
  22. llmFactory,
  23. loading,
  24. initialValue,
  25. onOk,
  26. }: IProps) => {
  27. const [form] = Form.useForm();
  28. const { t } = useTranslate('setting');
  29. const handleOk = async () => {
  30. const ret = await form.validateFields();
  31. return onOk(ret);
  32. };
  33. useEffect(() => {
  34. if (visible) {
  35. form.setFieldValue('api_key', initialValue);
  36. }
  37. }, [initialValue, form, visible]);
  38. return (
  39. <Modal
  40. title={t('modify')}
  41. open={visible}
  42. onOk={handleOk}
  43. onCancel={hideModal}
  44. okButtonProps={{ loading }}
  45. confirmLoading={loading}
  46. >
  47. <Form
  48. name="basic"
  49. labelCol={{ span: 6 }}
  50. wrapperCol={{ span: 18 }}
  51. style={{ maxWidth: 600 }}
  52. autoComplete="off"
  53. form={form}
  54. >
  55. <Form.Item<FieldType>
  56. label={t('apiKey')}
  57. name="api_key"
  58. tooltip={t('apiKeyTip')}
  59. rules={[{ required: true, message: t('apiKeyMessage') }]}
  60. >
  61. <Input />
  62. </Form.Item>
  63. {modelsWithBaseUrl.some((x) => x === llmFactory) && (
  64. <Form.Item<FieldType>
  65. label={t('baseUrl')}
  66. name="base_url"
  67. tooltip={t('baseUrlTip')}
  68. >
  69. <Input placeholder="https://api.openai.com/v1" />
  70. </Form.Item>
  71. )}
  72. {llmFactory.toLowerCase() === 'Minimax'.toLowerCase() && (
  73. <Form.Item<FieldType> label={'Group ID'} name="group_id">
  74. <Input />
  75. </Form.Item>
  76. )}
  77. </Form>
  78. </Modal>
  79. );
  80. };
  81. export default ApiKeyModal;