App.vue 22.5 KB
Newer Older
6
UPDATE  
64104061f23fda247c679fa8 已提交
1
<template>
2 3
  <div class="w-full h-screen">
    <!-- toolbar -->
4 5 6 7 8 9 10 11 12 13 14 15 16 17
    <div class="w-full h-14 pt-2 border-b-2 shadow-2xl fixed bg-slate-200 flex items-center">
      
      <div class="flex-none w-1/3">

      </div>
      <div class="flex-none w-1/3 text-center">
        <span class="leading-10 font-bold">{{ name }} {{ config?.mode === 'completions' ? '(无上下文)' : '' }}</span>

      </div> 
      <div class="flex-none w-1/3 *:ml-4 *:text-gray-600 *:hover:text-gray-900 text-sm float-right flex justify-end pr-4">
        <button @click="page='chat'">Chat</button>
        <button @click="page='content'">知识库</button>
        <button>设置</button>

18
        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"
19
          class="w-4 h-4  cursor-pointer inline" @click="cleanHistory">
20
          <path stroke-linecap="round" stroke-linejoin="round"
21
            d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" />
22
        </svg>
23 24 25 26
      </div>
      
      
     
27 28 29
    </div>
    <!-- main content -->
    <div class="flex w-full h-full pt-14">
30 31 32 33
      
      
      <div v-if="page === 'content'" class="w-full bg-slate-300 md:bg-slate-300 p-2 sm:p-8">
        <content/>
34 35
      </div>
      <!-- right -->
36
      <div class="flex-auto bg-slate-300 md:bg-slate-300 p-2 sm:p-8" v-else>
37

38
        
39

40
        <div class="w-full bg-slate-200 h-full m-auto relative container max-w-6xl rounded-xl">
41
          <div class="w-full h-full pb-24 p-4 overflow-y-auto overflow-x-hidden" ref="messageList">
42
            <div v-for="(item,index) in message" class="mb-8">
43 44 45 46
              <div v-if="item.user === 'User'">
                <div class="flex flex-row-reverse">
                  <t-image class="rounded-lg" v-if="config.user_img" :src="config.user_img" fit="cover"
                    :style="{ width: '40px', height: '40px' }"></t-image>
47
                  <div class="bg-green-400 text-gray-700  p-4 mx-2 w-fit max-w-2xl 2xl:max-w-4xl rounded-lg cursor-pointer text-sm" @click="copyAsPrompt(item.message)" v-html="item.message">
48
                   
49 50
                  </div>
                </div>
6
UPDATE  
64104061f23fda247c679fa8 已提交
51

52 53 54 55 56
              </div>
              <div v-else class="flex">
                <t-image class="rounded-lg" v-if="config.robot_img" :src="config.robot_img" fit="cover"
                  :style="{ width: '40px', height: '40px' }"></t-image>
                <div class="bg-slate-50 text-gray-700 p-4 mx-2 w-fit max-w-2xl 2xl:max-w-4xl rounded-lg text-wrapper">
57 58
                  <template v-if="item?.viewMode??'chat' === 'image'">
                    <img v-if="item.img" :src="item.img"/>
6
622aa39c1f9b166ab1a38c05 已提交
59
                    <img v-else src="/loading.gif" class="w-[512px]"/>
60
                  </template>
61 62 63 64 65
                  <template v-else-if="item.message && item.message.length > 5">
                    <p class="text-sm">
                      {{ item.message }}
                    </p>
                    <!-- <markdown-it-vue class="md-body" content="123" :options="mdOptions" :key="index" v-if="item.message"/> -->
66 67

                  </template>
W
weixin_44463441 已提交
68
                  <p class="text-sm" v-else>思考中...</p>
69
                  
70 71 72
                </div>
              </div>
            </div>
73
            <div class="text-center" v-if="mode !== 'draw'">
74 75 76 77 78 79 80 81 82 83
              <div v-if="loading"  @click="stop" class="-mt-4 px-5 py-1 m-auto w-fit cursor-pointer hover:bg-slate-300 border-dotted border-[1px] border-slate-400 rounded-md">
                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="animate-spin w-4 h-4 inline-block">
                  <path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
                  <path stroke-linecap="round" stroke-linejoin="round" d="M9 9.563C9 9.252 9.252 9 9.563 9h4.874c.311 0 .563.252.563.563v4.874c0 .311-.252.563-.563.563H9.564A.562.562 0 019 14.437V9.564z" />
                </svg>
                <span class="ml-2 text-[12px]">停止</span>
              </div>
             
            </div>
          </div>
