create.vue 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <base-dialog :width="900" @cancel="cancelDialog">
  3. <div slot="header">{{ $t('common.create') }}</div>
  4. <div slot="body">
  5. <a-form-model ref="form" :model="form" :rules="rules" :label-col="{ span: 4 }" :wrapper-col="{ span: 18 }">
  6. <a-form-model-item :label="$t('common.name')" prop="name">
  7. <a-input v-model="form.name" :placeholder="$t('common.tips.input', [$t('common.name')])" />
  8. </a-form-model-item>
  9. <a-form-model-item :label="$t('aice.llm_type')" prop="llm_type">
  10. <base-select
  11. v-model="form.llm_type"
  12. :options="llmTypeOptions"
  13. :selectProps="{ placeholder: $t('common.tips.select', [$t('aice.llm_type')]) }" />
  14. </a-form-model-item>
  15. <a-form-model-item :label="$t('aice.model_name')" prop="model_name">
  16. <a-input v-model="form.model_name" :placeholder="$t('common.tips.input', [$t('aice.model_name')])" />
  17. </a-form-model-item>
  18. <a-form-model-item :label="$t('aice.model_tag')" prop="model_tag">
  19. <a-input v-model="form.model_tag" :placeholder="$t('common.tips.input', [$t('aice.model_tag')])" />
  20. </a-form-model-item>
  21. </a-form-model>
  22. </div>
  23. <div slot="footer">
  24. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  25. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  26. </div>
  27. </base-dialog>
  28. </template>
  29. <script>
  30. import DialogMixin from '@/mixins/dialog'
  31. import WindowsMixin from '@/mixins/windows'
  32. import { validateModelForm } from '@/utils/validate'
  33. export default {
  34. name: 'LlmInstantmodelCreateDialog',
  35. mixins: [DialogMixin, WindowsMixin],
  36. data () {
  37. return {
  38. loading: false,
  39. form: {
  40. name: undefined,
  41. llm_type: 'ollama',
  42. model_name: undefined,
  43. model_tag: undefined,
  44. },
  45. rules: {
  46. name: [{ required: true, validator: this.$validate('resourceName') }],
  47. llm_type: [{ required: true, message: this.$t('common.tips.select', [this.$t('aice.llm_type')]) }],
  48. model_name: [{ required: true, message: this.$t('common.tips.input', [this.$t('aice.model_name')]) }],
  49. model_tag: [{ required: true, message: this.$t('common.tips.input', [this.$t('aice.model_tag')]) }],
  50. },
  51. llmTypeOptions: [
  52. { id: 'ollama', name: 'Ollama' },
  53. ],
  54. }
  55. },
  56. methods: {
  57. async handleConfirm () {
  58. try {
  59. await validateModelForm(this.$refs.form)
  60. const data = {
  61. generate_name: this.form.name,
  62. llm_type: this.form.llm_type,
  63. model_name: this.form.model_name,
  64. model_tag: this.form.model_tag,
  65. }
  66. await this.params.onManager('create', {
  67. managerArgs: { data },
  68. })
  69. this.loading = false
  70. this.cancelDialog()
  71. this.params.refresh && this.params.refresh()
  72. } catch (error) {
  73. throw error
  74. } finally {
  75. this.loading = false
  76. }
  77. },
  78. },
  79. }
  80. </script>