mirror of
https://github.com/open-webui/open-webui
synced 2025-02-07 05:27:55 +00:00
refac
This commit is contained in:
parent
95000c7b15
commit
fa5e1f7452
@ -153,10 +153,10 @@
|
||||
Placeholder.configure({ placeholder }),
|
||||
AIAutocompletion.configure({
|
||||
generateCompletion: async (text) => {
|
||||
// Implement your AI text generation logic here
|
||||
// This should return a Promise that resolves to the suggested text
|
||||
if (text.trim().length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log(text);
|
||||
return 'AI-generated suggestion';
|
||||
}
|
||||
})
|
||||
|
@ -50,8 +50,6 @@ export const AIAutocompletion = Extension.create({
|
||||
key: new PluginKey('aiAutocompletion'),
|
||||
props: {
|
||||
handleKeyDown: (view, event) => {
|
||||
if (event.key !== 'Tab') return false
|
||||
|
||||
const { state, dispatch } = view
|
||||
const { selection } = state
|
||||
const { $head } = selection
|
||||
@ -59,10 +57,11 @@ export const AIAutocompletion = Extension.create({
|
||||
if ($head.parent.type.name !== 'paragraph') return false
|
||||
|
||||
const node = $head.parent
|
||||
const prompt = node.textContent
|
||||
|
||||
if (event.key === 'Tab') {
|
||||
if (!node.attrs['data-suggestion']) {
|
||||
// Generate completion
|
||||
const prompt = node.textContent
|
||||
this.options.generateCompletion(prompt).then(suggestion => {
|
||||
if (suggestion && suggestion.trim() !== '') {
|
||||
dispatch(state.tr.setNodeMarkup($head.before(), null, {
|
||||
@ -72,6 +71,7 @@ export const AIAutocompletion = Extension.create({
|
||||
'data-suggestion': suggestion,
|
||||
}))
|
||||
}
|
||||
// If suggestion is empty or null, do nothing
|
||||
})
|
||||
} else {
|
||||
// Accept suggestion
|
||||
@ -86,8 +86,18 @@ export const AIAutocompletion = Extension.create({
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
return true
|
||||
} else if (node.attrs['data-suggestion']) {
|
||||
// Reset suggestion on any other key press
|
||||
dispatch(state.tr.setNodeMarkup($head.before(), null, {
|
||||
...node.attrs,
|
||||
class: null,
|
||||
'data-prompt': null,
|
||||
'data-suggestion': null,
|
||||
}))
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
Loading…
Reference in New Issue
Block a user