84
          <div class="w-full absolute bottom-0 bg-slate-100 h-22 py-2 px-2 rounded flex flex-col  text-sm">
85 86
            
            <div class="w-full h-10 flex">
W
weixin_44463441 已提交
87
                <input v-model="prompt" class="flex-auto ring-0	outline-0	pl-2 bg-slate-200 h-10 border-0" v-on:keyup.enter="query" placeholder="提示词" />
88

89
                <t-dropdown :options="options" @click="clickHandler" class="ml-4 mt-1" v-if="mode === 'draw'">
90 91 92 93 94
                  <t-button theme="default" variant="text" shape="square"> 
                    <t-icon :name="modeImage" size="24" class="w-6 h-6 text-cyan-800 font-bold hover:text-cyan-600 cursor-pointer"/>
                  </t-button>
                </t-dropdown>
              
95
                <!-- <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" 
96 97 98 99
                @click="showMoreSetting=!showMoreSetting"
                class="w-6 mx-2 ml-4 mt-2 h-6 flex-none text-cyan-800 font-bold hover:text-cyan-600 cursor-pointer">
                  <path stroke-linecap="round" stroke-linejoin="round" d="M10.343 3.94c.09-.542.56-.94 1.11-.94h1.093c.55 0 1.02.398 1.11.94l.149.894c.07.424.384.764.78.93.398.164.855.142 1.205-.108l.737-.527a1.125 1.125 0 011.45.12l.773.774c.39.389.44 1.002.12 1.45l-.527.737c-.25.35-.272.806-.107 1.204.165.397.505.71.93.78l.893.15c.543.09.94.56.94 1.109v1.094c0 .55-.397 1.02-.94 1.11l-.893.149c-.425.07-.765.383-.93.78-.165.398-.143.854.107 1.204l.527.738c.32.447.269 1.06-.12 1.45l-.774.773a1.125 1.125 0 01-1.449.12l-.738-.527c-.35-.25-.806-.272-1.203-.107-.397.165-.71.505-.781.929l-.149.894c-.09.542-.56.94-1.11.94h-1.094c-.55 0-1.019-.398-1.11-.94l-.148-.894c-.071-.424-.384-.764-.781-.93-.398-.164-.854-.142-1.204.108l-.738.527c-.447.32-1.06.269-1.45-.12l-.773-.774a1.125 1.125 0 01-.12-1.45l.527-.737c.25-.35.273-.806.108-1.204-.165-.397-.505-.71-.93-.78l-.894-.15c-.542-.09-.94-.56-.94-1.109v-1.094c0-.55.398-1.02.94-1.11l.894-.149c.424-.07.765-.383.93-.78.165-.398.143-.854-.107-1.204l-.527-.738a1.125 1.125 0 01.12-1.45l.773-.773a1.125 1.125 0 011.45-.12l.737.527c.35.25.807.272 1.204.107.397-.165.71-.505.78-.929l.15-.894z" />
                  <path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
100
                </svg> -->
101

102 103 104 105 106 107 108
                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
                  stroke="currentColor"
                  class="w-6 mx-2 ml-4 mt-2 h-6 flex-none text-cyan-800 font-bold hover:text-cyan-600 cursor-pointer"
                  @click="query">
                  <path stroke-linecap="round" stroke-linejoin="round"
                    d="M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5" />
                </svg>
109
            </div>
110
            <div class="w-full h-10 mt-2 flex gap-2" v-if="mode === 'draw'">
111
                <input v-model="negative_prompt" class="flex-auto ring-0	outline-0	pl-2 bg-slate-200 h-10" v-on:keyup.enter="query" placeholder="逆向提示词" />
