From 9154298085b8631099be6cdcd9bcb6a32eef899f Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Wed, 28 Jun 2023 14:25:07 -0700 Subject: [PATCH 1/2] use abspath to model --- ollama/engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ollama/engine.py b/ollama/engine.py index 7fefa109..91c298e8 100644 --- a/ollama/engine.py +++ b/ollama/engine.py @@ -45,7 +45,7 @@ def load(model, models_home=".", llms={}): if not model_path: # try loading this as a path to a model, rather than a model name - model_path = model + model_path = os.path.abspath(model) # suppress LLM's output with suppress_stderr(): From e63ad69388c49b3b0a719e286472f0a8dad0d90a Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Wed, 28 Jun 2023 14:33:10 -0700 Subject: [PATCH 2/2] batch mode --- ollama/cmd/cli.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/ollama/cmd/cli.py b/ollama/cmd/cli.py index 017d6d07..270ba283 100644 --- a/ollama/cmd/cli.py +++ b/ollama/cmd/cli.py @@ -54,15 +54,18 @@ def list_models(*args, **kwargs): def generate(*args, **kwargs): if prompt := kwargs.get('prompt'): print('>>>', prompt, flush=True) - print(flush=True) generate_oneshot(*args, **kwargs) - print(flush=True) return - return generate_interactive(*args, **kwargs) + if sys.stdin.isatty(): + return generate_interactive(*args, **kwargs) + + return generate_batch(*args, **kwargs) def generate_oneshot(*args, **kwargs): + print(flush=True) + for output in engine.generate(*args, **kwargs): output = json.loads(output) choices = output.get("choices", []) @@ -70,20 +73,26 @@ def generate_oneshot(*args, **kwargs): print(choices[0].get("text", ""), end="", flush=True) # end with a new line - print() + print(flush=True) + print(flush=True) def generate_interactive(*args, **kwargs): - print('>>> ', end='', flush=True) - for line in sys.stdin: - if not sys.stdin.isatty(): - print(line, end='') - - print(flush=True) - kwargs.update({'prompt': line}) - generate_oneshot(*args, **kwargs) - print(flush=True) + while True: print('>>> ', end='', flush=True) + line = next(sys.stdin) + if not line: + return + + kwargs.update({"prompt": line}) + generate_oneshot(*args, **kwargs) + + +def generate_batch(*args, **kwargs): + for line in sys.stdin: + print('>>> ', line, end='', flush=True) + kwargs.update({"prompt": line}) + generate_oneshot(*args, **kwargs) def add(model, models_home):