冲刺记录15
今天任务:添加物品识别功能
遇到困难:识别出来的内容只显示在后端,没有显示到界面上
<template>
<view class="container">
<view v-for="(message, index) in historyTextList" :key="index" :class="{'user-message': message.role === 'user', 'bot-message': message.role === 'assistant'}">
<text>{{ message.content }}</text>
</view>
<view class="fixed-input-container">
<input v-model="TEXT" class="input-field" />
<button class="send-button" @click="sendToSpark()">send</button>
</view>
</view>
</template>
<script>
import * as base64 from "base-64"
import CryptoJS from '../../static/crypto-js/crypto-js.js'
import parser from '../../static/fast-xml-parser/src/parser'
import * as utf8 from "utf8"
import URL from 'url'
export default {
data() {
return {
TEXT:"",
httpUrl: "https://spark-api.xf-yun.com/v3.5/chat",
modelDomain: '',
APPID: '058ab497',
APISecret: 'ODRjYjkxZDkwYzJlN2UyNGM2MjlkZDA2',
APIKey: '9f72399979c03be474a3af799e41cc9b',
sparkResult: '',
historyTextList: [],
tempRes: ''
}
},
methods: {
async sendToSpark() {
let myUrl = await this.getWebSocketUrl();
this.tempRes = "";
let realThis = this;
this.socketTask = uni.connectSocket({
url: myUrl,
method: 'GET',
success: res => {
console.log(res, "ws成功连接...", myUrl)
realThis.wsLiveFlag = true;
}
})
realThis.socketTask.onError((res) => {
console.log("连接发生错误,请检查appid是否填写", res)
})
realThis.socketTask.onOpen((res) => {
this.historyTextList.push({
"role": "user",
"content": this.TEXT
})
console.info("wss的onOpen成功执行...", res)
let params = {
"header": {
"app_id": this.APPID,
"uid": "aef9f963-7"
},
"parameter": {
"chat": {
"domain": this.modelDomain,
"temperature": 0.5,
"max_tokens": 1024
}
},
"payload": {
"message": {
"text": this.historyTextList
}
}