Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Germey committed Dec 31, 2023
1 parent e9474ba commit bea3698
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
57 changes: 41 additions & 16 deletions src/components/chat/InputBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<div class="input-box">
<el-upload
v-model:file-list="fileList"
class="upload"
:class="{
upload: true,
disabled: !canUpload
}"
:disabled="!canUpload"
name="file"
:show-file-list="true"
:limit="1"
Expand All @@ -22,14 +26,14 @@
:class="{
btn: true,
'btn-send': true,
disabled: !value
disabled: !question
}"
@click="onSubmit"
>
<font-awesome-icon icon="fa-solid fa-location-arrow" class="icon icon-send" />
</span>
<el-input
v-model="value"
v-model="questionValue"
:rows="1"
class="input"
type="textarea"
Expand All @@ -45,6 +49,7 @@
import { defineComponent } from 'vue';
import { ElInput, ElMessage, ElTooltip, ElUpload } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { CHAT_MODEL_CHATGPT4_VISION, IChatModel } from '@/operators';
export default defineComponent({
name: 'InputBox',
Expand All @@ -55,15 +60,20 @@ export default defineComponent({
ElUpload
},
props: {
modelValue: {
references: {
type: Array,
required: false,
default: () => []
},
question: {
type: String,
required: true
}
},
emits: ['update:modelValue', 'submit'],
emits: ['update:question', 'update:references', 'submit'],
data() {
return {
value: this.modelValue,
questionValue: this.question,
fileList: []
};
},
Expand All @@ -73,27 +83,34 @@ export default defineComponent({
Authorization: `Bearer ${this.$store.state.token.access}`
};
},
urls() {
urls(): string[] {
// @ts-ignore
return this.fileList.map((file: UploadFile) => file?.response?.file_url);
},
canUpload() {
return [CHAT_MODEL_CHATGPT4_VISION.name].includes(this.model.name);
},
model(): IChatModel {
return this.$store.state.chat.model;
}
},
watch: {
value(val) {
this.$emit('update:modelValue', val);
urls(val) {
this.$emit('update:references', val);
},
modelValue(val) {
if (val !== this.value) {
this.value = val;
}
questionValue(val: string) {
this.$emit('update:question', val);
}
// question(val: string) {
// this.questionValue = val;
// }
},
methods: {
onSubmit() {
if (!this.value) {
if (!this.question) {
return;
}
this.$emit('submit', this.value);
this.$emit('submit');
},
onExceed() {
ElMessage.warning(this.$t('chat.message.uploadReferencesExceed'));
Expand All @@ -118,7 +135,7 @@ export default defineComponent({
}
.el-upload-list {
position: absolute;
width: 200px;
width: 400px;
bottom: 40px;
}
}
Expand All @@ -135,6 +152,14 @@ export default defineComponent({
top: 40px;
.upload {
display: inline-block;
&.disabled {
.btn-upload {
cursor: not-allowed;
.icon-attachment {
color: #eee;
}
}
}
}
.input {
border: none;
Expand Down
1 change: 1 addition & 0 deletions src/operators/chat/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface IChatConversationOptions {

export interface IChatAskRequest {
question: string;
references?: string[];
stateful?: boolean;
conversation_id?: string;
}
Expand Down
13 changes: 11 additions & 2 deletions src/pages/chat/Conversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
</div>
</div>
<div class="bottom">
<input-box v-model="question" @submit="onSubmitQuestion" />
<input-box
:question="question"
:references="references"
@update:question="question = $event"
@update:references="references = $event"
@submit="onSubmitQuestion"
/>
</div>
</div>
</template>
Expand Down Expand Up @@ -43,7 +49,8 @@ import { Status } from '@/store/common/models';
import { log } from '@/utils/log';
export interface IData {
question: '';
question: string;
references: string[];
messages: IChatMessage[];
}
Expand All @@ -58,6 +65,7 @@ export default defineComponent({
data(): IData {
return {
question: '',
references: [],
messages:
this.$store.state.chat.conversations?.find(
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
Expand Down Expand Up @@ -153,6 +161,7 @@ export default defineComponent({
.askQuestion(
{
question,
references: this.references,
conversation_id: this.conversationId,
stateful: true
},
Expand Down

0 comments on commit bea3698

Please sign in to comment.