Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
arshad-yaseen committed Feb 15, 2025
1 parent 73e1028 commit 3ca3fb2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
15 changes: 6 additions & 9 deletions docs/configuration/register-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@ The `trigger` option determines when the completion service provides code comple

```javascript
registerCompletion(monaco, editor, {
trigger: 'onTyping',
trigger: 'onTyping', // Only recommended for low-latency and low-cost models
});
```

| Trigger | Description | Notes |
| -------------------- | --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `'onIdle'` (default) | Provides completions after a brief pause in typing. | This approach is less resource-intensive, as it only initiates a request when the editor is idle. |
| `'onTyping'` | Provides completions in real-time as you type. | Best suited for models with low response latency, such as Groq models or Claude 3-5 Haiku. This trigger mode initiates additional background requests to deliver real-time suggestions, a method known as predictive caching. |
| `'onDemand'` | Does not provide completions automatically. | Completions are triggered manually using the `trigger` function from the `registerCompletion` return. This allows for precise control over when completions are provided. |
| Trigger | Description | Notes |
| -------------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `'onIdle'` (default) | Provides completions after a brief pause in typing. | This approach is less resource-intensive, as it only initiates a request when the editor is idle. |
| `'onTyping'` | Provides completions in real-time as you type. | Best suited for models with low response latency, such as Groq models. This trigger mode initiates additional background requests to deliver real-time suggestions, a method known as predictive caching. |
| `'onDemand'` | Does not provide completions automatically. | Completions are triggered manually using the `trigger` function from the `registerCompletion` return. This allows for precise control over when completions are provided. |

[OnTyping Demo](https://github.com/user-attachments/assets/22c2ce44-334c-4963-b853-01b890b8e39f)

> [!NOTE]
> If you prefer real-time completions, you can set the `trigger` option to `'onTyping'`. This may increase the number of requests made to the provider and the cost. This should not be too costly since most small models are very inexpensive.
## Manually Trigger Completions

If you prefer not to trigger completions automatically (e.g., on typing or on idle), you can trigger completions manually. This is useful in scenarios where you want to control when completions are provided, such as through a button click or a keyboard shortcut.
Expand Down
16 changes: 11 additions & 5 deletions packages/monacopilot/src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ const compileRelatedFiles = (files?: RelatedFile[]): string => {
return files
.map(({path, content}) => {
return `
### ${path}
### Path: ${path}
\`\`\`
${content}
\`\`\``.trim();
})
.join('\n\n');
};

export const craftCompletionPrompt = (meta: CompletionMetadata): PromptData => {
export const craftCompletionPrompt = (
metadata: CompletionMetadata,
): PromptData => {
const {
technologies = [],
filename,
Expand All @@ -28,7 +30,7 @@ export const craftCompletionPrompt = (meta: CompletionMetadata): PromptData => {
textBeforeCursor = '',
textAfterCursor = '',
editorState: {completionMode},
} = meta;
} = metadata;

const mergedTechStack = joinWithAnd(
[language, ...technologies].filter(
Expand All @@ -37,7 +39,7 @@ export const craftCompletionPrompt = (meta: CompletionMetadata): PromptData => {
);

const systemInstruction = `
You are an expert code completion assistant.
You are an EXCELLENT code completion assistant.
**Context:**
File: ${filename || 'Untitled'}
Expand All @@ -56,7 +58,11 @@ ${textBeforeCursor}<cursor>${textAfterCursor}
${capitalizeFirstLetter(completionMode)} the code at <cursor>.
Output only the raw code to be inserted at the cursor location without any additional text, comments, or code block syntax.`;
**Completion Constraints**
1. MUST start with: "${textBeforeCursor.slice(-1)}"
2. MUST end before: "${textAfterCursor.slice(0, 1)}"
Output ONLY the raw code to be inserted at the cursor location without any additional text, comments, or code block syntax.`;

return {
system: systemInstruction,
Expand Down
6 changes: 3 additions & 3 deletions playground/app/api/code-completion/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {NextRequest, NextResponse} from 'next/server';

import {CompletionCopilot} from 'monacopilot';

const copilot = new CompletionCopilot(process.env.GROQ_API_KEY, {
provider: 'groq',
model: 'llama-3-70b',
const copilot = new CompletionCopilot(process.env.OPENAI_API_KEY, {
provider: 'openai',
model: 'gpt-4o-mini',
});

export async function POST(req: NextRequest) {
Expand Down

0 comments on commit 3ca3fb2

Please sign in to comment.