add function

This commit is contained in:
Bruce MacDonald 2023-06-27 17:36:02 -04:00
parent 7454900733
commit 01d2667f8b
3 changed files with 18 additions and 11 deletions

View file

@ -50,6 +50,14 @@ models = ollama.models()
Serve the ollama http server Serve the ollama http server
### `ollama.add(filepath)`
Add a model by importing from a file
```python
ollama.add("./path/to/model")
```
## Cooming Soon ## Cooming Soon
### `ollama.pull(model)` ### `ollama.pull(model)`
@ -60,14 +68,6 @@ Download a model
ollama.pull("huggingface.co/thebloke/llama-7b-ggml") ollama.pull("huggingface.co/thebloke/llama-7b-ggml")
``` ```
### `ollama.import(filename)`
Import a model from a file
```python
ollama.import("./path/to/model")
```
### `ollama.search("query")` ### `ollama.search("query")`
Search for compatible models that Ollama can run Search for compatible models that Ollama can run

View file

@ -23,8 +23,8 @@ def main():
generate_parser.set_defaults(fn=generate) generate_parser.set_defaults(fn=generate)
add_parser = subparsers.add_parser("add") add_parser = subparsers.add_parser("add")
add_parser.add_argument("model_file") add_parser.add_argument("file")
generate_parser.set_defaults(fn=add) add_parser.set_defaults(fn=add)
args = parser.parse_args() args = parser.parse_args()
args = vars(args) args = vars(args)
@ -48,4 +48,4 @@ def generate(*args, **kwargs):
def add(*args, **kwargs): def add(*args, **kwargs):
model.add(*args, **kwargs) engine.add(*args, **kwargs)

View file

@ -1,6 +1,7 @@
import os import os
import json import json
import sys import sys
import shutil
from contextlib import contextmanager from contextlib import contextmanager
from llama_cpp import Llama as LLM from llama_cpp import Llama as LLM
from template import template from template import template
@ -61,3 +62,9 @@ def load(model, models_home=".", llms={}):
def unload(model, llms={}): def unload(model, llms={}):
if model in llms: if model in llms:
llms.pop(model) llms.pop(model)
def add(file, models_home=".", *args, **kwargs):
if not os.path.exists(file):
raise ValueError("Model file {model} not found")
shutil.move(file, models_home)