<!-- 创建Prompt模板 -->
<template>

  <el-form label-position="left" ref="form" label-width="80px" :model="form" :size="defaultFormItemSize">
    <el-row class="title">基本信息</el-row>
    <el-form-item label="任务名称:">
      <el-input v-model="form.taskName" class="inputWidth" :size="defaultFormItemSize"></el-input>
    </el-form-item>
    <el-form-item label="任务描述:">
      <el-input v-model="form.taskDescribe" type="textarea" :rows="4" class="inputWidth" :size="defaultFormItemSize"></el-input>
    </el-form-item>
    <el-form-item label="优化前数据集:">
      <el-cascader v-model="form.sourceDatasetName" :options="options"  :size="defaultFormItemSize"></el-cascader>
    </el-form-item>
    <el-form-item label="优化后数据集:">
      <el-cascader v-model="form.destDatasetName" :options="options"  :size="defaultFormItemSize"></el-cascader>
    </el-form-item>

    <el-row class="title">优化参数配置</el-row>
    <el-form-item label="质量优化:">
      <el-switch v-model="form.qualityQptimality" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" >
      </el-switch>
      <el-row> <span class="introduce">启用此功能可能会为您提供更好质量的提示词，但也会花费更长的时间进行优化</span></el-row>

    </el-form-item>
    <el-form-item label="缩短提示词:">
      <el-switch v-model="form.shortenPrompt" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0">
      </el-switch>
      <el-row> <span class="introduce">可以省去“的”、“吧”等含义不强的文本实体，精炼语料内容并降低推理成本</span></el-row>
    </el-form-item>
    <el-form-item label="迭代轮次:">
      <el-input-number v-model="form.epoch" :min="1" label="迭代轮次"  :size="defaultFormItemSize"></el-input-number>
      <el-row> <span class="introduce">反复迭代Prompt优化，更多的迭代次数意味着优化效果越强，但也需要花费更长时间</span></el-row>

    </el-form-item>
    <el-form-item label="思维链条:">
      <el-switch v-model="form.chain" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0">
      </el-switch>
      <el-row> <span class="introduce">开启后将指引模型拆解Prompt内容，逐步进行推理。建议仅在数学计算、逻辑推理等场景下开启使用</span></el-row>
    </el-form-item>

    <el-row type="flex" justify="end" class="dialog-btn-layer mt20">
      <el-button :size="defaultFormItemSize" :plain="true" @click="onCancel(false)">取消</el-button>
      <el-button type="primary" :size="defaultFormItemSize" @click="onSubmit">确定</el-button>
    </el-row>
  </el-form>
</template>

<script>

import { BatchOptimizationController } from '@/api/gptController.js';
export default {
  data () {
    return {
      form: {
        'chain': 0,
        'destDatasetId': 0,
        'destDatasetName': '',
        'destDatasetVersion': 0,
        'epoch': 0,
        'failCount': 0,
        'finishTime': '',
        'qualityQptimality': 0,
        'shortenPrompt': 0,
        'sourceDatasetId': 0,
        'sourceDatasetName': '',
        'sourceDatasetVersion': 0,
        'successCount': 0,
        'taskDescribe': '',
        'taskName': '',
        'taskStatus': 0
      }

    };
  },
  props: ['isEdit', 'item'],
  components: {},

  computed: {

  },

  mounted () {
    this.intFrom()
  },

  methods: {
    intFrom () {
      this.form = { ...this.form, ...this.item }
      try {
        this.form.templateLabel = JSON.parse(this.item.templateLabel)
      } catch (error) {
        // console.log(error);
      }
    },
    onCancel (isSuccess) {
      if (this.observer != null) {
        this.observer.cancel(isSuccess);
      }
    },
    onSubmit () {
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            let params = {};
            params.promptOptimizeBatchDto = { ...this.form };

            if (this.isEdit) {
              BatchOptimizationController.update(this, params).then(res => {
                resolve(res);
                this.$message.success('编辑成功');
                this.onCancel(true);
              }).catch(e => {
                reject(e);
              });
            } else {
              BatchOptimizationController.add(this, params).then(res => {
                resolve(res);
                this.$message.success('添加成功');
                this.onCancel(true);
              }).catch(e => {
                reject(e);
              });
            }
          } else {
            reject();
          }
        });
      });
    }
  }
};
</script>
<style scoped>
.inputWidth {
  width: 600px;
}
.title {
  font-size: 20px;
  margin-bottom: 16px;
}
.introduce{
  font-size: 12px;
  color: #909399;
}
</style>
