Skip to content

Commit

Permalink
patch to #564
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Dec 3, 2023
1 parent e5ebd45 commit 2fc0b57
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/content-script/selection-tools/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,78 +17,76 @@ const createGenPrompt =
isTranslation = false,
targetLanguage = '',
enableBidirectional = false,
includeLanguagePrefix = false
includeLanguagePrefix = false,
}) =>
async (selection) => {
const preferredLanguage = isTranslation
? targetLanguage
: await getPreferredLanguage()
let fullMessage = isTranslation
? `Translate the following into ${preferredLanguage} and only show me the translated content`
: message
if (enableBidirectional) {
fullMessage += `. If it is already in ${preferredLanguage}, translate it into English and only show me the translated content`
}
const prefix = includeLanguagePrefix
? `Reply in ${preferredLanguage}.`
: ''
return `${prefix}${fullMessage}:\n'''\n${selection}\n'''`
async (selection) => {
const preferredLanguage = isTranslation ? targetLanguage : await getPreferredLanguage()
let fullMessage = isTranslation
? `Translate the following into ${preferredLanguage} and only show me the translated content`
: message
if (enableBidirectional) {
fullMessage += `. If it is already in ${preferredLanguage}, translate it into English and only show me the translated content`
}
const prefix = includeLanguagePrefix ? `Reply in ${preferredLanguage}.` : ''
return `${prefix}${fullMessage}:\n'''\n${selection}\n'''`
}

export const config = {
explain: {
icon: <ChatText />,
label: 'Explain',
genPrompt: createGenPrompt({
message: 'Explain the following',
includeLanguagePrefix: true
includeLanguagePrefix: true,
}),
},
translate: {
icon: <Translate />,
label: 'Translate',
genPrompt: createGenPrompt({
isTranslation: true
isTranslation: true,
targetLanguage: await getPreferredLanguage(),
}),
},
translateToEn: {
icon: <Globe />,
label: 'Translate (To English)',
genPrompt: createGenPrompt({
isTranslation: true,
targetLanguage: 'English'
targetLanguage: 'English',
}),
},
translateToZh: {
icon: <Globe />,
label: 'Translate (To Chinese)',
genPrompt: createGenPrompt({
isTranslation: true,
targetLanguage: 'Chinese'
targetLanguage: 'Chinese',
}),
},
translateBidi: {
icon: <Globe />,
label: 'Translate (Bidirectional)',
genPrompt: createGenPrompt({
isTranslation: true,
enableBidirectional: true
targetLanguage: await getPreferredLanguage(),
enableBidirectional: true,
}),
},
summary: {
icon: <CardHeading />,
label: 'Summary',
genPrompt: createGenPrompt({
message: 'Summarize the following as concisely as possible',
includeLanguagePrefix: true
includeLanguagePrefix: true,
}),
},
polish: {
icon: <Palette />,
label: 'Polish',
genPrompt: createGenPrompt({
message:
'Check the following content for possible diction and grammar problems, and polish it carefully'
'Check the following content for possible diction and grammar problems, and polish it carefully',
}),
},
sentiment: {
Expand All @@ -97,32 +95,30 @@ export const config = {
genPrompt: createGenPrompt({
message:
'Analyze the sentiments expressed in the following content and make a brief summary of the sentiments',
includeLanguagePrefix: true
includeLanguagePrefix: true,
}),
},
divide: {
icon: <CardList />,
label: 'Divide Paragraphs',
genPrompt: createGenPrompt({
message:
'Divide the following into paragraphs that are easy to read and understand'
message: 'Divide the following into paragraphs that are easy to read and understand',
}),
},
code: {
icon: <Braces />,
label: 'Code Explain',
genPrompt: createGenPrompt({
message: 'Explain the following code',
includeLanguagePrefix: true
includeLanguagePrefix: true,
}),
},
ask: {
icon: <QuestionCircle />,
label: 'Ask',
genPrompt: createGenPrompt({
message:
'Analyze the following content and express your opinion, or give your answer',
includeLanguagePrefix: true
message: 'Analyze the following content and express your opinion, or give your answer',
includeLanguagePrefix: true,
}),
},
}

0 comments on commit 2fc0b57

Please sign in to comment.