{"id":13861717,"url":"https://github.com/simonw/llm-llama-cpp","last_synced_at":"2025-04-09T09:07:08.510Z","repository":{"id":185367659,"uuid":"670826050","full_name":"simonw/llm-llama-cpp","owner":"simonw","description":"LLM plugin for running models using llama.cpp","archived":false,"fork":false,"pushed_at":"2024-01-29T00:13:54.000Z","size":66,"stargazers_count":133,"open_issues_count":13,"forks_count":18,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-05-03T01:19:59.803Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-25T23:47:45.000Z","updated_at":"2024-08-05T06:03:50.751Z","dependencies_parsed_at":null,"dependency_job_id":"6c772755-7360-47fd-b697-1515c8414395","html_url":"https://github.com/simonw/llm-llama-cpp","commit_stats":null,"previous_names":["simonw/llm-llama-cpp"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-llama-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-llama-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-llama-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-llama-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/llm-llama-cpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008631,"owners_count":21032556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-05T06:01:28.704Z","updated_at":"2025-04-09T09:07:08.487Z","avatar_url":"https://github.com/simonw.png","language":"Python","readme":"# llm-llama-cpp\n\n[![PyPI](https://img.shields.io/pypi/v/llm-llama-cpp.svg)](https://pypi.org/project/llm-llama-cpp/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/llm-llama-cpp?include_prereleases\u0026label=changelog)](https://github.com/simonw/llm-llama-cpp/releases)\n[![Tests](https://github.com/simonw/llm-llama-cpp/workflows/Test/badge.svg)](https://github.com/simonw/llm-llama-cpp/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/llm-llama-cpp/blob/main/LICENSE)\n\n[LLM](https://llm.datasette.io/) plugin for running models using [llama.cpp](https://github.com/ggerganov/llama.cpp)\n\n## Installation\n\nInstall this plugin in the same environment as `llm`.\n```bash\nllm install llm-llama-cpp\n```\nThe plugin has an additional dependency on [llama-cpp-python](https://github.com/abetlen/llama-cpp-python) which needs to be installed separately.\n\nIf you have a C compiler available on your system you can install that like so:\n```bash\nllm install llama-cpp-python\n```\nYou could also try installing one of the wheels made available in their [latest release](https://github.com/abetlen/llama-cpp-python/releases/latest) on GitHub. Find the URL to the wheel for your platform, if one exists, and run:\n```bash\nllm install https://...\n```\nIf you are on an Apple Silicon Mac you can try this command, which should compile the package with METAL support for running on your GPU:\n\n```bash\nCMAKE_ARGS=\"-DLLAMA_METAL=on\" FORCE_CMAKE=1 llm install llama-cpp-python\n```\n## Running a GGUF model directly\n\nThe quickest way to try this plugin out is to download a GGUF file and execute that using the `gguf` model with the `-o path PATH` option:\n\nFor example, download the `una-cybertron-7b-v2-bf16.Q8_0.gguf` file from [TheBloke/una-cybertron-7B-v2-GGUF](https://huggingface.co/TheBloke/una-cybertron-7B-v2-GGUF/tree/main) and execute it like this:\n\n```bash\nllm -m gguf \\\n  -o path una-cybertron-7b-v2-bf16.Q8_0.gguf \\\n  'Instruction: Five reasons to get a pet walrus\nResponse:'\n```\nThe output starts like this:\n\n\u003e  1. Walruses are fascinating animals that possess unique qualities that can captivate and entertain you for hours on end. Getting the chance to be around one regularly would ensure that you'll never run out of interesting things to learn about them, whether from an educational or personal standpoint.\n\u003e\n\u003e 2. Pet walruses can help alleviate depression and anxiety, as they require constant care and attention. Nurturing a relationship with these intelligent creatures provides comfort and fulfillment, fostering a sense of purpose in your daily life. Moreover, their playful nature encourages laughter and joy, promoting overall happiness. [...]\n\n## Adding models\n\nYou can also add or download models to execute them directly using the `-m` option.\n\nThis tool should work with any model that works with `llama.cpp`.\n\nThe plugin can download models for you. Try running this command:\n\n```bash\nllm llama-cpp download-model \\\n  https://huggingface.co/TheBloke/Llama-2-7b-Chat-GGUF/resolve/main/llama-2-7b-chat.Q6_K.gguf \\\n  --alias llama2-chat --alias l2c --llama2-chat\n```\nThis will download the Llama 2 7B Chat GGUF model file (this one is 5.53GB), save it and register it with the plugin - with two aliases, `llama2-chat` and `l2c`.\n\nThe `--llama2-chat` option configures it to run using a special Llama 2 Chat prompt format. You should omit this for models that are not Llama 2 Chat models.\n\nIf you have already downloaded a `llama.cpp` compatible model you can tell the plugin to read it from its current location like this:\n\n```bash\nllm llama-cpp add-model path/to/llama-2-7b-chat.Q6_K.gguf \\\n  --alias l27c --llama2-chat\n```\nThe model filename (minus the `.gguf` extension) will be registered as its ID for executing the model.\n\nYou can also set one or more aliases using the `--alias` option.\n\nYou can see a list of models you have registered in this way like this:\n```bash\nllm llama-cpp models\n```\nModels are registered in a `models.json` file. You can find the path to that file in order to edit it directly like so:\n```bash\nllm llama-cpp models-file\n```\nFor example, to edit that file in Vim:\n```bash\nvim \"$(llm llama-cpp models-file)\"\n```\nTo find the directory with downloaded models, run:\n```bash\nllm llama-cpp models-dir\n```\nHere's how to change to that directory:\n```bash\ncd \"$(llm llama-cpp models-dir)\"\n```\n\n## Running a prompt through a model\n\nOnce you have downloaded and added a model, you can run a prompt like this:\n```bash\nllm -m llama-2-7b-chat.Q6_K 'five names for a cute pet skunk'\n```\nOr if you registered an alias you can use that instead:\n```bash\nllm -m llama2-chat 'five creative names for a pet hedgehog'\n```\n\n## More models to try\n\n### Llama 2 7B\n\nThis model is Llama 2 7B GGML without the chat training. You'll need to prompt it slightly differently:\n```bash\nllm llama-cpp download-model \\\n  https://huggingface.co/TheBloke/Llama-2-7B-GGUF/resolve/main/llama-2-7b.Q6_K.gguf \\\n  --alias llama2\n```\nTry prompts that expect to be completed by the model, for example:\n```bash\nllm -m llama2 'Three fancy names for a posh albatross are:'\n```\n### Llama 2 Chat 13B\n\nThis model is the Llama 2 13B Chat GGML model - a 10.7GB download:\n```bash\nllm llama-cpp download-model \\\n  'https://huggingface.co/TheBloke/Llama-2-13B-chat-GGUF/resolve/main/llama-2-13b-chat.Q6_K.gguf'\\\n  -a llama2-chat-13b --llama2-chat\n```\n\n### Llama 2 Python 13B\n\nThis model is the Llama 2 13B Python GGML model - a 9.24GB download:\n```bash\nllm llama-cpp download-model \\\n  'https://huggingface.co/TheBloke/CodeLlama-13B-Python-GGUF/resolve/main/codellama-13b-python.Q5_K_M.gguf'\\\n  -a llama2-python-13b --llama2-chat\n```\n\n## Options\n\nThe following options are available:\n\n- `-o verbose 1` - output more verbose logging\n- `-o max_tokens 100` - max tokens to return. Defaults to 4000.\n- `-o no_gpu 1` - remove the default `n_gpu_layers=1`` argument, which should disable GPU usage\n- `-o n_gpu_layers 10` - increase the `n_gpu_layers` argument to a higher value (the default is `1`)\n- `-o n_ctx 1024` - set the `n_ctx` argument to `1024` (the default is `4000`)\n\nFor example:\n\n```bash\nllm chat -m llama2-chat-13b -o n_ctx 1024\n```\n\nThese are mainly provided to support experimenting with different ways of executing the underlying model.\n\n## Development\n\nTo set up this plugin locally, first checkout the code. Then create a new virtual environment:\n```bash\ncd llm-llama-cpp\npython3 -m venv venv\nsource venv/bin/activate\n```\nNow install the dependencies and test dependencies:\n```bash\npip install -e '.[test]'\n```\nTo run the tests:\n```bash\npytest\n```\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fllm-llama-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fllm-llama-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fllm-llama-cpp/lists"}