Skip to main content

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

  1. Install Python ≥ 3.7
    Windows: Python Downloads Mac/Linux: Preinstalled or use your package manager.

  2. Install Ollama Python client

    pip install ollama
    
  3. Ensure the Ollama server is running locally

    ollama serve
    
  4. 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 used
  • prompt_eval_count: Tokens in your prompt
  • eval_count: Tokens generated/used in completion
  • response: The full answer text from Ollama
  • total_duration: Full query latency (ns)
  • prompt_eval_duration: Prompt token eval time
  • eval_duration: Output token eval time
  • done: 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_count to track cost and offload efficiency.
    • Use prompt_eval_count for context window analytics.
  • Change model for any Ollama-supported LLM.

Troubleshooting

  • If you get ModuleNotFoundError: ollama, ensure pip install ollama matches 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

ollama_prompt-1.0.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ollama_prompt-1.0.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

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

Hashes for ollama_prompt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 69594f26781ec01768339ea9ad121c2110820a755cf457402185323b1a283940
MD5 c0eeafed7a5c11fef706b7cec63a38bd
BLAKE2b-256 8596e33aa275b27c5f25266f6c29fc93141c93ec35a7124929aef26ba3774952

See more details on using hashes here.

Provenance

The following attestation bundles were made for ollama_prompt-1.0.0.tar.gz:

Publisher: publish.yml on dansasser/ollama-prompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for ollama_prompt-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbe33dce052203aabbdb2aec2df43539a46c6e46433c0c8b02c6fa2c2b373215
MD5 7b81719596015c2a866ba64af9a23249
BLAKE2b-256 617291fc79ae765065eb791ffaf3338b71f1a163f735023b21e35d67e101f77c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ollama_prompt-1.0.0-py3-none-any.whl:

Publisher: publish.yml on dansasser/ollama-prompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page