mirror of
https://github.com/dogkeeper886/ollama37.git
synced 2025-12-15 10:17:03 +00:00
search command
This commit is contained in:
@@ -37,14 +37,6 @@ def main():
|
||||
title='commands',
|
||||
)
|
||||
|
||||
server.set_parser(
|
||||
subparsers.add_parser(
|
||||
"serve",
|
||||
description="Start a persistent server to interact with models via the API.",
|
||||
help="Start a persistent server to interact with models via the API.",
|
||||
)
|
||||
)
|
||||
|
||||
list_parser = subparsers.add_parser(
|
||||
"models",
|
||||
description="List all available models stored locally.",
|
||||
@@ -52,6 +44,18 @@ def main():
|
||||
)
|
||||
list_parser.set_defaults(fn=list_models)
|
||||
|
||||
search_parser = subparsers.add_parser(
|
||||
"search",
|
||||
description="Search for compatible models that Ollama can run.",
|
||||
help="Search for compatible models that Ollama can run. Usage: search [model]",
|
||||
)
|
||||
search_parser.add_argument(
|
||||
"query",
|
||||
nargs="?",
|
||||
help="Optional name of the model to search for.",
|
||||
)
|
||||
search_parser.set_defaults(fn=search)
|
||||
|
||||
pull_parser = subparsers.add_parser(
|
||||
"pull",
|
||||
description="Download a specified model from a remote source.",
|
||||
@@ -73,6 +77,14 @@ def main():
|
||||
)
|
||||
run_parser.set_defaults(fn=run)
|
||||
|
||||
server.set_parser(
|
||||
subparsers.add_parser(
|
||||
"serve",
|
||||
description="Start a persistent server to interact with models via the API.",
|
||||
help="Start a persistent server to interact with models via the API.",
|
||||
)
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
args = vars(args)
|
||||
|
||||
@@ -146,6 +158,22 @@ def generate_batch(*args, **kwargs):
|
||||
generate_oneshot(*args, **kwargs)
|
||||
|
||||
|
||||
def search(*args, **kwargs):
|
||||
try:
|
||||
model_names = model.search_directory(*args, **kwargs)
|
||||
if len(model_names) == 0:
|
||||
print("No models found.")
|
||||
return
|
||||
elif len(model_names) == 1:
|
||||
print(f"Found {len(model_names)} available model:")
|
||||
else:
|
||||
print(f"Found {len(model_names)} available models:")
|
||||
for model_name in model_names:
|
||||
print(model_name.lower())
|
||||
except Exception as e:
|
||||
print("Failed to fetch available models, check your network connection")
|
||||
|
||||
|
||||
def pull(*args, **kwargs):
|
||||
model.pull(model_name=kwargs.pop('model'), *args, **kwargs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user