Skip to content

Commit

Permalink
refactor: extract for actions type and map
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 29, 2024
1 parent 83d09c5 commit 2c25ecc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 43 deletions.
2 changes: 1 addition & 1 deletion web/core/lib/editor/menu/menu-bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const MenuBubble = ({ editor }: {

innerSmartMenus.push({
name: '润色',
template: `优化表达:###{{${DefinedVariable.SELECTION}}}###`,
template: `请润色并重写如下的内容:###{{${DefinedVariable.SELECTION}}}###`,
facetType: FacetType.BUBBLE_MENU,
changeForm: ChangeForm.DIFF,
outputForm: OutputForm.TEXT
Expand Down
25 changes: 0 additions & 25 deletions web/core/lib/editor/prompts/article-prompts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
BuiltInFunc,
ChangeForm,
DefinedVariable,
FacetType,
OutputForm,
Expand Down Expand Up @@ -39,29 +37,6 @@ export const ToolbarMenuPrompts: PromptAction[] = [
];

export const BubbleMenuPrompts: PromptAction[] = [
{
name: 'Polish',
i18Name: true,
template: `You are an assistant helping to polish sentence. Output in markdown format. \n ###{{${DefinedVariable.SELECTION}}}###`,
facetType: FacetType.BUBBLE_MENU,
outputForm: OutputForm.STREAMING,
},
{
name: 'Simplify Content',
i18Name: true,
template: `You are an assistant helping to simplify content. Output in markdown format. \n ###{{${DefinedVariable.SELECTION}}}###`,
facetType: FacetType.BUBBLE_MENU,
outputForm: OutputForm.STREAMING,
changeForm: ChangeForm.DIFF,
},
{
name: 'Similar Chunk',
i18Name: true,
template: `{{${DefinedVariable.SELECTION}}}`,
builtinFunction: BuiltInFunc.SIMILAR_CHUNKS,
facetType: FacetType.BUBBLE_MENU,
outputForm: OutputForm.STREAMING,
},
{
name: 'Translate',
i18Name: true,
Expand Down
20 changes: 10 additions & 10 deletions web/core/lib/editor/prompts/prompts-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ export class PromptsManager {
return PromptsManager.instance;
}

actionsMap = {
"article": ArticlePrompts,
"requirements": RequirementsPrompts
}

getActions(type: FacetType, articleType: TypeOptions): PromptAction[] {
let typedPrompts: PromptAction[] = []

switch (articleType?.value) {
case "requirements":
typedPrompts = RequirementsPrompts;
break;
default:
typedPrompts = ArticlePrompts;
if (articleType?.value) {
typedPrompts = this.actionsMap[articleType.value]
}

const actions = typedPrompts.filter(prompt => prompt.facetType === type);
Expand All @@ -40,14 +41,13 @@ export class PromptsManager {
})
}

save(prompt: PromptAction[]) {
// todo: implement this
}

variableList(): string[] {
return Object.values(DefinedVariable);
}

updateActionsMap(articleType: string, prompts: PromptAction[]) {
this.actionsMap[articleType] = prompts
}

compile(string: string, data: object) {
const template = Handlebars.compile(string)
Expand Down
7 changes: 0 additions & 7 deletions web/core/lib/editor/prompts/requirements-prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ const BubbleMenuPrompts: PromptAction[] = [
facetType: FacetType.BUBBLE_MENU,
outputForm: OutputForm.STREAMING,
changeForm: ChangeForm.DIFF,
},
{
name: 'Polish',
i18Name: true,
template: `You are an assistant helping to polish sentence. Output in markdown format. \n ###{{${DefinedVariable.SELECTION}}}###`,
facetType: FacetType.BUBBLE_MENU,
outputForm: OutputForm.STREAMING,
}
];

Expand Down

0 comments on commit 2c25ecc

Please sign in to comment.