Skip to content

Commit

Permalink
Merge pull request #63 from OVINC-CN/feat_search_history
Browse files Browse the repository at this point in the history
feat(chat): search history
  • Loading branch information
OrenZhang authored Feb 13, 2025
2 parents bccf2ce + 7595886 commit 977ea64
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/locale/en-us.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const mEnUS = {
SyncMessageFailed: 'Sync Message Failed',
DecryptMessageLogFailed: 'Failed to decrypt historical conversations. Please check your encrypt key.',
ReasoningContent: 'Reasoning Content',
PleaseInputHistoryKeyword: 'Search Keyword',
};

export default mEnUS;
1 change: 1 addition & 0 deletions src/locale/zh-cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const mZhCN = {
SyncMessageFailed: '同步历史会话失败,请关注',
DecryptMessageLogFailed: '解密历史会话失败,请检查加密密钥',
ReasoningContent: '思考过程',
PleaseInputHistoryKeyword: '请输入关键字以搜索历史记录',
};

export default mZhCN;
37 changes: 29 additions & 8 deletions src/views/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {useI18n} from 'vue-i18n';
const i18n = useI18n();
// message
const historySearchKey = ref('');
const oldLocalMessageKey = 'local-message';
const localMessages = ref([]);
const currentMessageID = ref('');
Expand All @@ -23,15 +24,22 @@ const messageIDPrefix = 'local-message-';
const localMessageStore = ref({});
const localMessageStoreKey = 'local-message-store';
const sortedMessageStore = computed(() => {
return Object.entries(localMessageStore.value)
const filteredEntries = Object.entries(localMessageStore.value)
.sort(([, a], [, b]) => b.created_at - a.created_at)
.reduce(
(acc, [key, value]) => {
acc[key] = value;
return acc;
},
{},
);
.filter(([, value]) => {
const content = localStorage.getItem(`${messageIDPrefix}${value.created_at}`);
if (!content) {
return false;
}
return content.includes(historySearchKey.value);
});
return filteredEntries.reduce(
(acc, [key, value]) => {
acc[key] = value;
return acc;
},
{},
);
});
const addMessage = (message) => {
localMessages.value.push(message);
Expand Down Expand Up @@ -363,6 +371,11 @@ const setPromptForm = (data) => promptForm.value = data;
</template>
</a-button>
</a-space>
<a-input
class="history-search-input"
v-model="historySearchKey"
:placeholder="$t('PleaseInputHistoryKeyword')"
/>
<a-list
v-if="Object.keys(sortedMessageStore).length > 0"
:max-height="320"
Expand Down Expand Up @@ -493,4 +506,12 @@ const setPromptForm = (data) => promptForm.value = data;
.sync-history-config-button-box > :deep(.arco-space-item) > button{
width: 100%;
}
.history-search-input {
border-radius: var(--border-radius-large);
}
.history-search-input :deep(.arco-input) {
text-align: center;
}
</style>

0 comments on commit 977ea64

Please sign in to comment.