-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
editor/src/components/editor/action/BuiltinFunctionExecutor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Editor } from "@tiptap/core"; | ||
import { BuiltInFunc, PromptAction } from "@/components/editor/defs/custom-action.type"; | ||
|
||
export class BuiltinFunctionExecutor { | ||
private editor: Editor; | ||
|
||
constructor(editor: Editor) { | ||
this.editor = editor; | ||
} | ||
|
||
execute(action: PromptAction): Promise<string> | undefined { | ||
switch (action.builtinFunction) { | ||
case BuiltInFunc.GRAMMAR_CHECK: | ||
break; | ||
case BuiltInFunc.SIMILAR_CHUNKS: | ||
return this.searchSimilarChunks(action); | ||
case BuiltInFunc.SPELLING_CHECK: | ||
break; | ||
case BuiltInFunc.WIKI_SUMMARY: | ||
break; | ||
case BuiltInFunc.RELATED_CHUNKS: | ||
break; | ||
} | ||
} | ||
|
||
private searchSimilarChunks(action: PromptAction) { | ||
return new Promise<string>((resolve, reject) => { | ||
const selection = this.editor.state.selection; | ||
const query = this.editor.state.doc.textBetween(selection.from, selection.to); | ||
|
||
const response = fetch(`http://127.0.0.1:8080/api/embedding-document/search?q=${query}`, { | ||
method: "GET", | ||
}); | ||
|
||
response.then((res) => { | ||
res.json().then((data) => { | ||
resolve(data); | ||
}); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters