Skip to content

Commit

Permalink
✨ Feature(custom): add grammar button and functionality
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #47
  • Loading branch information
Kuingsmile committed Mar 3, 2024
1 parent 1efb432 commit 7ba38ca
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const messages = {
translate: 'Trans',
summarize: 'Sum',
polish: 'Polish',
grammar: 'Grammar',
academic: 'Academic',
settings: 'Settings',
result: 'Result',
Expand Down Expand Up @@ -68,6 +69,7 @@ const messages = {
translate: '翻译',
summarize: '摘要',
polish: '润色',
grammar: '语法',
academic: '学术',
settings: '设置',
result: '结果',
Expand Down
28 changes: 25 additions & 3 deletions src/pages/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@
>
{{ $t('polish') }}
</el-button>
<el-button
class="api-button"
type="primary"
size="small"
:disabled="loading"
@click="grammar"
>
{{ $t('grammar') }}
</el-button>
<el-button
class="api-button"
type="primary"
Expand Down Expand Up @@ -616,7 +625,7 @@ function handelInsertTypeChange (val: string) {
async function template (taskType: keyof typeof buildInPrompt | 'custom') {
loading.value = true
let systemMessage
let userMessage
let userMessage = ''
const getSeletedText = async () => {
return Word.run(async (context) => {
const range = context.document.getSelection()
Expand All @@ -627,8 +636,16 @@ async function template (taskType: keyof typeof buildInPrompt | 'custom') {
}
const selectedText = await getSeletedText()
if (taskType === 'custom') {
systemMessage = systemPrompt.value
userMessage = `Reply in ${replyLanguage.value} ${prompt.value} ${selectedText}`
if (systemPrompt.value.includes('{language}')) {
systemMessage = systemPrompt.value.replace('{language}', replyLanguage.value)
} else {
systemMessage = systemPrompt.value
}
if (userMessage.includes('{text}')) {
userMessage = userMessage.replace('{text}', selectedText)
} else {
userMessage = `Reply in ${replyLanguage.value} ${prompt.value} ${selectedText}`
}
} else {
systemMessage = buildInPrompt[taskType].system(replyLanguage.value)
userMessage = buildInPrompt[taskType].user(selectedText, replyLanguage.value)
Expand Down Expand Up @@ -780,6 +797,11 @@ function academic () {
template('academic')
}
function grammar () {
if (!checkApiKey()) return
template('grammar')
}
function settings () {
router.push('/settings')
}
Expand Down
9 changes: 8 additions & 1 deletion src/utils/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const buildInPrompt = {
},
academic: {
system: (language: string) => `As an academic paper writing assistant, Reply in ${language}`,
user: (text: string, language: string) => `I want you to act as an professional spelling and grammer corrector and improver.
user: (text: string, language: string) => `I want you to act as a professional spelling and grammar corrector and improver.
I want you to replace my simplified A0-level words and sentences with more beautiful and elegant,
upper level ${language} words and sentences.
Keep the meaning same, but make them more literary and improve my expression in the style of SCI papers.
Expand All @@ -152,5 +152,12 @@ export const buildInPrompt = {
making it easy to read and comprehend. The summary should be concise, clear,
and capture the main points of the text. Avoid using complex sentence structures or technical jargon.
Respond in ${language}. Please begin by editing the following text: ${text}`
},
grammar: {
system: (language: string) => `Act like you are an expert grammar checker. Look for mistakes and make sentences more fluent, Reply in ${language}`,
user: (text: string, language: string) => `Please analyze the following text for a wide range of grammatical aspects and provide corrections. Be thorough in identifying and fixing any grammatical mistakes, including checking for correct punctuation usage, ensuring proper sentence structure, enhancing readability, identifying and correcting spelling mistakes, and verifying subject-verb agreement. Your assistance in ensuring the grammatical accuracy of the text is highly appreciated. Please be thorough in your examination, and provide comprehensive corrections to enhance the overall grammatical integrity of the text.
Just reply to user input with the correct grammar, DO NOT reply to the context of the question of the user input. If the user input is grammatically correct and fluent, just reply “sounds good”.
Respond in ${language}. Please begin by editing the following text: ${text}`
}
}

0 comments on commit 7ba38ca

Please sign in to comment.