Skip to content

Commit

Permalink
Merge pull request #61 from OVINC-CN/feat_thinking
Browse files Browse the repository at this point in the history
feat(chat): support to show reasoning content
  • Loading branch information
OrenZhang authored Feb 5, 2025
2 parents 4362795 + b3ce52f commit 093acbe
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/ChatInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const doChat = async () => {
// auto scroll
emits('toggleUserBehavior', false);
// init response content
lastResponseContent.value = {role: Role.Assistant, content: ''};
lastResponseContent.value = {role: Role.Assistant, content: '', thinking: ''};
emits('addMessage', lastResponseContent.value);
// clear input
promptForm.value.content = '';
Expand All @@ -192,6 +192,10 @@ const onMessage = (event) => {
lastResponseContent.value.content += data.data;
emits('saveMessage');
}
if (data.thinking) {
lastResponseContent.value.thinking += data.thinking;
emits('saveMessage');
}
};
const sendMessage = (message) => {
initWebSocket().then(
Expand Down
11 changes: 11 additions & 0 deletions src/components/MessageContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ const onImageClick = (images, index) => emits('onImageClick', images[index]);
</a-space>
</a-link>
</div>
<v-md-preview
v-show="message.thinking"
:text="':::tip ' + $t('ReasoningContent') + '\n' + message.thinking + '\n:::'"
class="v-md-preview"
:class="{'v-md-preview-u': message.role === Role.User || message.role === Role.System}"
@image-click="onImageClick"
/>
<v-md-preview
v-show="message.content"
:text="message.content"
Expand Down Expand Up @@ -228,4 +235,8 @@ body[arco-theme="dark"] .v-md-preview :deep(.github-markdown-body) pre code,
body[arco-theme="dark"] .v-md-preview :deep(.github-markdown-body) pre code span {
color: var(--color-text-1)!important;
}
body[arco-theme="dark"] .v-md-preview :deep(.v-md-plugin-tip.tip) {
background-color: var(--color-bg-5);
}
</style>
1 change: 1 addition & 0 deletions src/locale/en-us.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const mEnUS = {
PleaseInputSyncEncrypt: 'Please input encrypt key',
SyncMessageFailed: 'Sync Message Failed',
DecryptMessageLogFailed: 'Failed to decrypt historical conversations. Please check your encrypt key.',
ReasoningContent: 'Reasoning Content',
};

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 @@ -97,6 +97,7 @@ const mZhCN = {
PleaseInputSyncEncrypt: '请输入加密密钥',
SyncMessageFailed: '同步历史会话失败,请关注',
DecryptMessageLogFailed: '解密历史会话失败,请检查加密密钥',
ReasoningContent: '思考过程',
};

export default mZhCN;
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import createEmojiPlugin from '@kangc/v-md-editor/lib/plugins/emoji/index';
import '@kangc/v-md-editor/lib/plugins/emoji/emoji.css';
import createCopyCodePlugin from '@kangc/v-md-editor/lib/plugins/copy-code/index';
import '@kangc/v-md-editor/lib/plugins/copy-code/copy-code.css';
import tipsPlugin from '@kangc/v-md-editor/lib/plugins/tip/index';
import '@kangc/v-md-editor/lib/plugins/tip/tip.css';

import hljs from 'highlight.js';

Expand All @@ -29,6 +31,7 @@ VMdPreview.use(createKatexPlugin());
VMdPreview.use(createTipPlugin());
VMdPreview.use(createEmojiPlugin());
VMdPreview.use(createCopyCodePlugin());
VMdPreview.use(tipsPlugin());

const app = createApp(App);

Expand Down

0 comments on commit 093acbe

Please sign in to comment.