112 113 114 115 116 117 118
                <div class="flex-none w-40 ring-0	outline-0	pl-2  h-10 flex justify-between">
                  <input v-model="width" class="ring-0	outline-0	pl-2 bg-slate-200 h-10 w-16" placeholder="width"/> 
                  <span class="h-10 leading-10">*</span>
                  <input v-model="height" class="ring-0	outline-0	pl-2 bg-slate-200 h-10 w-16" placeholder="height"/>
                </div>
                <input v-model="steps" class="flex-none w-30 ring-0	outline-0	pl-2 bg-slate-200 h-10 w-16" placeholder="steps"/>
                <input v-model="sampler" class="flex-none w-40 ring-0	outline-0	pl-2 bg-slate-200 h-10 w-16 text-small" placeholder="sampler"/>
119
            </div>
120 121 122
          </div>
        </div>
      </div>
6
UPDATE  
64104061f23fda247c679fa8 已提交
123 124
    </div>

125
  </div>
6
UPDATE  
64104061f23fda247c679fa8 已提交
126
</template>
127
<script>
6
UPDATE  
64104061f23fda247c679fa8 已提交
128

129 130 131
// import { Configuration, OpenAIApi } from "openai"
import OpenAI from './js/openai.js'
import Config from './js/config.js'
132 133
import InsCodeAI from './js/inscodeai.js'

134
import SDApi from './js/sd.js'
135
import StorageApi from './js/storage.js'
136
import PodsApi from './js/pod.js'
137
import RepEs from './js/repEs.js'
138 139
import { MessagePlugin } from 'tdesign-vue-next';

140 141
import Content from './components/content/index.vue'

6
UPDATE  
64104061f23fda247c679fa8 已提交
142

143 144 145
// import MarkdownItVue from 'markdown-it-vue'
// import 'markdown-it-vue/dist/markdown-it-vue.css'
// https://github.com/ravenq/markdown-it-vue
146 147
import MarkdownItVue from 'markdown-it-vue'
import 'markdown-it-vue/dist/markdown-it-vue.css'
6
UPDATE  
64104061f23fda247c679fa8 已提交
148

149
// const DataServe = new Data()
6
UPDATE  
64104061f23fda247c679fa8 已提交
150

