@@ -315,23 +315,53 @@ export default {
315
315
console .debug (' [assistant] form\' s myoutputs' , this .myOutputs )
316
316
},
317
317
methods: {
318
+ // Parse the file if a fileId is passed as initial value to a text field
319
+ parseTextFileInputs (taskType ) {
320
+ if (taskType === undefined || taskType === null ) {
321
+ return
322
+ }
323
+ Object .keys (this .myInputs ).forEach (k => {
324
+ if (taskType .inputShape [k]? .type === ' Text' ) {
325
+ if (this .myInputs [k]? .fileId || this .myInputs [k]? .filePath ) {
326
+ const { filePath , fileId } = { fileId: this .myInputs [k]? .fileId , filePath: this .myInputs [k]? .filePath }
327
+ this .myInputs [k] = ' '
328
+ this .parseFile ({ fileId, filePath })
329
+ .then (response => {
330
+ if (response .data ? .ocs ? .data ? .parsedText ) {
331
+ this .myInputs [k] = response .data ? .ocs ? .data ? .parsedText
332
+ }
333
+ })
334
+ }
335
+ }
336
+ })
337
+ },
338
+ parseFile ({ filePath, fileId }) {
339
+ const url = generateOcsUrl (' /apps/assistant/api/v1/parse-file' )
340
+ return axios .post (url, {
341
+ filePath,
342
+ fileId,
343
+ })
344
+ },
318
345
getTaskTypes () {
319
346
this .loadingTaskTypes = true
320
347
axios .get (generateOcsUrl (' /apps/assistant/api/v1/task-types' ))
321
348
.then ((response ) => {
322
- this . taskTypes = response .data .ocs .data .types
349
+ const taskTypes = response .data .ocs .data .types
323
350
// check if selected task type is in the list, fallback to text2text
324
- const taskType = this . taskTypes .find (tt => tt .id === this .mySelectedTaskTypeId )
351
+ const taskType = taskTypes .find (tt => tt .id === this .mySelectedTaskTypeId )
325
352
if (taskType === undefined ) {
326
- const text2textType = this . taskTypes .find (tt => tt .id === TEXT2TEXT_TASK_TYPE_ID )
353
+ const text2textType = taskTypes .find (tt => tt .id === TEXT2TEXT_TASK_TYPE_ID )
327
354
if (text2textType) {
355
+ this .parseTextFileInputs (text2textType)
328
356
this .mySelectedTaskTypeId = TEXT2TEXT_TASK_TYPE_ID
329
357
} else {
330
358
this .mySelectedTaskTypeId = null
331
359
}
360
+ } else {
361
+ this .parseTextFileInputs (taskType)
332
362
}
333
363
// add placeholders
334
- this . taskTypes .forEach (tt => {
364
+ taskTypes .forEach (tt => {
335
365
if (tt .id === TEXT2TEXT_TASK_TYPE_ID && tt .inputShape .input ) {
336
366
tt .inputShape .input .placeholder = t (' assistant' , ' Generate a first draft for a blog post about privacy' )
337
367
} else if (tt .id === ' context_chat:context_chat' && tt .inputShape .prompt ) {
@@ -350,6 +380,7 @@ export default {
350
380
tt .inputShape .source_input .placeholder = t (' assistant' , ' A description of what you need or some original content' )
351
381
}
352
382
})
383
+ this .taskTypes = taskTypes
353
384
})
354
385
.catch ((error ) => {
355
386
console .error (error)
0 commit comments