最後更新: 2024-09-05
目錄
- 介紹
- Connect to Ollama
- Hotkey
- Built-in Context Providers
- Codebase retrieval(embeddings)
- Force Re-Index
- Custom Commands
介紹
Homepage: https://Continue.dev
* Easily understand code sections # 選好一段 code 後 ctrl+l, 輸入 "explain the code"
* Tab to autocomplete code suggestions # tab 鍵
* Refactor functions where you are coding # 選好一段 code 後 ctrl+i, 輸入 "refactor it to X"
* Understand terminal errors immediately # 在 terminal 行 ./code.py 出 error 後 ctrl+shift+r
Continue makes it easy to use different models for chat, autocomplete, and embeddings.
VS Code UI Settings
Recommend moving Continue to VS Code's right sidebar.
在不夠 RAM 情況
# codellama for chat and starcoder2 for autocomplete
(3.8 GB, 1.7 GB, 274 MB)
ollama pull codellama:7b
ollama pull starcoder2:3b
GPU 夠 vram 的情況
chat 及 autocomplete 都用 deepseek-coder-v2:16b
Connect to Ollama
1) nginx 設定
2) In Continue 's config.json
%userprofile%\.continue
{
"models": [
{
"title": "codellama",
"provider": "ollama",
"model": "codellama:7b",
"apiBase": "https://YOUR-OPENWEBUI/ollama-api/",
//"apiKey": "sk-YOUR-API-KEY"
}
],
"tabAutocompleteModel": {
"title": "starcoder2",
"provider": "ollama",
"model": "starcoder2:3b",
"apiBase": "https://YOUR-OPENWEBUI/ollama-api/",
//"apiKey": "sk-YOUR-API-KEY"
},
"embeddingsProvider": {
"title": "nomic-embed-text",
"provider": "ollama",
"model": "nomic-embed-text",
"apiBase": "https://YOUR-OPENWEBUI/ollama-api/",
//"apiKey": "sk-YOUR-API-KEY"
},
}
3) 設定 Login
.continue 的 "apiKey": "xxx" 相當於 http header
Authorization: Bearer sk-YOUR-API-KEY
Notes
Bearer authentication also called token authentication
它是將原本的 username & password 改成一串字.
Nginx 設定
location /ollama-api/ { if ($http_authorization != "Bearer <secret token>") { return 401;} }
P.S.
使用 requestOptions 設定可以轉用 Basic Authorization
"requestOptions": { "headers": { "Authorization":"Basic somebase64encodedauth" }
Hotkey
tab # Autocomplete Code Suggestions
Select code block, Ctrl + L # Explain
- what does this code do?
Select code block ,Ctrl + I # Quick edit
# Use keyboard shortcuts to accept/reject the edit
- accept [Ctrl+Shift+Enter]
- reject [Cmd+Shift+Backspace]
Ctrl + Shift + R # Automatically debug terminal
Ctrl + Shift + L # Select code for follow-up
In Chat Box
/ # Commands & customCommands
@ # to add context (Context Providers)
Built-in Context Providers
'@file'
to reference any file in your current workspace.
'@code'
to reference specific functions or classes from throughout your project.
'@terminal'
to reference the contents of your IDE's terminal.
'@docs'
to index and retrieve snippets from any documentation site.
generating embeddings, and storing them locally for you
To add multiple documentation sites
"docs": [ { "title": "Continue", "startUrl": "https://docs.continue.dev/intro", "rootUrl": "https://docs.continue.dev", "faviconUrl": "https://docs.continue.dev/favicon.ico", "maxDepth": 3 } ]
Notes
- startUrl: The URL where the indexing process should begin.
- rootUrl: The base URL of the documentation site, used to determine which pages to index.
'@open'
to reference the contents of all of your open files.
Set onlyPinned to true to only reference pinned files.
'@codebase'
to automatically retrieve the most relevant snippets from your codebase.
Indexing generates embeddings used for codebase retrieval.
'@folder'
to use the same retrieval mechanism as '@codebase', but only on a single folder.
'@tree'
to reference the structure of your current workspace.
The LLM will be able to see the nested directory structure of your project.
Codebase retrieval(embeddings)
It indexes your codebase so that it can later automatically pull
in the most relevant context from throughout your workspace
The index is stored entirely locally.
功能:
- Asking high-level questions about your codebase
- Generate code using existing samples as reference
- Use @folder to ask questions about a specific folder
By default, all embeddings are calculated locally with all-MiniLM-L6-v2 and stored locally in ~/.continue/index
ollama pull nomic-embed-text
{ "embeddingsProvider": { "provider": "ollama", "model": "nomic-embed-text", "apiBase": "http://localhost:11434" } }
P.S. all-MiniLM-L6-v2
Transformers.js is a JavaScript port of the popular Transformers library.
It allows embeddings to be calculated locally in the browser (or in this case inside of the sidebar of your IDE).
Which is shipped alongside the Continue extension and generates embeddings of size 384.
{ "embeddingsProvider": { "provider": "transformers.js" } }
Force Re-Index
Currently we do not automatically re-index your docs.
If you would like to force a re-index, you can use the following command:
Ctrl + Shift + P
- Continue: Docs Force Re-Index
- Continue: Codebase Force Re-Index
Custom Commands
Custom commands are great when you are frequently reusing a prompt.
e.g.
"customCommands": [
{
"name": "test",
"prompt": "{{{ input }}}\n\nWrite a comprehensive set of unit tests for the selected code.
It should setup, run tests that check for correctness including important edge cases,
and teardown. Ensure that the tests are complete and sophisticated.
Give the tests just as chat output, don't edit any file.",
"description": "Write unit tests for highlighted code"
},
{
"name": "check",
"description": "Check for mistakes in my code",
"prompt": "{{{ input }}}\n\nPlease read the highlighted code and check for any mistakes.
You should look for the following, and be extremely vigilant:\n
- Syntax errors\n
- Logic errors\n
- Security vulnerabilities\n
- Performance issues\n
- Anything else that looks wrong\n\n
Once you find an error, please explain it as clearly as possible,
but without using extra words. For example, instead of saying 'I think there is a syntax error on line 5',
you should say 'Syntax error on line 5'.
Give your answer as one bullet point per mistake found."
}
],
Built-in variables
{{{ input }}} - The full text from the input box in the sidebar that is sent along with the slash command
If you type "/test only write one test", {{{ input }}} will be "only write one test"
{{{ currentFile }}} - The currently open file in your IDE