Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfeng33 committed Oct 3, 2024
1 parent 418852a commit e5f0f60
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/ai/src/react/copilot/generateCopilotText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,22 @@ export const generateCopilotText = async (

editor.setOptions(CopilotPlugin, { abortController });

const suggestion = await fetchSuggestion?.({
if (!fetchSuggestion) {
throw new Error('fetchSuggestion is not defined');
}

const suggestion = await fetchSuggestion({
abortSignal: abortController,
prompt,
});

return setCopilot(
node.id,
suggestion ?? 'Can not get suggestion did you config fetchSuggestion?'
);
if (!suggestion) {
console.warn('No suggestion was generated for the given prompt.');

return;
}

return setCopilot(node.id, suggestion);
};

export const generateCopilotTextDebounce = debounce(generateCopilotText, 500);

0 comments on commit e5f0f60

Please sign in to comment.