File tree 1 file changed +13
-3
lines changed
1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -46,23 +46,33 @@ export default class AiChat extends Service {
46
46
47
47
async getAnswerFromAi ( messages : Array < AiMessage > , chatConfig : any ) {
48
48
let res = await this . requestAnswerFromAi ( messages , chatConfig ) ;
49
+ console . log ( res ) ;
49
50
let answerContent = '' ;
51
+ let isFinish = res . choices [ 0 ] . finish_reason ;
52
+
53
+ if ( isFinish !== 'length' ) {
54
+ answerContent = res . choices [ 0 ] ?. message . content ;
55
+ }
56
+
50
57
// 若内容过长被截断,继续回复
51
- if ( res . choices [ 0 ] . finish_reason == 'length' ) {
58
+ while ( isFinish = == 'length' ) {
52
59
const prefix = res . choices [ 0 ] . message . content ;
53
60
answerContent += prefix ;
54
61
messages . push ( {
55
62
role : 'assistant' ,
56
63
content : prefix ,
57
64
partial : true
58
65
} ) ;
66
+
59
67
res = await this . requestAnswerFromAi ( messages , chatConfig ) ;
60
- answerContent += res . choices [ 0 ] ?. message . content ;
68
+ answerContent += res . choices [ 0 ] . message . content ;
69
+ isFinish = res . choices [ 0 ] . finish_reason ;
61
70
}
71
+
62
72
const code = this . extractCode ( answerContent ) ;
63
73
const schema = this . extractSchemaCode ( code ) ;
64
74
const answer = {
65
- role : res . choices [ 0 ] ? .message . role ,
75
+ role : res . choices [ 0 ] . message . role ,
66
76
content : answerContent
67
77
} ;
68
78
const replyWithoutCode = this . removeCode ( answerContent ) ;
You can’t perform that action at this time.
0 commit comments