diff options
| author | juodumas <juodumas@gmail.com> | 2023-09-18 13:59:51 +0300 |
|---|---|---|
| committer | juodumas <juodumas@gmail.com> | 2023-09-18 14:12:51 +0300 |
| commit | 356ead8aa66e939d78bf38b4e5515545bbdf5a91 (patch) | |
| tree | e73e4d970a0c00f737c78196f39bd26c96003434 /py/chat.py | |
| parent | 924e3a390f043e979f16113f6b0a55f8c54b1f5e (diff) | |
| download | vim-ai-356ead8aa66e939d78bf38b4e5515545bbdf5a91.tar.gz | |
Add support for base_url option to use local models
For example, you can start llama-cpp-python like this (it emulates
the openai api):
```sh
CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install 'llama-cpp-python[server]'
wget https://huggingface.co/TheBloke/CodeLlama-13B-Instruct-GGUF/resolve/main/codellama-13b-instruct.Q5_K_M.gguf
python3 -m llama_cpp.server --n_gpu_layers 100 --model codellama-13b-instruct.Q5_K_M.gguf
```
Then set the API url in your `.vimrc`:
```vim
let g:vim_ai_chat = {
\ "engine": "chat",
\ "options": {
\ "base_url": "http://127.0.0.1:8000",
\ },
\ }
```
And chat with the locally hosted AI using `:AIChat`.
The change in utils.py was needed because llama-cpp-python adds a new
line to the final response: `[DONE]^M`.
Diffstat (limited to '')
| -rw-r--r-- | py/chat.py | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -1,3 +1,4 @@ +from urllib.parse import urljoin # import utils plugin_root = vim.eval("s:plugin_root") vim.command(f"py3file {plugin_root}/py/utils.py") @@ -69,7 +70,9 @@ try: **openai_options } printDebug("[chat] request: {}", request) - response = openai_request('https://api.openai.com/v1/chat/completions', request, http_options) + base_url = options.get('base_url', 'https://api.openai.com') + url = urljoin(base_url, 'v1/chat/completions') + response = openai_request(url, request, http_options) def map_chunk(resp): printDebug("[chat] response: {}", resp) return resp['choices'][0]['delta'].get('content', '') |