Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/AssistantFormOutputs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
:optional-shape-options="selectedTaskType.optionalOutputShapeEnumValues ?? null"
:values="outputs"
:show-advanced="showAdvanced"
:can-improve-output="canImproveOutput"
@update:values="$emit('update:outputs', $event)"
@update:show-advanced="$emit('update:show-advanced', $event)" />
@update:show-advanced="$emit('update:show-advanced', $event)"
@improve="$emit('improve', $event)" />
<NcNoteCard v-if="outputEqualsInput"
class="warning-note"
type="warning">
Expand Down Expand Up @@ -70,11 +72,16 @@ export default {
type: Boolean,
default: false,
},
canImproveOutput: {
type: Boolean,
default: false,
},
},

emits: [
'update:outputs',
'update:show-advanced',
'improve',
],

computed: {
Expand Down
35 changes: 34 additions & 1 deletion src/components/AssistantTextProcessingForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@
v-model:show-advanced="showAdvanced"
v-model:outputs="myOutputs"
:inputs="myInputs"
:selected-task-type="selectedTaskType" />
:selected-task-type="selectedTaskType"
:can-improve-output="canImproveOutput"
@improve="onImprove" />
</div>
<div class="footer">
<div class="footer--action-buttons">
Expand Down Expand Up @@ -215,6 +217,7 @@ import { saveLastSelectedTaskType } from '../assistant.js'

const TEXT2TEXT_TASK_TYPE_ID = 'core:text2text'
const CHAT_TASK_TYPE_ID = 'chatty-llm'
const TEXT2TEXT_IMPROVE_TASK_TYPE_ID = 'core:text2text:improve'

export default {
name: 'AssistantTextProcessingForm',
Expand Down Expand Up @@ -460,6 +463,20 @@ export default {
actionButtonsToShow() {
return this.hasOutput ? this.actionButtons : []
},
improveTaskType() {
const taskType = this.taskTypes.find(tt => tt.id === TEXT2TEXT_IMPROVE_TASK_TYPE_ID)
if (taskType === undefined) {
return null
}
if (this.taskTypeIdList !== null && !this.taskTypeIdList.includes(TEXT2TEXT_IMPROVE_TASK_TYPE_ID)) {
return null
}
return taskType
},
canImproveOutput() {
return this.hasOutput
&& this.improveTaskType !== null
},
showRunningEmptyContent() {
return this.showSyncTaskRunning && this.myOutputs === null
},
Expand All @@ -484,6 +501,22 @@ export default {
console.debug('[assistant] form\'s myoutputs', this.myOutputs)
},
methods: {
onImprove(content) {
if (!this.canImproveOutput) {
return
}
this.$emit('new-task')
this.mySelectedTaskTypeId = TEXT2TEXT_IMPROVE_TASK_TYPE_ID
this.$nextTick(() => {
this.$refs?.assistantFormInputs?.setDefaultValues(true)
this.$nextTick(() => {
this.myInputs = {
...this.myInputs,
input: content,
}
})
})
},
// Parse the file if a fileId is passed as initial value to a text field
parseTextFileInputs(taskType) {
if (taskType === undefined || taskType === null) {
Expand Down
12 changes: 11 additions & 1 deletion src/components/fields/TaskTypeField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
:field="field"
:options="options ?? undefined"
:is-output="isOutput"
:can-improve-output="isTextField ? canImproveOutput : false"
@submit="$emit('submit', $event)"
@update:value="$emit('update:value', $event)" />
@update:value="$emit('update:value', $event)"
@improve="$emit('improve', $event)" />
</template>

<script>
Expand Down Expand Up @@ -56,11 +58,16 @@ export default {
type: [Object, Array, null],
default: null,
},
canImproveOutput: {
type: Boolean,
default: false,
},
},

emits: [
'submit',
'update:value',
'improve',
],

data() {
Expand Down Expand Up @@ -91,6 +98,9 @@ export default {
}
return (this.defaults && this.defaults[this.fieldKey] && parseInt(this.defaults[this.fieldKey]) < 10)
},
isTextField() {
return this.field.type === SHAPE_TYPE_NAMES.Text
},
component() {
if (this.field.type === SHAPE_TYPE_NAMES.Text) {
return TextField
Expand Down
13 changes: 11 additions & 2 deletions src/components/fields/TaskTypeFields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
:options="getInputFieldOptions(field, key)"
:is-output="isOutput"
:defaults="defaults"
:can-improve-output="canImproveOutput"
@submit="onSubmit"
@update:value="onValueChange(key, $event)" />
@update:value="onValueChange(key, $event)"
@improve="$emit('improve', $event)" />
<!--NcButton v-if="hasOptionalShape"
@click="$emit('update:show-advanced', !showAdvanced)">
<template #icon>
Expand All @@ -32,7 +34,9 @@
:options="getOptionalInputFieldOptions(field, key)"
:is-output="isOutput"
:defaults="optionalDefaults"
@update:value="onValueChange(key, $event)" />
:can-improve-output="canImproveOutput"
@update:value="onValueChange(key, $event)"
@improve="$emit('improve', $event)" />
</div>
</div>
</template>
Expand Down Expand Up @@ -84,11 +88,16 @@ export default {
type: Boolean,
default: false,
},
canImproveOutput: {
type: Boolean,
default: false,
},
},

emits: [
'submit',
'update:values',
'improve',
],

data() {
Expand Down
9 changes: 8 additions & 1 deletion src/components/fields/TextField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
:label="field.description"
:placeholder="field.placeholder ?? field.description"
:title="field.name"
:can-improve-output="canImproveOutput"
@submit="onSubmit"
@update:value="onUpdateValue" />
@update:value="onUpdateValue"
@improve="$emit('improve', $event)" />
</template>

<script>
Expand Down Expand Up @@ -42,11 +44,16 @@ export default {
type: Boolean,
default: false,
},
canImproveOutput: {
type: Boolean,
default: false,
},
},

emits: [
'submit',
'update:value',
'improve',
],

data() {
Expand Down
77 changes: 51 additions & 26 deletions src/components/fields/TextInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,36 @@
:title="title"
@submit="hasValue && $emit('submit', $event)"
@update:model-value="$emit('update:value', $event)" />
<NcButton v-if="isOutput && hasValue"
class="copy-button"
variant="secondary"
:title="t('assistant', 'Copy output')"
@click="onCopy">
<template #icon>
<NcLoadingIcon v-if="streaming()" />
<ClipboardCheckOutlineIcon v-else-if="copied" />
<ContentCopyIcon v-else />
</template>
<span v-if="streaming()">
{{ t('assistant', 'Getting results...') }}
</span>
<span v-else>
{{ t('assistant', 'Copy') }}
</span>
</NcButton>
<div v-if="isOutput && hasValue"
class="output-buttons">
<NcButton v-if="!streaming() && canImproveOutput"
class="improve-button"
variant="secondary"
:title="t('assistant', 'Improve with new instructions')"
@click="$emit('improve', formattedValue)">
<template #icon>
<WrenchOutlineIcon size="20" />
</template>
{{ t('assistant', 'Improve this text') }}
Comment thread
lukasdotcom marked this conversation as resolved.
</NcButton>
<NcButton
class="copy-button"
variant="secondary"
:title="t('assistant', 'Copy output')"
@click="onCopy">
<template #icon>
<NcLoadingIcon v-if="streaming()" size="20" />
<ClipboardCheckOutlineIcon v-else-if="copied" size="20" />
<ContentCopyIcon v-else size="20" />
</template>
<span v-if="streaming()">
{{ t('assistant', 'Getting results...') }}
</span>
<span v-else>
{{ t('assistant', 'Copy') }}
</span>
</NcButton>
</div>
<NcButton v-if="!isOutput && !hasValue && showChooseButton"
class="choose-file-button"
variant="secondary"
Expand All @@ -54,6 +67,7 @@
<script>
import FileDocumentOutlineIcon from 'vue-material-design-icons/FileDocumentOutline.vue'
import ClipboardCheckOutlineIcon from 'vue-material-design-icons/ClipboardCheckOutline.vue'
import WrenchOutlineIcon from 'vue-material-design-icons/WrenchOutline.vue'
import ContentCopyIcon from 'vue-material-design-icons/ContentCopy.vue'

import NcButton from '@nextcloud/vue/components/NcButton'
Expand Down Expand Up @@ -89,15 +103,14 @@ export default {
FileDocumentOutlineIcon,
ClipboardCheckOutlineIcon,
ContentCopyIcon,
WrenchOutlineIcon,
},

mixins: [
isMobile,
],

inject: [
'streaming',
],
inject: ['streaming'],

props: {
id: {
Expand Down Expand Up @@ -128,11 +141,16 @@ export default {
type: Boolean,
default: true,
},
canImproveOutput: {
type: Boolean,
default: false,
},
},

emits: [
'submit',
'update:value',
'improve',
],

data() {
Expand Down Expand Up @@ -230,21 +248,28 @@ body[dir="rtl"] .choose-file-button {
right: unset;
}

body[dir="rtl"] .output-buttons {
left: 4px;
right: unset;
}

.text-input {
position: relative;

.copy-button,
.output-buttons,
.choose-file-button {
position: absolute !important;
}

.choose-file-button {
bottom: 2px;
}

.copy-button {
.output-buttons {
bottom: 4px;
right: 4px;
display: flex;
gap: 4px;
}

.choose-file-button {
bottom: 2px;
}

.rich-contenteditable__input {
Expand Down
Loading