12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- const api_key = 'app-fxpiWOYqtJM1BOaJnG54NlCZ'
- const url = 'https://ai.xsip.cn/v1'
- import { formatDate } from '@/utils';
- export default {
- data() {
- return {
- controller:null
- }
- },
- computed:{
- userinfo(){
- return this.$s.getObj('userinfo')
- }
- },
- methods: {
- async getResult(){
- if(this.loading){
- this.$message.warning('请等当前执行完成')
- return
- }
- this.loading = true
- this.result = null
- let header = {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${api_key}`,
- }
- let data = {
- inputs:{
- claim:this.claim
- },
- response_mode:'blocking',
- user:this.userinfo.id
- }
- this.controller = new AbortController();
- let res = await fetch(url + '/workflows/run', {
- method: 'POST',
- headers: header,
- body: JSON.stringify(data),
- signal: this.controller.signal
- })
- if(res.ok){
- const reader = res.body.getReader();
- const decoder = new TextDecoder('utf-8');
- while (true) {
- const { done, value } = await reader.read();
- if(done){
- break
- }
- const chunk = decoder.decode(value);
- if(chunk){
- try{
- let json = JSON.parse(chunk)
- this.result = json.data.outputs?json.data.outputs.json:{}
- this.saveSession(json)
- }catch(e){
- }finally{
- this.loading = false
- this.controller = null;
- }
- }
- }
- }
- },
- cancelRun(){
- if (this.controller) {
- this.controller.abort();
- }
- this.loading = false
- },
- //保存会话
- saveSession(json){
- let data = json.data
- let time = formatDate(new Date(),"YYYY-MM-DD HH:mm:ss")
- let content = {
- query:{
- claim:this.claim,
- },
- answer:data.outputs?data.outputs.json:{}
- }
- let params = {
- conversationId:data.id,
- conversationName:time+'-权利要求解释及有益效果',
- content:JSON.stringify(content),
- type:1
- }
- this.$api.addSession(params).then(response=>{
- if(response.code == 200){
- this.queryConfessionSession()
- }
- })
- },
- },
- }
|