-
-
Notifications
You must be signed in to change notification settings - Fork 742
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
79 changed files
with
688 additions
and
397 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
60 changes: 60 additions & 0 deletions
60
templates/plate-playground-template/src/components/editor/plugins/copilot-plugins.tsx
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,60 @@ | ||
'use client'; | ||
|
||
import type { TElement } from '@udecode/plate-common'; | ||
|
||
import { faker } from '@faker-js/faker'; | ||
import { CopilotPlugin } from '@udecode/plate-ai/react'; | ||
import { getAncestorNode } from '@udecode/plate-common'; | ||
import { serializeMdNodes, stripMarkdown } from '@udecode/plate-markdown'; | ||
|
||
import { GhostText } from '@/components/plate-ui/ghost-text'; | ||
|
||
export const copilotPlugins = [ | ||
CopilotPlugin.configure(({ api }) => ({ | ||
options: { | ||
completeOptions: { | ||
api: '/api/ai/copilot', | ||
body: { | ||
system: `You are an advanced AI writing assistant, similar to VSCode Copilot but for general text. Your task is to predict and generate the next part of the text based on the given context. | ||
Rules: | ||
- Continue the text naturally up to the next punctuation mark (., ,, ;, :, ?, or !). | ||
- Maintain style and tone. Don't repeat given text. | ||
- For unclear context, provide the most likely continuation. | ||
- Handle code snippets, lists, or structured text if needed. | ||
- Don't include """ in your response. | ||
- CRITICAL: Always end with a punctuation mark. | ||
- CRITICAL: Avoid starting a new block. Do not use block formatting like >, #, 1., 2., -, etc. The suggestion should continue in the same block as the context. | ||
- If no context is provided or you can't generate a continuation, return "0" without explanation.`, | ||
}, | ||
onError: () => { | ||
// Mock the API response. Remove it when you implement the route /api/ai/copilot | ||
api.copilot.setBlockSuggestion({ | ||
text: stripMarkdown(faker.lorem.sentence()), | ||
}); | ||
}, | ||
onFinish: (_, completion) => { | ||
if (completion === '0') return; | ||
|
||
api.copilot.setBlockSuggestion({ | ||
text: stripMarkdown(completion), | ||
}); | ||
}, | ||
}, | ||
debounceDelay: 500, | ||
getPrompt: ({ editor }) => { | ||
const contextEntry = getAncestorNode(editor); | ||
|
||
if (!contextEntry) return ''; | ||
|
||
const prompt = serializeMdNodes([contextEntry[0] as TElement]); | ||
|
||
return `Continue the text up to the next punctuation mark: | ||
""" | ||
${prompt} | ||
"""`; | ||
}, | ||
renderGhostText: GhostText, | ||
}, | ||
})), | ||
] as const; |
11 changes: 11 additions & 0 deletions
11
templates/plate-playground-template/src/components/editor/plugins/cursor-overlay-plugin.tsx
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,11 @@ | ||
'use client'; | ||
|
||
import { CursorOverlayPlugin } from '@udecode/plate-selection/react'; | ||
|
||
import { CursorOverlay } from '@/components/plate-ui/cursor-overlay'; | ||
|
||
export const cursorOverlayPlugin = CursorOverlayPlugin.configure({ | ||
render: { | ||
afterEditable: () => <CursorOverlay />, | ||
}, | ||
}); |
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
Oops, something went wrong.