Ollama CLI prompt tool for local LLM code analysis
Project description
ollama-prompt.py – Local Ollama CLI Tool for Deep Analysis
Overview
ollama-prompt is a cross-platform Python command-line utility to interact with a local Ollama server for advanced code analysis, prompt evaluation, and cost tracking. It sends a user-defined prompt to a chosen Ollama model, offloads analysis, and returns a complete JSON response with all server-side metadata: prompt, output, token counts, durations, and more.
This tool is ideal for:
- AGI agent orchestration
- Cost-aware code review workflows
- Analytics on token usage
- Integrating structured LLM output into your developer pipeline
Features
- Flexible CLI flags: set prompt, model, temperature, and token count.
- Prints full verbose JSON: includes response text, token usage (
prompt_eval_count,eval_count), and engine stats. - Matches PowerShell API workflows and allows easy parsing for downstream analysis, reporting, or archiving.
- Works on Windows, Mac, Linux with Python 3.7+ and Ollama installed.
Installation
-
Install Python ≥ 3.7
Windows: Python Downloads Mac/Linux: Preinstalled or use your package manager. -
Install Ollama Python client
pip install ollama
-
Ensure the Ollama server is running locally
ollama serve -
Download/copy the script Save the following code as
ollama-prompt.py:
import ollama
import argparse
import json
def main():
parser = argparse.ArgumentParser(description="Send a prompt to local Ollama and get full verbose JSON response (tokens, durations, output).")
parser.add_argument('--prompt', required=True, help="Prompt to send to the model")
parser.add_argument('--model', default="deepseek-v3.1:671b-cloud", help="Model name")
parser.add_argument('--temperature', type=float, default=0.1, help="Sampling temperature")
parser.add_argument('--max_tokens', type=int, default=2048, help="Maximum tokens for response")
args = parser.parse_args()
result = ollama.generate(
model=args.model,
prompt=args.prompt,
options={
"temperature": args.temperature,
"num_predict": args.max_tokens
},
stream=False
)
result_dict = result.model_dump() if hasattr(result, "model_dump") else dict(result)
print(json.dumps(result_dict, indent=2))
if __name__ == "__main__":
main()
Usage
Basic Analysis
python3 ollama-prompt.py --prompt "Summarize the architecture in src/modules." --model deepseek-v3.1:671b-cloud
Custom Temperature & Tokens
python3 ollama-prompt.py --prompt "Evaluate performance of the sorting algorithms." --temperature 0.05 --max_tokens 4096
Full JSON Output for Agent/Log Use
python3 ollama-prompt.py --prompt "Critical design flaws in utils.py?" > analysis.json
Output
Returns a single JSON object. Example fields:
model: Model name usedprompt_eval_count: Tokens in your prompteval_count: Tokens generated/used in completionresponse: The full answer text from Ollamatotal_duration: Full query latency (ns)prompt_eval_duration: Prompt token eval timeeval_duration: Output token eval timedone: Completion status
Advanced Tips
- Pipe results to jq or similar for further processing:
python3 ollama-prompt.py --prompt "..." | jq .eval_count
- Integrate in agent loops or cost dashboards:
- Use
eval_countto track cost and offload efficiency. - Use
prompt_eval_countfor context window analytics.
- Use
- Change
modelfor any Ollama-supported LLM.
Troubleshooting
- If you get
ModuleNotFoundError: ollama, ensurepip install ollamamatches the Python interpreter used. - Ollama must be running locally for API requests to succeed.
- For maximum context windows, check your model’s max token support.
License
MIT (see Ollama license)
Credits
Developed by Daniel T Sasser II (and Comet Assistant) for robust code offload workflows, AGI agent orchestration, and token/cost analytics.
For help or suggestions, open an issue or contact the developer.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ollama_prompt-1.0.0.tar.gz.
File metadata
- Download URL: ollama_prompt-1.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69594f26781ec01768339ea9ad121c2110820a755cf457402185323b1a283940
|
|
| MD5 |
c0eeafed7a5c11fef706b7cec63a38bd
|
|
| BLAKE2b-256 |
8596e33aa275b27c5f25266f6c29fc93141c93ec35a7124929aef26ba3774952
|
Provenance
The following attestation bundles were made for ollama_prompt-1.0.0.tar.gz:
Publisher:
publish.yml on dansasser/ollama-prompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ollama_prompt-1.0.0.tar.gz -
Subject digest:
69594f26781ec01768339ea9ad121c2110820a755cf457402185323b1a283940 - Sigstore transparency entry: 641774032
- Sigstore integration time:
-
Permalink:
dansasser/ollama-prompt@be7a8437c1afa3245e64201e819680e7fa994869 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dansasser
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@be7a8437c1afa3245e64201e819680e7fa994869 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ollama_prompt-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ollama_prompt-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbe33dce052203aabbdb2aec2df43539a46c6e46433c0c8b02c6fa2c2b373215
|
|
| MD5 |
7b81719596015c2a866ba64af9a23249
|
|
| BLAKE2b-256 |
617291fc79ae765065eb791ffaf3338b71f1a163f735023b21e35d67e101f77c
|
Provenance
The following attestation bundles were made for ollama_prompt-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on dansasser/ollama-prompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ollama_prompt-1.0.0-py3-none-any.whl -
Subject digest:
bbe33dce052203aabbdb2aec2df43539a46c6e46433c0c8b02c6fa2c2b373215 - Sigstore transparency entry: 641774034
- Sigstore integration time:
-
Permalink:
dansasser/ollama-prompt@be7a8437c1afa3245e64201e819680e7fa994869 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dansasser
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@be7a8437c1afa3245e64201e819680e7fa994869 -
Trigger Event:
release
-
Statement type: