From 1db3402d0c997a81a0c403fa25529dfe2519bf7a8c6ee99011acb402737d80e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Mon, 29 Jul 2024 11:18:37 +0200 Subject: [PATCH] indenting --- askollama/cli.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/askollama/cli.py b/askollama/cli.py index 5a9437e..4c2e035 100644 --- a/askollama/cli.py +++ b/askollama/cli.py @@ -3,12 +3,12 @@ import sys from argparse import ArgumentParser import ollama +default_model = 'llama3.1' client_url = os.getenv('OLLAMA_HOST') if client_url is None: # lookup config file if client_url is None: client_url = '0.0.0.0' # localhost -default_model = 'llama3.1' parser = ArgumentParser('ollama-ask', description='Ollama CLI options') parser.add_argument('-m', '--model', default=default_model, help='Specify ollama model') @@ -27,34 +27,29 @@ def cli(): def run(host, model, question): client = ollama.Client(host=host) - messages = [ - { - 'role': 'user', - 'content': question, - }, - ] + messages = [{ 'role': 'user', 'content': question }] try: - for part in client.chat(model=model, messages=messages, stream=True): - print(part['message']['content'], end='', flush=True) - except ollama._types.ResponseError as e: - if e.status_code == 404: - print('Model not available, trying to pull it...', file=sys.stderr) - for progress in client.pull(model, stream=True): - digest = progress.get('digest', '') - if not digest: - print(progress.get('status')) - continue - print("Asking again...", file=sys.stderr) for part in client.chat(model=model, messages=messages, stream=True): - print(part['message']['content'], end='', flush=True) + print(part['message']['content'], end='', flush=True) + except ollama._types.ResponseError as e: + if e.status_code == 404: + print('Model not available, trying to pull it...', file=sys.stderr) + for progress in client.pull(model, stream=True): + digest = progress.get('digest', '') + if not digest: + print(progress.get('status')) + continue + print("Asking again...", file=sys.stderr) + for part in client.chat(model=model, messages=messages, stream=True): + print(part['message']['content'], end='', flush=True) print() if args.debug: print("Server using: ", args.host) print("Model using : ", args.model) - print("Question: ", question) + print("Question : ", question) run(args.host, args.model, question)