@@ -26,19 +26,7 @@ const messages: any = ref([])
26
26
const loading = ref (false )
27
27
const ask_buffer = ref (' ' )
28
28
29
- async function send() {
30
- if (messages .value .length === 0 ) {
31
- messages .value .push ({
32
- role: ' user' ,
33
- content: props .content + ' \n\n Current Language Code: ' + current
34
- })
35
- } else {
36
- messages .value .push ({
37
- role: ' user' ,
38
- content: ask_buffer .value
39
- })
40
- ask_buffer .value = ' '
41
- }
29
+ async function request() {
42
30
loading .value = true
43
31
const t = ref ({
44
32
role: ' assistant' ,
@@ -110,6 +98,22 @@ async function send() {
110
98
111
99
}
112
100
101
+ async function send() {
102
+ if (messages .value .length === 0 ) {
103
+ messages .value .push ({
104
+ role: ' user' ,
105
+ content: props .content + ' \n\n Current Language Code: ' + current
106
+ })
107
+ } else {
108
+ messages .value .push ({
109
+ role: ' user' ,
110
+ content: ask_buffer .value
111
+ })
112
+ ask_buffer .value = ' '
113
+ }
114
+ await request ()
115
+ }
116
+
113
117
const renderer = new marked .Renderer ()
114
118
renderer .code = (code , lang : string ) => {
115
119
const language = hljs .getLanguage (lang ) ? lang : ' nginx'
@@ -134,6 +138,22 @@ function store_record() {
134
138
messages: messages .value
135
139
})
136
140
}
141
+
142
+ function clear_record() {
143
+ openai .store_record ({
144
+ file_name: props .path ,
145
+ messages: []
146
+ })
147
+ messages .value = []
148
+ }
149
+
150
+ async function regenerate(index : number ) {
151
+ editing_idx .value = - 1
152
+ messages .value = messages .value .slice (0 , index )
153
+ await request ()
154
+ }
155
+
156
+ const editing_idx = ref (- 1 )
137
157
</script >
138
158
139
159
<template >
@@ -145,17 +165,46 @@ function store_record() {
145
165
item-layout =" horizontal"
146
166
:data-source =" messages"
147
167
>
148
- <template #renderItem =" { item } " >
168
+ <template #renderItem =" { item , index } " >
149
169
<a-list-item >
150
170
<a-comment :author =" item.role" :avatar =" item.avatar" >
151
171
<template #content >
152
- <div class =" content" v-html =" marked.parse(item.content)" ></div >
172
+ <div class =" content" v-if =" item.role==='assistant'||editing_idx!=index"
173
+ v-html =" marked.parse(item.content)" ></div >
174
+ <a-input style =" padding : 0 " v-else v-model:value =" item.content"
175
+ :bordered =" false" />
176
+ </template >
177
+ <template #actions >
178
+ <span v-if =" item.role==='user'&&editing_idx!==index" @click =" editing_idx=index" >
179
+ {{ $gettext('Modify') }}
180
+ </span >
181
+ <template v-else-if =" editing_idx == index " >
182
+ <span @click =" regenerate(index+1)" >{{ $gettext('Save') }}</span >
183
+ <span @click =" editing_idx=-1" >{{ $gettext('Cancel') }}</span >
184
+ </template >
185
+ <span v-else-if =" !loading" @click =" regenerate(index)" :disabled =" loading" >
186
+ {{ $gettext('Reload') }}
187
+ </span >
153
188
</template >
154
189
</a-comment >
155
190
</a-list-item >
156
191
</template >
157
192
</a-list >
158
193
<div class =" input-msg" >
194
+ <div class =" control-btn" >
195
+ <a-space v-show =" !loading" >
196
+ <a-popconfirm
197
+ :cancelText =" $gettext('No')"
198
+ :okText =" $gettext('OK')"
199
+ :title =" $gettext('Are you sure you want to clear the record of chat?')"
200
+ @confirm =" clear_record" >
201
+ <a-button type =" text" >{{ $gettext('Clear') }}</a-button >
202
+ </a-popconfirm >
203
+ <a-button type =" text" @click =" regenerate(messages?.length-1)" >
204
+ {{ $gettext('Regenerate response') }}
205
+ </a-button >
206
+ </a-space >
207
+ </div >
159
208
<a-textarea auto-size v-model:value =" ask_buffer" />
160
209
<div class =" sned-btn" >
161
210
<a-button size =" small" type =" text" :loading =" loading" @click =" send" >
@@ -209,6 +258,11 @@ function store_record() {
209
258
.input-msg {
210
259
position : relative ;
211
260
261
+ .control-btn {
262
+ display : flex ;
263
+ justify-content : center ;
264
+ }
265
+
212
266
.sned-btn {
213
267
position : absolute ;
214
268
right : 0 ;
0 commit comments