151 152 153
export default {
  name: 'LlmApp',
  components: {
154
    MarkdownItVue, Content
155 156 157
  },
  data() {
    return {
158
      page: '',
159 160 161 162
      id: 0,
      name: '加载中...',
      userAvatarList: [],
      robotAvatarList: [],
163
      mode: 'chat',
164
      modeImage: 'image', // image chat chart-bubble
165 166 167 168 169 170 171 172 173 174 175
      message: [
        // {"user": "User", "message": "创建一个用户表,要求分区"},
        // {"user": "AI", "message": "在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:"},
        // {"user": "User", "message": "create table user(id int primary key, name varchar)将这个建表语句翻译成GaussDB建表语句create table user(id int primary key, name varchar)将这个建表语句翻译成GaussDB建表语句create table user(id int primary key, name varchar)将这个建表语句翻译成GaussDB建表语句create table user(id int primary key, name varchar)将这个建表语句翻译成GaussDB建表语句create table user(id int primary key, name varchar)将这个建表语句翻译成GaussDB建表语句"},
        // {"user": "AI", "message": "在GaussDB数据库中,创建一个带有主键约束的用户表可以使用以下语句:"},
      ],
      client: null,
      indexClient: null,
      prompt: '',
      config: {
      },
176 177 178 179 180
      sdServerType: 'common',
      sdServerTypeOptions: [
        { label: '公共服务器', value: 'common' },
        { label: '私有服务器', value: 'private' },
      ],
181
      sdServerUrl: '',
182 183 184 185 186
      loading: false,
      maxHistory: 200,
      speaking: false, // 是否正在输出语音
      autoSpeech: false, // 是否自动开始语音
      speech: null, // 语音object
187 188 189 190 191
      options: [
        { content: '绘图模式', value: 'draw' },
        { content: '聊天模式', value: 'chat' },
        { content: '自动模式', value: 'auto' },
      ],
192
      showProfileSetting: false, //是否显示角色设置模块
193 194 195 196
      width: 512,
      height: 512,
      steps: 20,
      sampler: 'DPM++ SDE Karras',
197
      showMoreSetting: false,
198
      default_prompt: '1girl, (ulzzang-6500:0.7), kpop idol, yae miko, detached sleeves, bare shoulders, pink hair, long hair, cleavage,japanese clothes,breast,best quality, (painting:1.5), (hair ornament:1.35), jewelry, purple eyes, earrings, breasts, torii, cherry blossoms, lantern light, depth of field, detailed face, face focus, ribbon_trim, (looking at viewer:1.25), nontraditional miko, shiny skin, long sleeves, smile, thick lips, game cg,  east asian architecture, (blurry background:1.2), sitting, upper body <lora:YaeMiko_Test:0.45>,<lora:mix4:0.5>',
6
622aa39c1f9b166ab1a38c05 已提交
199
      negative_prompt: 'nfsw, bright lantern, brightness, (nipples:1.2), pussy, EasyNegative, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, glans,extra fingers, fewer fingers, strange fingers, bad hand, bare thighs,hand,bad finger',
200 201 202 203
      history: {
        name: 'ai',
        key: 'history',
      },
204 205 206 207 208 209 210 211 212 213 214
      mdOptions: {
        markdownIt: {
          linkify: true
        },
        linkAttributes: {
          attrs: {
            target: '_blank',
            rel: 'noopener'
          }
        }
      }
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
    }
  },
  methods: {
    hideLeftMenu() {

    },
    changeUserAvatar(imgSrc) {
      this.config.user_img = imgSrc
    },
    changeRobotAvatar(imgSrc) {
      this.config.robot_img = imgSrc
    },
    getAvatar() {
      let that = this
      DataServe.find('t_llm_rep_chat_img', { resoure_sub_type: 'user_avatar' }).then(res => {
        if (res && res.status === 200 && res.data && res.data.code === 200 && res.data.data) {
          const data = res.data.data
          for (let item of data) {
            that.userAvatarList.push({
              src: JSON.parse(item.ext).img_src,
              name: item.name
            })
          }
        }
      })

      DataServe.find('t_llm_rep_chat_img', { resoure_sub_type: 'robot_avatar' }).then(res => {
        if (res && res.status === 200 && res.data && res.data.code === 200 && res.data.data) {
          const data = res.data.data
          for (let item of data) {
            that.robotAvatarList.push({
              src: JSON.parse(item.ext).img_src,
              name: item.name
            })
          }
        }
      })
    },
    initAIClient () {
254 255
      // this.client = new OpenAI(this.config)
      this.client = new InsCodeAI(this.config)
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
    },
    initIndexClient () {
      if (this.config?.index_url) {
        const index_type = this.config?.index_type
        //confluence
        if (index_type === 'es') {
          this.indexClient = new RepEs(this.config)
        } else if(index_type === 'confluence') {
          this.indexClient = new RepConfluence(this.config)
        } else {
          this.indexClient = new RepSimple(this.config)
        }
      } 
    },
    query() {
6
622aa39c1f9b166ab1a38c05 已提交
271
      
272 273 274 275 276 277 278 279 280 281 282
      if (this.loading) {
        MessagePlugin.warning({ content: '正在执行中,请稍等!', placement: 'center' })
        return
      }
      if (this.prompt === '') {

        MessagePlugin.warning({ content: '提示词不能为空!', placement: 'center' })
        console.info('提示词不能为空')
        return
      }
      
283 284 285
      this.loading = true


286 287
      if (this.mode === 'draw') {
        this.draw()
288
      } else {
289

290 291 292 293 294 295 296 297 298 299 300 301

        const _this = this
        const messages = this.message
        const currentMsg = {
          "user": "AI", "message": ''
        }
        const newPrompt = this.prompt
        this.prompt = ''
        messages.push({ "user": "User", "message": newPrompt })
        messages.push(currentMsg)
        _this.$refs.messageList.scrollTop = _this.$refs.messageList.scrollHeight;
        
302
        if (this.indexClient) {
303 304
          this.indexClient.query(newPrompt).then(res => {
            this.getAnswer(res, newPrompt, currentMsg)
305
          }).catch((err) => {
306
            this.getAnswer(null, newPrompt, currentMsg)
307
          })
308 309
        }else {
          this.getAnswer(null, newPrompt, currentMsg)
310
        }
311
      }
312 313 314 315 316 317 318 319 320
      // if (this.indexClient) {
      //   this.indexClient.query(this.prompt).then(res => {
      //     this.getAnswer(res)
      //   }).catch((err) => {
      //     this.getAnswer()
      //   })
      // } else {
      //   this.getAnswer()
      // }
6
UPDATE  
64104061f23fda247c679fa8 已提交
321

322 323 324 325 326 327 328
    },
    scrollBottom () {
      const _this = this
      this.$nextTick(() => {
        _this.$refs.messageList.scrollTop = _this.$refs.messageList.scrollHeight + 20;
      })
      
329
    },
330 331
    draw () {

6
622aa39c1f9b166ab1a38c05 已提交
332
      this.loading = true
333 334 335 336
      const currentMsg = {
        "user": "AI", "message": '', img: null, viewMode: 'image'
      }
      const query = this.prompt
337
      const negative_prompt = this.negative_prompt
338 339
      const _this = this
      const messages = this.message
340 341 342 343 344
      const content = 'prompt: <br/>' + 
                        this.prompt + 
                        (negative_prompt ? '<br/><br/>' + 'negative_prompt: </br>' + negative_prompt : '') + '<br/><br/>' +
                        'width: ' + this.width + ' height: ' + this.height + '<br/>steps: ' + this.steps +'<br/>sampler: ' + this.sampler 
      messages.push({ "user": "User", "message": content })
345 346 347

      messages.push(currentMsg)

348
      // this.prompt = ''
349
      this.scrollBottom()
350 351 352 353 354
      const config = JSON.parse(JSON.stringify(this.config)) 
      config.width = this.width
      config.height = this.height
      config.steps = this.steps
      config.sampler = this.sampler
355
      config.sd_api = this.sdServerUrl
356 357

      SDApi.draw(config, query, negative_prompt).then(res => {
358 359

        _this.loading = false
360
        
361 362 363 364 365
        console.info('close')
        currentMsg.img = res

        messages.splice(messages.length - 1, 1)
        messages.push(currentMsg)
366
        _this.scrollBottom()
367
        _this.saveHistory()
368 369
        

370 371 372 373
      }).catch(err => {
        _this.loading = false
      })
    },
374 375 376 377
    getAnswer(context = null, prompt = null, currentMsg = null) {


      const newPrompt = prompt ? prompt : this.prompt
378
      const _this = this
379
      this.config.api_url = this.sdServerUrl
380
      const messages = this.message
381
      this.scrollBottom()
382 383 384 385 386 387 388
      this.client.createCompletion(
        newPrompt,
        this.message,
        context,
        {
          onmessage: (msg, isPart) => {
            // _this.set(_this.message, id, currentMsg)
389
            // console.info(msg)
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
            if (isPart) {
              currentMsg.message += msg
            } else {
              currentMsg.message = msg
            }

            messages.splice(messages.length - 1, 1)
            messages.push(currentMsg)
            _this.$refs.messageList.scrollTop = _this.$refs.messageList.scrollHeight;
            // console.info(currentMsg.message)
          },
          onclose: () => {
            _this.loading = false
            _this.saveHistory()
            console.info('close')
            if(_this.autoSpeech) {
              _this.speak()
            }
          },
          onerror: (err) => {
            _this.loading = false
            console.info(err)
          }
        })
    },
    getAppInfo() {


418
      const data = Config.getData().data
419 420 421
      this.name = data.name
      document.title = this.name
      if (data.ext) {
422
        const config = data.ext
423
        
424
        this.config = config
W
weixin_44463441 已提交
425
        
426 427 428 429
        console.info(config)
      }
    },
    recoveryHistory() {
430

431
      StorageApi.get(this.history.name).then(data => {
432
        if (data && data.data) {
433 434 435 436 437
          const historyMessage = JSON.parse(data.data)
          if (historyMessage !== null && historyMessage.length > 0) {
            this.message = historyMessage
          }
          
438 439
        }
      })      
440 441 442 443 444 445 446 447 448
    },
    saveHistory() {
      if (this.message.length > this.maxHistory) {
        const tmpHistory = []
        const start = this.message.length - this.maxHistory
        const end = this.message.length
        for (let id = start; id < end; id++) {
          tmpHistory.push(this.message[id])
        }
449
        StorageApi.put(this.history.name, JSON.stringify(tmpHistory))
450
      } else {
451
        StorageApi.put(this.history.name, JSON.stringify(this.message))
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
      }

    },
    cleanHistory() {
      this.message = []
      this.saveHistory()
    },
    initSpeaker () {
      window.speechSynthesis.cancel()
      this.speech = new SpeechSynthesisUtterance();
      this.speech.onend = () => {
        console.log("语音播报结束")
        this.speaking = false
      }
    },
    speak () {
       this.speaking = true
        const content = this.message[this.message.length - 1].message
        if (content && content.length > 1) {
          // var utterThis = new SpeechSynthesisUtterance(text);
          this.speech.text = content;
          console.info('speak ' + content)
          // speech.lang = 'zh';//汉语
          window.speechSynthesis.speak(this.speech);
        }
        
    },
    stop () {
      this.client.close()
    },
    copyAsPrompt (message) {
      this.prompt = message
484
    },
485
    handleSDServerTypeChange (type) {
486 487
      
      if (type === 'common') {
488
        
489
        this.sdServerUrl = this.config.common_gpt_url
490
      }
491
      this.saveConfig()
492 493
    },
    recoverConfig () {
494
      const config = localStorage.getItem('ai-docs-config')
495
      
496 497 498 499
      if (config) {
        const configJSON = JSON.parse(config)
        this.config = configJSON
        this.sdServerUrl = configJSON.sdServerUrl
500 501 502 503 504
        this.sdServerType = configJSON.sdServerType??'common'

        const data = Config.getData().data
        this.name = data.name
        document.title = this.name
6
622aa39c1f9b166ab1a38c05 已提交
505

506
        
W
weixin_44463441 已提交
507 508 509 510 511
        if (data.ext) {
          if (data.ext.common_gpt_url && this.sdServerType === 'common') {
            this.config.common_gpt_url = data.ext.common_gpt_url
            this.sdServerUrl = data.ext.common_gpt_url
          }
512
          
W
weixin_44463441 已提交
513 514 515
          if (data.ext.api_prompt_prefix) {
            this.config.api_prompt_prefix = data.ext.api_prompt_prefix
          }
516
          this.config.prompt_template = data.ext.prompt_template
W
weixin_44463441 已提交
517
          this.config.welcome_text = data.ext.welcome_text
W
weixin_44463441 已提交
518
          this.config.temperature = data.ext?.temperature??0.7
519
        }
W
weixin_44463441 已提交
520
        
6
622aa39c1f9b166ab1a38c05 已提交
521

522
      } else {
523
        
524
        this.getAppInfo()
525
        this.sdServerUrl = this.config.common_gpt_url
526
        this.sdServerType = 'common'
527 528 529 530
        
      }
    },
    saveConfig () {
531
      
532 533 534
      const config = JSON.parse(JSON.stringify(this.config))
      config.sdServerType = this.sdServerType
      config.sdServerUrl = this.sdServerUrl
535
      config.sdServerType = this.sdServerType
536
      localStorage.setItem('ai-docs-config', JSON.stringify(config))
537 538 539 540 541 542 543
    },
    getPods () {

      PodsApi.getPods().then(res => {


      })
W
weixin_44463441 已提交
544 545
    },
    initChat() {
546
      
W
weixin_44463441 已提交
547 548 549 550 551 552 553 554 555 556 557 558 559 560
      this.initAIClient()
      this.initIndexClient()
      const config = this.config

      if (config.default_prompt) {
        this.prompt = config.default_prompt
      }
      if (config?.auto_speech??false) {
        this.autoSpeech = true
        this.initSpeaker()
      }
      if (config?.welcome_text && config?.welcome_text.length > 0 && this.message.length === 0) {
        this.message.push({
          "user": "AI", 
561 562
          "message": config.welcome_text,
          "ignore": true,
W
weixin_44463441 已提交
563 564 565 566
        })
      }
      this.showProfileSetting = config?.show_profile_setting??false

567 568 569 570
    }
  },
  mounted() {
    this.id = this.$route?.params?.id
571 572 573
    StorageApi.init(this.history.name).then(res => {
      this.recoveryHistory()
    })
574
    this.recoverConfig()
575
    // this.getAvatar()
576
    if (this.mode === 'chat') {
W
weixin_44463441 已提交
577
      this.initChat()
578
    }
579
  } 
580 581 582 583 584 585 586 587 588 589 590

};
</script>


<style>
.text-wrapper {
  white-space: pre-wrap;
}
.vuepress-markdown-body {
  padding: 16px !important;
6
UPDATE  
64104061f23fda247c679fa8 已提交
591 592
}
</style>
593