Compare commits

..

No commits in common. "769e05336c661ff299d1af421a94d86cd4301652" and "12f411fbac5d1d8fa3bca09e07508c9f06bf4425" have entirely different histories.

5 changed files with 101 additions and 47 deletions

View File

@ -1 +0,0 @@
vsce package --baseContentUrl https://gitea.fabelous.app/fabel/Fabelous-Autocoder/src/branch/main --baseImagesUrl https://gitea.fabelous.app/fabel/Fabelous-Autocoder/src/branch/main

View File

@ -1,58 +1,76 @@
# Fabelous Autocoder # Fabelous Autocoder
Fabelous Autocoder is a powerful VS Code extension that provides intelligent code completion using advanced language models. It offers seamless integration with your development workflow, allowing you to generate and preview code suggestions with ease. Fabelous Autocoder is a Visual Studio Code extension that provides an easy-to-use interface for Ollama autocompletion. This extension allows developers to use Ollama's powerful language models to generate code completions as they type. It is highly customizable, allowing users to configure various settings to fit their needs.
![Fabelous Autocoder in Action](demo.gif)
## Features ## Features
- **Intelligent Code Completion**: Leverages advanced language models to provide context-aware code suggestions. - Autocompletion using Ollama language models
- **Preview Functionality**: View generated code completions before accepting them. - Customizable completion keys
- **Easy Accept/Decline**: Use simple keyboard shortcuts to accept or decline suggestions. - Inline preview of generated completions
- **Customizable**: Configure various parameters like API endpoint, model, and response behavior. - Configurable maximum tokens predicted
- **Language Agnostic**: Works with multiple programming languages. - Configurable prompt window size
- Configurable response preview delay
- Configurable temperature for the model
## How It Works ## Installation
You can also download the extension from the release tab of the following Git repository:
1. Trigger the autocompletion by typing a completion key (configurable, default is space). [Fabelous-Autocoder Git Repository](https://gitea.fabelous.app/fabel/Fabelous-Autocoder.git)
2. The extension sends your current code context to the configured API.
3. A code completion is generated and displayed as a preview.
4. Accept the completion with `Tab` or decline it with `Backspace`.
## Usage To do so, follow these steps:
![Fabelous Autocoder Showcase](demo.gif) 1. Visit the repository link.
2. Click on the "Releases" tab.
3. Look for the latest release and click on it.
4. Download the extension file compatible with your operating system.
5. Install the extension manually in Visual Studio Code.
1. **Trigger Completion**: Type normally and hit the completion key (space by default). After installation, you'll be able to use the Fabelous Autocoder extension in your Visual Studio Code environment.
2. **Preview**: The suggested completion appears in light gray text.
3. **Accept**: Press `Tab` to accept the entire suggestion.
4. **Decline**: Press `Backspace` to remove the preview and decline the suggestion.
5. **Partial Accept**: You can continue typing to partially accept the suggestion.
## Configuration ## Configuration
Customize Fabelous Autocoder through VS Code settings: Fabelous Autocoder is highly customizable, allowing users to configure various settings to fit their needs. To access the configuration settings, follow these steps:
- `fabelous-autocoder.endpoint`: API endpoint for the language model. 1. Open Visual Studio Code
- `fabelous-autocoder.model`: Specify the model to use. 2. Click on the Settings icon on the sidebar (or press `Ctrl+,`)
- `fabelous-autocoder.temperature`: Control the randomness of completions. 3. Search for "Fabelous Autocoder" in the search bar
- `fabelous-autocoder.max tokens predicted`: Set the maximum length of completions. 4. Configure the desired settings
- `fabelous-autocoder.prompt window size`: Adjust the context window size.
- `fabelous-autocoder.completion keys`: Set custom completion trigger keys.
- `fabelous-autocoder.response preview`: Toggle preview functionality.
- `fabelous-autocoder.preview max tokens`: Limit preview length.
- `fabelous-autocoder.preview delay`: Add delay before showing preview.
- `fabelous-autocoder.continue inline`: Control inline continuation behavior.
## Installation Here are some of the available configuration options:
- `fabelous-autocoder.endpoint`: The endpoint of the Ollama REST API
- `fabelous-autocoder.authentication`: The authentication token for Ollama
- `fabelous-autocoder.model`: The model to use for generating completions
- `fabelous-autocoder.max tokens predicted`: The maximum number of tokens generated by the model
- `fabelous-autocoder.prompt window size`: The size of the prompt in characters
- `fabelous-autocoder.completion keys`: The characters that trigger the autocompletion item provider
- `fabelous-autocoder.response preview`: Whether to show a preview of the generated completion inline
- `fabelous-autocoder.preview max tokens`: The maximum number of tokens generated for the response preview
- `fabelous-autocoder.preview delay`: The time to wait before starting inline preview generation
- `fabelous-autocoder.continue inline`: Whether to continue autocompletion after the inline preview
- `fabelous-autocoder.temperature`: The temperature of the model
- `fabelous-autocoder.keep alive`: The time in minutes before Ollama unloads the model
1. [Click here to download the latest version](https://gitea.fabelous.app/Fabel/Fabelous-Autocoder/releases/download/latest/fabelous-autocoder-0.2.0.vsix) Note that changing the `completion keys` setting requires a reload of Visual Studio Code.
2. Open Visual Studio Code
3. Go to Extensions (Ctrl+Shift+X)
4. Click on the three dots in the upper-right corner and select "Install from VSIX..."
5. Navigate to the location where you extracted Fabelous Autocoder and select the .vsix file
6. Click "Install" to install the extension
## Requirements ## Usage
- VS Code version 1.89.0 or higher To use Fabelous Autocoder, simply start typing in the editor. When the configured completion keys are pressed, the extension will generate a completion using the configured Ollama model. The completion will be displayed inline with a preview of the generated code. If the `continue inline` setting is enabled, the extension will continue generating completions after the inline preview.
- Internet connection for API calls
To generate a multi-line completion, press `Enter` after the inline preview. This will open a new editor with the generated completion.
To customize the behavior of the extension, see the Configuration section above.
## License
Fabelous Autocoder is licensed under the CC BY-ND 4.0 license. See the [LICENSE](https://gitea.fabelous.app/fabel/Fabelous-Autocoder/src/branch/main/LICENSE) file for more information.
## Acknowledgments
Fabelous Autocoder was created by [Falko Habel](https://gitea.fabelous.app/fabel). It was inspired by the [Ollama](https://ollama.ai) project.

BIN
demo.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 213 KiB

View File

@ -1,6 +1,6 @@
{ {
"name": "fabelous-autocoder", "name": "fabelous-autocoder",
"version": "0.2.1", "version": "0.2.0",
"displayName": "Fabelous Autocoder", "displayName": "Fabelous Autocoder",
"description": "A simple to use Ollama autocompletion Plugin", "description": "A simple to use Ollama autocompletion Plugin",
"icon": "icon.png", "icon": "icon.png",
@ -66,6 +66,11 @@
"default": 2000, "default": 2000,
"description": "The size of the prompt in characters. NOT tokens, so can be set about 1.5-2x the max tokens of the model (varies)." "description": "The size of the prompt in characters. NOT tokens, so can be set about 1.5-2x the max tokens of the model (varies)."
}, },
"fabelous-autocoder.completion keys": {
"type": "string",
"default": " ",
"description": "Character that the autocompletion item provider appear on. Multiple characters will be treated as different entries. REQUIRES RELOAD"
},
"fabelous-autocoder.response preview": { "fabelous-autocoder.response preview": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
@ -118,11 +123,6 @@
"command": "fabelous-autocoder.handleBackspace", "command": "fabelous-autocoder.handleBackspace",
"key": "backspace", "key": "backspace",
"when": "editorTextFocus" "when": "editorTextFocus"
},
{
"key": "alt+oem_plus",
"command": "fabelous-autocoder.autocomplete",
"when": "editorTextFocus"
} }
], ],
"commands": [ "commands": [

View File

@ -275,17 +275,54 @@ async function handleBackspace() {
} }
} }
async function provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, cancellationToken: vscode.CancellationToken) {
const item = new vscode.CompletionItem('Fabelous autocompletion');
item.insertText = new vscode.SnippetString('${1:}');
item.documentation = new vscode.MarkdownString('Press `Enter` to get an autocompletion from Fabelous Autocoder');
if (config.responsePreview) {
await new Promise(resolve => setTimeout(resolve, config.responsePreviewDelay * 1000));
if (cancellationToken.isCancellationRequested) {
return [item];
}
const context = getContextLines(document, position);
const fimPrompt = createFIMPrompt(context, document.languageId);
try {
const result = await generateCompletion(fimPrompt, cancellationToken);
const preview = (result as any).preview;
if (preview) {
item.detail = preview.split('\n')[0];
}
} catch (error) {
console.error('Error fetching preview:', error);
}
}
if (config.continueInline || !config.responsePreview) {
item.command = {
command: 'fabelous-autocoder.autocomplete',
title: 'Fabelous Autocomplete',
arguments: []
};
}
return [item];
}
export function activate(context: vscode.ExtensionContext) { export function activate(context: vscode.ExtensionContext) {
updateConfig(); updateConfig();
createPreviewDecorationType(); createPreviewDecorationType();
context.subscriptions.push( context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(updateConfig), vscode.workspace.onDidChangeConfiguration(updateConfig),
vscode.languages.registerCompletionItemProvider('*', { provideCompletionItems }, ...config.completionKeys),
vscode.commands.registerTextEditorCommand('fabelous-autocoder.autocomplete', autocompleteCommand), vscode.commands.registerTextEditorCommand('fabelous-autocoder.autocomplete', autocompleteCommand),
vscode.commands.registerCommand('fabelous-autocoder.handleTab', handleTab), vscode.commands.registerCommand('fabelous-autocoder.handleTab', handleTab),
vscode.commands.registerCommand('fabelous-autocoder.handleBackspace', handleBackspace) vscode.commands.registerCommand('fabelous-autocoder.handleBackspace', handleBackspace) // Add this line
); );
} }
export function deactivate() {} export function deactivate() {}