Skip to content

Commit

Permalink
chore(monacopilot): set max-context-lines default to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
arshad-yaseen committed Feb 17, 2025
1 parent e4e84a5 commit 9d87ea0
Show file tree
Hide file tree
Showing 20 changed files with 202 additions and 407 deletions.
6 changes: 3 additions & 3 deletions docs/configuration/register-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ This configuration will provide completions relevant to React, Next.js, and Tail

## Max Context Lines

To manage potentially lengthy code in your editor, you can limit the number of lines included in the completion request using the `maxContextLines` option.
To manage potentially lengthy code in your editor, you can limit the number of lines included in the completion request using the `maxContextLines` option. By default, this is set to `100` lines.

For example, if there's a chance that the code in your editor may exceed `500+ lines`, you don't need to provide `500 lines` to the model. This would increase costs due to the huge number of input tokens. Instead, you can set `maxContextLines` to maybe `80` or `100`, depending on how accurate you want the completions to be and how much you're willing to pay for the model.
For example, if there's a chance that the code in your editor may exceed `500` lines, you don't need to provide all those lines to the model. This would increase costs due to the huge number of input tokens. You can adjust `maxContextLines` based on how accurate you want the completions to be and how much you're willing to pay for the model.

```javascript
registerCompletion(monaco, editor, {
maxContextLines: 80,
maxContextLines: 60,
});
```

Expand Down
16 changes: 14 additions & 2 deletions packages/core/src/copilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type {
Model,
Provider,
} from './types/llm';
import {HTTP} from './utils/http';
import validate from './validator';

export abstract class Copilot<Meta> {
Expand Down Expand Up @@ -131,7 +130,20 @@ export abstract class Copilot<Meta> {
requestBody: ChatCompletionCreateParams,
headers: Record<string, string>,
) {
return HTTP.post(endpoint, requestBody, {headers});
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...headers,
},
body: JSON.stringify(requestBody),
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

return response.json();
}

protected handleError(error: unknown): CopilotResponse {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export {Copilot} from './copilot';
export {HTTP} from './utils/http';

export * from './logger';
export * from './constants';
Expand Down
84 changes: 0 additions & 84 deletions packages/core/src/utils/http.ts

This file was deleted.

136 changes: 0 additions & 136 deletions packages/core/tests/http.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/monacopilot/src/completion-copilot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Copilot, type PromptData} from '@monacopilot/core';

import {craftCompletionPrompt} from './prompt';
import {buildDefaultPrompt} from './prompt';
import type {
CompletionMetadata,
CompletionRequest,
Expand All @@ -27,6 +27,6 @@ export class CompletionCopilot extends Copilot<CompletionMetadata> {
}

protected getDefaultPrompt(metadata: CompletionMetadata): PromptData {
return craftCompletionPrompt(metadata);
return buildDefaultPrompt(metadata);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {logger} from '@monacopilot/core';

import {processInlineCompletions} from './processor';
import {getEditorState} from './state';
import {RegisterCompletionOptions, TriggerType} from './types';
Expand Down Expand Up @@ -49,15 +47,3 @@ export const createInlineCompletionsProvider = (
},
);
};

export const handleTriggerCompletion = (editor: StandaloneCodeEditor) => {
const state = getEditorState(editor);
if (!state) {
logger.warn(
'Completion is not registered. Use `registerCompletion` to register completion first.',
);
return;
}
state.isExplicitlyTriggered = true;
editor.trigger('keyboard', 'editor.action.inlineSuggest.trigger', {});
};
5 changes: 5 additions & 0 deletions packages/monacopilot/src/defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {TriggerType} from './types';

export const DEFAULT_MAX_CONTEXT_LINES = 100;
export const DEFAULT_ENABLE_CACHING = true;
export const DEFAULT_TRIGGER = TriggerType.OnIdle;
Loading

0 comments on commit 9d87ea0

Please # to comment.