### Quick Start Examples for ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Demonstrates basic usage of the ollama-prompt tool for simple queries, file reference usage, and continuing a previous session. ```bash # Simple query ollama-prompt --prompt "Explain Rust ownership" # With file reference ollama-prompt --prompt "Review @./src/auth.py for security issues" # Continue previous session ollama-prompt --session-id --prompt "What about the API layer?" ``` -------------------------------- ### Verify Ollama Installation Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md This command checks if the Ollama CLI is installed and lists available models, ensuring the prerequisites for using ollama-prompt are met. It's a simple verification step before proceeding with session management. ```bash ollama list ``` -------------------------------- ### Pull Local Ollama Models Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Example commands for downloading and installing language models locally using the Ollama CLI. ```bash # Pull models to your local machine ollama pull llama2:13b ollama pull codellama:7b ollama pull mistral:7b ``` -------------------------------- ### Parallel Work Sessions: Start and Track Multiple Sessions Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md This example shows how to manage multiple, distinct conversation sessions simultaneously. It creates separate JSON files for work and personal projects, extracts their respective session IDs, and demonstrates how to continue each one independently. ```bash # Create output directory mkdir -p ./sessions # Session 1: Work project ollama-prompt --prompt "Debug this production issue with authentication" > ./sessions/work.json WORK_SESSION=$(jq -r '.session_id' ./sessions/work.json) # Session 2: Personal project ollama-prompt --prompt "Help me learn guitar chords" > ./sessions/personal.json PERSONAL_SESSION=$(jq -r '.session_id' ./sessions/personal.json) # Later: Continue work session ollama-prompt --session-id $WORK_SESSION \ --prompt "What was the auth error we were debugging?" # Later: Continue personal session ollama-prompt --session-id $PERSONAL_SESSION \ --prompt "Now teach me the C major scale" ``` -------------------------------- ### Multi-day Project: Start and Save Session ID (Day 1) Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md This bash script initiates a conversation for a project on Day 1, saving the output to a file and extracting the session ID into a separate file. This allows the session to be resumed on subsequent days. ```bash # Start conversation ollama-prompt --prompt "I'm building a todo app. Help me outline the features." > day1.json # Save the session ID for tomorrow SESSION_ID=$(jq -r '.session_id' day1.json) echo $SESSION_ID > session.txt ``` -------------------------------- ### ollama-prompt: Code Review Across Files Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/README.md Provides examples for conducting code reviews across multiple files using ollama-prompt. It demonstrates starting a review session and then continuing the review on a related file while preserving context. ```bash # Start review session ollama-prompt --prompt "Review @./src/auth.py for security issues" # Gets session_id: abc-123 # Continue with related file (context preserved) ollama-prompt --session-id abc-123 --prompt "Now review @./src/api.py. Does it follow the same patterns?" ``` -------------------------------- ### Multi-day Project: Continue Session (Day 2) Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md This bash script resumes a project conversation started on a previous day by loading the saved session ID. It uses the full context of the prior conversation to continue the work. ```bash # Load session ID from yesterday SESSION_ID=$(cat session.txt) # Continue with full context ollama-prompt --session-id $SESSION_ID \ --prompt "Let's start with the React component structure" ``` -------------------------------- ### Complete Ollama Setup Verification Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md A combined command to verify both the Ollama CLI version and the availability of listed models, ensuring the setup is complete. ```bash # Complete setup verification ollama --version && ollama list # If both commands succeed, ollama-prompt should work with both local and cloud models ``` -------------------------------- ### Start a New ollama-prompt Session and Save Output Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md Initiates a new conversation with ollama-prompt and saves the response, including the session ID, to a JSON file. This is the first step in creating a persistent chat thread. The output JSON contains the model used, the response, and a unique session ID. ```bash ollama-prompt --prompt "Help me plan a Python web application" > conversation.json ``` -------------------------------- ### Continuing a Conversation with Session ID Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md Create a new conversation and then continue it by providing the session ID obtained from the first command's output. This demonstrates the process of starting a session and then using its unique UUID for subsequent interactions. ```bash # Creates session ollama-prompt --prompt "Question 1" > out.json # Continues that session ollama-prompt --session-id $(jq -r '.session_id' out.json) --prompt "Question 2" ``` -------------------------------- ### Session Cleanup: List and Purge Old Sessions Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md This example demonstrates how to manage old ollama-prompt sessions. It first lists all sessions with their creation dates, allowing you to identify old ones, and then uses the `--purge` command to remove sessions older than a specified number of days. ```bash # List all sessions to find old ones ollama-prompt --list-sessions | jq '.sessions[] | {id: .session_id, created: .created_at}' # Remove sessions older than 30 days ollama-prompt --purge 30 ``` -------------------------------- ### File Reference Syntax Examples Source: https://github.com/dansasser/ollama-prompt/blob/main/analysis/multi-agent-parallel-analysis-pattern.md Demonstrates the correct and incorrect syntax for referencing files within prompts. Correct syntax requires a path separator (e.g., './', '../', '/') to avoid errors. ```plaintext @./src/main.py (current directory) @../utils/helpers.js (parent directory) @/absolute/path/file.py (absolute Unix path) @./subdirectory/module.ts @file.py (missing path separator) @C:\Claude\file.py (Windows absolute path fails) @relative/path/file.py (missing ./ prefix) ``` -------------------------------- ### Create a Tutorial Outline and Content with ollama-prompt Sessions Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/guides/use-cases.md This example demonstrates using ollama-prompt sessions to progressively build tutorial content. The first step generates an outline for a tutorial on an authentication system, and the second step uses the same session to write the full tutorial content based on the outline. ```bash # Step 1: Outline ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.5 \ --max_tokens 6000 \ --session-id \ --prompt "Create an outline for a beginner's tutorial on using the authentication system in @./src/auth.py." ``` ```bash # Step 2: Write Tutorial ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.5 \ --max_tokens 8000 \ --session-id \ --prompt "Based on the outline we created, write the complete tutorial with code examples." ``` -------------------------------- ### Install ollama-prompt from Source Source: https://github.com/dansasser/ollama-prompt/blob/main/README.md Installs the ollama-prompt package in development mode by cloning the repository and using pip. Requires Python 3.7+ and Ollama installed. ```bash git clone https://github.com/dansasser/ollama-prompt.git cd ollama-prompt pip install -e . ``` -------------------------------- ### Install and Use ollama-prompt CLI Source: https://github.com/dansasser/ollama-prompt/blob/main/README.md Installs the ollama-prompt package via pip and demonstrates basic usage for initial questions and follow-up questions using session IDs. Assumes Ollama CLI is installed and running. ```bash # 1. Install pip install ollama-prompt # 2. First question (creates session automatically) ollama-prompt --prompt "What is 2+2?" # 3. Follow-up with context ollama-prompt --session-id --prompt "What about 3+3?" ``` -------------------------------- ### Verify Ollama CLI Installation and Model Availability Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Commands to check if the Ollama CLI is installed correctly and to list available models, confirming Ollama is operational. ```bash # Check Ollama installation ollama --version # List available models (confirms Ollama is working) ollama list ``` -------------------------------- ### Chaining Pattern for Multi-Batch Analysis with Ollama Source: https://github.com/dansasser/ollama-prompt/blob/main/analysis/multi-agent-parallel-analysis-pattern.md Provides a bash command-line example demonstrating how to chain analyses using file references. Each subsequent batch can reference the output files (e.g., JSON analysis reports) from previous batches. ```bash # Batch 1 ollama-prompt --prompt "Analyze @./module_a.py" > analysis1.json # Batch 2 references Batch 1 ollama-prompt --prompt "Building on @./analysis1.json, analyze @./module_b.py" > analysis2.json # Batch 3 references both ollama-prompt --prompt "Considering @./analysis1.json @./analysis2.json, analyze @./module_c.py" > analysis3.json ``` -------------------------------- ### Start Conversation with File Context Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/session-management.md Initiates a conversation by providing initial context from a file, indicated by the '@' symbol. This is useful for starting discussions with existing code or documents. ```bash # Good ollama-prompt --prompt "I'm reviewing authentication code. Here's the first file: @./auth.py" # Better ollama-prompt --prompt "Code review session: analyzing authentication security in a Python web app. First file: @./auth.py" ``` -------------------------------- ### Verify ollama-prompt Installation Source: https://github.com/dansasser/ollama-prompt/blob/main/README.md Commands to verify the successful installation of the ollama-prompt CLI tool and to check available Ollama models. Assumes Ollama is installed and running. ```bash ollama-prompt --help ollama list # Check available models ``` -------------------------------- ### Python SDK Database Operations for Session Management Source: https://context7.com/dansasser/ollama-prompt/llms.txt Provides examples of direct database operations for custom session management using the `SessionDatabase` class. This includes initializing the database, creating, retrieving, updating, listing, deleting, purging old sessions, and getting the total session count. It uses the `datetime` module for timestamps and `uuid` for session IDs. ```python #!/usr/bin/env python3 from ollama_prompt.session_db import SessionDatabase from datetime import datetime import uuid # Initialize database (uses platform default path) db = SessionDatabase() # Create session manually session_data = { 'session_id': str(uuid.uuid4()), 'context': '', 'max_context_tokens': 64000, 'history_json': '{"messages": []}', 'model_name': 'deepseek-v3.1:671b-cloud', 'created_at': datetime.now().isoformat(), 'last_used': datetime.now().isoformat() } session_id = db.create_session(session_data) print(f"Created session: {session_id}") # Retrieve session session = db.get_session(session_id) print(f"Context tokens: {len(session['context']) // 4}") # Update session db.update_session(session_id, { 'context': 'User: Hello\n\nAssistant: Hi there!', 'last_used': datetime.now().isoformat() }) # List all sessions sessions = db.list_all_sessions(limit=10) for s in sessions: print(f"{s['session_id']}: {s['model_name']} - {s['last_used']}") # Delete session deleted = db.delete_session(session_id) print(f"Deleted: {deleted}") # Purge old sessions deleted_count = db.purge_sessions(days=30) print(f"Purged {deleted_count} old sessions") # Get total count count = db.get_session_count() print(f"Total sessions: {count}") db.close() ``` -------------------------------- ### ollama-prompt: Subprocess Analysis Example Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/README.md Shows an example of integrating ollama-prompt as a subprocess for code analysis, specifically with Claude Code. It covers initiating analysis, saving output, and using the session ID to continue analysis in the same session. ```bash # Claude delegates analysis to ollama-prompt mkdir -p ollama-output # Analysis with session ollama-prompt --prompt "Analyze @./codebase/module.py" \ --model deepseek-v3.1:671b-cloud \ > ollama-output/analysis01.json # Continue analysis in same session cat ollama-output/analysis01.json | python -c "import json; print(json.load(sys.stdin)['session_id'])" # Use that session_id to continue ``` -------------------------------- ### AI Agent Subprocess Example with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/README.md An example bash script showing how an AI assistant like Claude could delegate analysis to ollama-prompt as a subprocess and parse the JSON output. Requires ollama-prompt and Ollama. ```bash # Claude delegates codebase analysis to ollama-prompt ollama-prompt --prompt "Analyze @./src/auth.py for security issues" \ --model deepseek-v3.1:671b-cloud \ > analysis.json # Claude parses JSON response and continues with its own reasoning ``` -------------------------------- ### Generate API Documentation with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/guides/use-cases.md This command generates comprehensive API documentation for a Python file (`./src/api.py`). It requests function signatures, parameters, return types, examples, and error handling details. The output is saved to `./ollama-output/api-docs.json`. ```bash ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max_tokens 8000 \ --prompt "Generate comprehensive API documentation for @./src/api.py. Include: function signatures, parameters, return types, examples, and error handling." \ > ./ollama-output/api-docs.json ``` -------------------------------- ### Troubleshoot Ollama Connection Refused Error Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Provides solutions for 'Connection refused' errors by verifying Ollama CLI installation and ensuring the Ollama server is running. ```bash # Solution: Verify Ollama CLI is installed and try running a command ollama list # The above command will automatically start the Ollama server # If still failing, check Ollama installation: ollama --version ``` -------------------------------- ### Basic ollama-prompt CLI Usage Source: https://github.com/dansasser/ollama-prompt/blob/main/README.md Demonstrates a basic command-line interaction with ollama-prompt to ask a question to a specified model. Requires ollama-prompt and Ollama to be installed. ```bash ollama-prompt --prompt "Explain Python decorators" \ --model deepseek-v3.1:671b-cloud ``` -------------------------------- ### ollama-prompt: Multi-turn Conversation Examples Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/README.md Illustrates how to manage multi-turn conversations using ollama-prompt. It shows initiating a conversation, continuing with a preserved context using a session ID, and following up on the discussion. ```bash # First question ollama-prompt --prompt "Explain Python decorators" # Follow-up (context preserved) ollama-prompt --session-id --prompt "Show me a practical example" # Continue discussion ollama-prompt --session-id --prompt "How does this compare to Java annotations?" ``` -------------------------------- ### Managing Context Limits and Stateless Mode in ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Illustrates how to check session token usage, start a new session to manage context, increase the context limit, and use stateless mode for one-off queries. Addresses the 'Context Limit Exceeded' problem. ```bash # Check usage ollama-prompt --session-info # Look at context_usage_percent # Start new session ollama-prompt --prompt "Fresh start" # Increase limit ollama-prompt --max-context-tokens 100000 --prompt "..." # Use stateless mode ollama-prompt --no-session --prompt "..." ``` -------------------------------- ### List All Active ollama-prompt Sessions Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md This command lists all currently active sessions managed by ollama-prompt. The output is a JSON object containing an array of sessions, with each session detailing its ID, model, creation/last used timestamps, message count, and context tokens. ```bash ollama-prompt --list-sessions ``` -------------------------------- ### Perform Multi-File Code Review Using Sessions with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/guides/use-cases.md This example shows a multi-turn code review process across multiple files using session management. An initial review of `./src/auth.py` creates a session, followed by a review of `./src/api.py` that leverages the existing session context. A final prompt summarizes all issues. ```bash # Initial Review (creates session): ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max_tokens 6000 \ --prompt "Review @./src/auth.py focusing on authentication logic and security." ``` ```bash # Follow-up Review (maintains context): ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max_tokens 6000 \ --session-id \ --prompt "Now review @./src/api.py. Check if it properly uses the auth module we just reviewed." ``` ```bash # Final Summary: ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max_tokens 6000 \ --session-id \ --prompt "Summarize all issues found across both files and prioritize by severity." ``` -------------------------------- ### View Details of a Specific ollama-prompt Session Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md Retrieves detailed information about a particular ollama-prompt session using its unique session ID. This includes the full conversation history and context. The command takes the session ID as an argument. ```bash ollama-prompt --session-info f8e3c2a1-4b5d-6e7f-8g9h-0i1j2k3l4m5n ``` -------------------------------- ### Continue a Specific ollama-prompt Session by ID Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md Resumes a specific conversation thread by providing its exact session ID to the `ollama-prompt` command. This allows you to pick up a conversation exactly where you left off, with all previous context loaded. ```bash ollama-prompt --session-id f8e3c2a1-4b5d-6e7f-8g9h-0i1j2k3l4m5n \ --prompt "What was our last topic?" ``` -------------------------------- ### ollama-prompt File Reading Command Source: https://github.com/dansasser/ollama-prompt/blob/main/analysis/cogent-context-efficiency-analysis.md Example command demonstrating how to use ollama-prompt to analyze a local file by injecting its content into the prompt. This process offloads file reading from the AI model to the Python script. ```bash ollama-prompt --prompt "Analyze @C:/path/to/file.py and provide..." \ --model deepseek-v3.1:671b-cloud \ --temperature 0.05 \ --max_tokens 8000 ``` -------------------------------- ### Scripting ollama-prompt Sessions with Bash Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/session-management.md This Bash script demonstrates how to manage sessions for code review tasks. It starts a new session, processes multiple files within that session, and then requests a summary of the findings. ```bash #!/bin/bash # Start code review session SESSION_ID=$(ollama-prompt --prompt "Starting code review of authentication module" | jq -r .session_id) # Review multiple files for file in src/auth/*.py; do ollama-prompt --prompt "Review @./$file" --session-id $SESSION_ID done # Get summary ollama-prompt --prompt "Summarize all findings" --session-id $SESSION_ID ``` -------------------------------- ### Batch Chaining with Token Optimization Example (Bash) Source: https://github.com/dansasser/ollama-prompt/blob/main/analysis/multi-agent-parallel-analysis-pattern.md Demonstrates how to chain multiple Ollama Prompt commands for an iterative security audit. It showcases the use of '@file' references to include previous analysis results, significantly reducing token count by allowing Claude to read only summaries or key findings from prior steps rather than the full output. ```bash # Batch 1: Initial Survey ollama-prompt --prompt "Survey authentication in @./auth/*.py" > auth_survey.json # Claude reads ONLY summary (2K tokens), identifies: "Custom JWT, potential SHA1 issue" # Batch 2: Deep Dive (references Batch 1 via @file) ollama-prompt --prompt "Deep analysis of JWT implementation.\n\nPrevious context: @./auth_survey.json\n\nFocus: Verify SHA1-HMAC usage, assess exploit feasibility" > jwt_analysis.json # Claude reads ONLY key findings (1.5K tokens) # Batch 3: Validation (references both previous batches) ollama-prompt --prompt "Validate JWT exploit chain.\n\nBuild on: @./auth_survey.json @./jwt_analysis.json\n\nAssess: Can we forge admin tokens?" > exploit_validation.json # Claude reads final validation (2K tokens) ``` -------------------------------- ### JSON Output Structure from Ollama-Prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/subprocess-best-practices.md Example of the JSON structure returned by ollama-prompt. It includes metadata like the model used, the actual response content (often markdown), and completion status with token counts. ```json { "model": "deepseek-v3.1:671b-cloud", "response": "Actual markdown content here...", "done": true, "eval_count": 1234 } ``` -------------------------------- ### Continue an ollama-prompt Session (PowerShell) Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md This PowerShell script demonstrates how to extract a session ID from a JSON output file and then use that ID to continue a previous conversation with ollama-prompt. It preserves the context of the prior chat. ```powershell # Extract session ID from JSON $sessionId = (Get-Content conversation.json | ConvertFrom-Json).session_id # Continue conversation with that UUID ollama-prompt --session-id $sessionId --prompt "Now let's design the database schema" ``` -------------------------------- ### Use JSON Extension for Ollama-Prompt Output Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/subprocess-best-practices.md Demonstrates the correct way to redirect ollama-prompt output to a JSON file, highlighting the importance of the .json extension for parsing metadata. It also shows an incorrect example using a .md extension. ```bash # CORRECT - Use .json extension ollama-prompt --prompt "..." > ./ollama-output/analysis01.json # WRONG - Don't use .md extension ollama-prompt --prompt "..." > analysis.md ``` -------------------------------- ### One-off Conversation with --no-session Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md Execute a single prompt without creating or saving a conversation session. This is useful for quick questions or handling sensitive data that should not be persisted. The output will not contain a session ID. ```bash ollama-prompt --no-session --prompt "Just help me with this quick regex" ``` -------------------------------- ### Continue an ollama-prompt Session (Bash/Unix) Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/quickstart.md This Bash script shows how to extract a session ID from a JSON output file using `jq` and then use that ID to resume a previous conversation with ollama-prompt, maintaining the chat's context. It's the Unix-like equivalent to the PowerShell method. ```bash # Extract session ID from JSON SESSION_ID=$(jq -r '.session_id' conversation.json) # Continue conversation with that UUID ollama-prompt --session-id $SESSION_ID --prompt "Now let's design the database schema" ``` -------------------------------- ### List All Available Ollama Models (Local and Cloud) Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md A command to display all models currently available, including both locally downloaded and cloud-based models. ```bash # List all available models (local and cloud) ollama list ``` -------------------------------- ### Common ollama-prompt Usage Patterns Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Presents a collection of common command-line patterns for using ollama-prompt, including single queries, file analysis, multi-turn sessions, parallel batch processing, and stateless queries. Useful for quick reference. ```bash # Single query ollama-prompt --prompt "Question" # With file ollama-prompt --prompt "Analyze @./file.py" # Multi-turn session ollama-prompt --prompt "Start" > out1.json SESSION=$(jq -r '.session_id' out1.json) ollama-prompt --session-id $SESSION --prompt "Continue" # Parallel batch for i in 1 2 3 4; do ollama-prompt --prompt "Analyze part $i" > analysis$i.json & done wait # Stateless ollama-prompt --no-session --prompt "One-off query" ``` -------------------------------- ### Troubleshoot Cloud Model Access with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Steps to re-authenticate, verify cloud model availability, and test cloud model access using ollama-prompt. ```bash # Re-authenticate if needed ollama signin # Verify cloud model is available ollama list | grep cloud # Test cloud model access with ollama-prompt ollama-prompt --prompt "test" --model deepseek-v3.1:671b-cloud --no-session ``` -------------------------------- ### Generate README.md with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/guides/use-cases.md This command generates a README.md file for a project by analyzing specified Python files (`./setup.py` and `./src/__init__.py`) to understand project structure and dependencies. It utilizes a session to maintain context from previous interactions. ```bash ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.5 \ --max_tokens 6000 \ --session-id \ --prompt "Generate a README.md for this project. Analyze @./setup.py and @./src/__init__.py to understand the project structure and dependencies." ``` -------------------------------- ### Create and Continue Sessions with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Demonstrates how to initiate a new session by piping output to a JSON file and then using the extracted session ID to continue the conversation. This pattern is useful for multi-turn interactions. ```bash # First call creates session ollama-prompt --prompt "..." > output.json # Extract UUID SESSION_ID=$(jq -r '.session_id' output.json) # Continue with that UUID ollama-prompt --session-id $SESSION_ID --prompt "..." ``` -------------------------------- ### Create and Manage Sessions with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/guides/use-cases.md Demonstrates how to initiate and continue conversational sessions with ollama-prompt. The first call creates a session with a unique ID, which can be reused for subsequent prompts to maintain context. Use `--list-sessions` and `--session-info` for managing sessions. ```bash # First Call (creates session): ollama-prompt --prompt "Your first question" # Output includes: "session_id": "f8e3c2a1-4b5d-6e7f-8g9h-0i1j2k3l4m5n" ``` ```bash # Continue Session (use the UUID from output): ollama-prompt --session-id f8e3c2a1-4b5d-6e7f-8g9h-0i1j2k3l4m5n \ --prompt "Follow-up question" ``` -------------------------------- ### Multi-Turn Workflow with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Demonstrates a multi-turn interaction using ollama-prompt, where sessions are created, continued with specific prompts, and output is redirected to JSON files. It highlights extracting session IDs for subsequent commands. ```bash # STEP 1: Create session ollama-prompt --prompt "Review @./src/auth.py" > ./ollama-output/turn1.json # Extract: "session_id": "f8e3c2a1-..." # STEP 2: Continue ollama-prompt --session-id f8e3c2a1-4b5d-6e7f-8g9h-0i1j2k3l4m5n \ --prompt "Check @./src/api.py integration" > ./ollama-output/turn2.json # STEP 3: Summary ollama-prompt --session-id f8e3c2a1-4b5d-6e7f-8g9h-0i1j2k3l4m5n \ --prompt "Summarize all issues" > ./ollama-output/summary.json ``` -------------------------------- ### ollama-prompt Session Auto-Creation JSON Output Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Example JSON output from ollama-prompt showing the auto-generated session ID when a new session is created. ```json { "model": "deepseek-v3.1:671b-cloud", "response": "...", "session_id": "f8e3c2a1-4b5d-6e7f-8g9h-0i1j2k3l4m5n" } ``` -------------------------------- ### Authenticate and Pull Cloud Ollama Models Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Instructions for signing into Ollama for cloud model access and pulling cloud model metadata for improved performance. ```bash # Authenticate with Ollama account (required for cloud models) ollama signin # Follow the prompts to create/login to your ollama.com account # Pull cloud model metadata (recommended for faster access) ollama pull deepseek-v3.1:671b-cloud ``` -------------------------------- ### Manage Ollama Sessions with SDK Source: https://context7.com/dansasser/ollama-prompt/llms.txt Demonstrates how to create, retrieve, and update Ollama sessions using the SDK's session manager. It covers initializing a session, loading an existing one, preparing prompts with context, and updating the session after receiving a model response. The session data structure is also outlined. ```python session, is_new = manager.get_or_create_session( model_name="deepseek-v3.1:671b-cloud", max_context_tokens=64000, system_prompt="You are a code review expert." ) print(f"Session ID: {session['session_id']}") print(f"Is new: {is_new}") # Load existing session session, is_new = manager.get_or_create_session( session_id="a3f5c8d1-2b4e-4f1a-8c9d-1e2f3a4b5c6d" ) # Prepare prompt with context user_prompt = "What security issues did you find?" full_prompt = manager.prepare_prompt(session, user_prompt) # After getting model response, update session assistant_response = "I found 3 SQL injection vulnerabilities..." manager.update_session(session, user_prompt, assistant_response) # Close database connection manager.close() ``` -------------------------------- ### ollama-prompt Session Auto-Creation Example Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Demonstrates how ollama-prompt automatically generates and stores a new session ID when the --session-id flag is not provided, returning the ID in JSON output. ```bash ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max_tokens 6000 \ --prompt "Analyze codebase structure" ``` -------------------------------- ### Run ollama-prompt with Default Parameters Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/guides/use-cases.md This is the basic command structure for using ollama-prompt. It specifies the model, temperature, maximum tokens, and the prompt. Outputs are typically saved to the './ollama-output/' directory. Ensure the output directory exists before running. ```bash ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max_tokens 6000 \ --prompt "Your prompt here" ``` -------------------------------- ### Standard Ollama Prompt Command Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md A standard template for running ollama-prompt commands. It emphasizes specifying the model, temperature, maximum tokens, and redirecting output to a designated directory. ```bash ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max_tokens 6000 \ --prompt "Analysis prompt" \ > ./ollama-output/result.json ``` -------------------------------- ### Python SDK File Reference Handling with Security Source: https://context7.com/dansasser/ollama-prompt/llms.txt Demonstrates how to process file references within prompts securely using the SDK. It includes functions to expand file references, read file snippets with byte limits, and safely join repository paths to prevent traversal attacks. Error handling for path traversal is also shown. ```python #!/usr/bin/env python3 from ollama_prompt.cli import ( expand_file_refs_in_prompt, read_file_snippet, safe_join_repo ) # Expand file references in prompt prompt = "Review @./src/auth.py and @./src/api.py for issues" expanded = expand_file_refs_in_prompt( prompt, repo_root="/path/to/project", max_bytes=200_000 ) print(expanded) # Read single file with bounds result = read_file_snippet( "./src/auth.py", repo_root="/path/to/project", max_bytes=100_000 ) if result['ok']: print(f"File: {result['path']}") print(f"Content length: {len(result['content'])}") else: print(f"Error: {result['error']}") # Safe path joining with traversal prevention try: safe_path = safe_join_repo("/path/to/project", "../etc/passwd") except ValueError as e: print(f"Path traversal blocked: {e}") # Allowed: relative paths within repo safe_path = safe_join_repo("/path/to/project", "./src/auth.py") print(f"Safe path: {safe_path}") ``` -------------------------------- ### Purge Old Sessions with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Removes sessions that are older than a specified number of days. This is useful for managing disk space and keeping the session list clean. For example, `--purge 7` removes sessions older than 7 days. ```bash ollama-prompt --purge 7 # Remove sessions older than 7 days ``` -------------------------------- ### Chaining Commands with jq Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Demonstrates how to chain ollama-prompt commands and process their JSON output using `jq`. This includes extracting session IDs, capturing response content into markdown files, and listing/filtering active sessions. ```bash # Extract session_id SESSION_ID=$(ollama-prompt --prompt "Start" | tee output.json | jq -r '.session_id') # Extract response content ollama-prompt --prompt "Analyze" | jq -r '.response' > analysis.md # Check if session exists ollama-prompt --list-sessions | jq '.sessions[] | select(.session_id == "f8e3c2a1-...")' ``` -------------------------------- ### Extract Response Content from JSON (Bash with jq) Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/subprocess-best-practices.md Demonstrates how to extract specific fields from JSON files generated by ollama-prompt using the 'jq' command-line JSON processor. The first example extracts only the 'response' field, while the second extracts 'model', 'eval_count', and 'response'. Assumes JSON files are located in './ollama-output/'. ```bash # Read just the response field from JSON cat ./ollama-output/analysis01.json | jq -r '.response' # Read with metadata cat ./ollama-output/analysis01.json | jq '{model, eval_count, response}' ``` -------------------------------- ### Automate Single File Code Review with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/guides/use-cases.md This command initiates a code review for a specific file (`./src/auth.py`), focusing on security, code quality, and best practices. The output is redirected to a JSON file for further analysis. It requires the specified model and parameters to be configured. ```bash ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max_tokens 6000 \ --prompt "Review @./src/auth.py for security issues, code quality, and best practices. Provide specific line numbers for issues found." \ > ./ollama-output/review-auth.json ``` -------------------------------- ### AI for Understanding Error Types with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/guides/ai-vs-grep-verification.md This bash command utilizes ollama-prompt to get an AI-driven understanding of potential flag errors within a specified file. It focuses on identifying error types and their general context, rather than exhaustive counting. The output is captured in a JSON file. Dependencies: ollama-prompt. ```bash ollama-prompt --prompt "What flag errors might exist in @file.md?" \ > understanding.json ``` -------------------------------- ### Standard Single Analysis with Ollama Prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/subprocess-best-practices.md This command performs a standard single analysis using the ollama-prompt CLI. It sets the model, temperature, and max-tokens, then directs the output to a JSON file. Ensure the output directory exists. ```bash mkdir -p ./ollama-output ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max-tokens 6000 \ --prompt "Analysis prompt" \ > ./ollama-output/analysis01.json ``` -------------------------------- ### Troubleshooting Session Not Found Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Provides steps to resolve 'Session not found' errors by listing available sessions and ensuring the correct session UUID is used in subsequent commands. ```bash # List all sessions to find correct UUID ollama-prompt --list-sessions # Use exact UUID from list ollama-prompt --session-id --prompt "..." ``` -------------------------------- ### Troubleshoot Ollama Model Not Found Error (Cloud) Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Steps to resolve 'Model not found' errors for cloud models by signing in and pulling the necessary model. ```bash # Solution: Authenticate and pull cloud model ollama signin ollama pull deepseek-v3.1:671b-cloud ``` -------------------------------- ### ollama-prompt: Session Management Utilities Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/README.md Demonstrates essential command-line utilities for managing ollama-prompt sessions. This includes listing all sessions, retrieving details for a specific session, and purging old sessions. ```bash # List All Sessions ollama-prompt --list-sessions # Show Session Details ollama-prompt --session-info # Cleanup Old Sessions # Remove sessions older than 30 days ollama-prompt --purge 30 ``` -------------------------------- ### Read config.py: Small, Simple Configuration File Source: https://github.com/dansasser/ollama-prompt/blob/main/analysis/multi-agent-parallel-analysis-pattern.md Reads and displays the content of a small Python configuration file ('config.py'). This is typically done when the file is under a certain line limit (e.g., 50 lines) and contains only configuration data without complex patterns, making direct content display more efficient than pattern analysis. ```python # Database configuration DATABASE = { 'host': 'localhost', 'port': 5432, 'name': 'app_db' } # API settings API_CONFIG = { 'timeout': 30, 'retry_attempts': 3 } ``` -------------------------------- ### Ollama-Prompt Python SDK - Session Manager Initialization Source: https://context7.com/dansasser/ollama-prompt/llms.txt Demonstrates the basic initialization of the SessionManager from the ollama_prompt Python SDK. This class provides programmatic access to manage Ollama conversation sessions. ```python #!/usr/bin/env python3 from ollama_prompt.session_manager import SessionManager # Initialize manager with default database manager = SessionManager() ``` -------------------------------- ### ollama-prompt: Auto-create and Continue Sessions Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/README.md Demonstrates the new auto-session creation feature in v1.2.0 and how to continue a conversation using a persistent session ID. It also shows how to opt-out for stateless operations. ```bash # Auto-creates session (NEW in v1.2.0) ollama-prompt --prompt "Hello" # Output includes: "session_id": "abc-123-def-456" # Continue conversation with full context ollama-prompt --session-id abc-123-def-456 --prompt "What did I just say?" # Opt-out for stateless operation ollama-prompt --no-session --prompt "One-off query" ``` -------------------------------- ### Command-Line Flags: File References Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Sets parameters related to file referencing. Includes the root directory for relative paths and the maximum byte size allowed for individual files to be included in prompts. ```bash --repo-root # Base directory (default: .) --max-file-bytes # Max bytes per file (default: 200,000) ``` -------------------------------- ### File Analysis with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/README.md Shows how to use the `@./path/to/file.py` syntax within a prompt to have ollama-prompt analyze local files. Requires ollama-prompt and Ollama. ```bash ollama-prompt --prompt "Review @./src/auth.py for security issues" ``` -------------------------------- ### Understanding Session Pruning and Output Redirection in ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Explains the automatic session pruning behavior based on context token usage and provides the correct method for redirecting command output to a file using shell redirection. Corrects the misconception about an `--output` flag. ```bash # Check usage ollama-prompt --session-info # Check context_usage_percent # Correct output redirection ollama-prompt --prompt "..." > ./ollama-output/result.json ``` -------------------------------- ### Launch 4 Concurrent Analyses with Ollama-Prompt (Bash) Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/subprocess-best-practices.md Launches four independent analyses concurrently using the ollama-prompt CLI tool. Each analysis uses the same model and settings but targets a different prompt. The '&' symbol runs each command in the background, and 'wait' ensures all background jobs are completed before proceeding. Output is redirected to separate JSON files. ```bash ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max-tokens 6000 \ --prompt "Analyze CLI structure..." \ > ./ollama-output/cli-analysis.json & ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max-tokens 6000 \ --prompt "Analyze API integration..." \ > ./ollama-output/api-analysis.json & ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max-tokens 6000 \ --prompt "Design database schema..." \ > ./ollama-output/database-design.json & ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max-tokens 6000 \ --prompt "Create implementation roadmap..." \ > ./ollama-output/roadmap.json & wait echo "All analyses complete. Results in ./ollama-output/" ``` -------------------------------- ### Scripting ollama-prompt Sessions with PowerShell Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/sessions/session-management.md This PowerShell script illustrates session management for code reviews. It initiates a session, iterates through Python files in a specified directory, and sends them for review within the established session. ```powershell # Start code review session $result = ollama-prompt --prompt "Starting code review" | ConvertFrom-Json $sessionId = $result.session_id # Review files Get-ChildItem src\auth\*.py | ForEach-Object { ollama-prompt --prompt "Review @$($_.FullName)" --session-id $sessionId } ``` -------------------------------- ### Basic Ollama-Prompt CLI Query Source: https://context7.com/dansasser/ollama-prompt/llms.txt Executes a single, stateless prompt to Ollama, returning a full JSON response with metadata. This is useful for quick queries without needing conversation history. ```bash # Basic query ollama-prompt --prompt "Explain Python decorators" \ --model deepseek-v3.1:671b-cloud \ --temperature 0.1 \ --max_tokens 2048 # Output: Full JSON response with metadata { "model": "deepseek-v3.1:671b-cloud", "created_at": "2025-11-15T10:30:45.123Z", "response": "Python decorators are functions that modify...", "done": true, "total_duration": 1234567890, "load_duration": 123456, "prompt_eval_count": 45, "eval_count": 256, "session_id": "a3f5c8d1-2b4e-4f1a-8c9d-1e2f3a4b5c6d" } ``` -------------------------------- ### Continue Session with ollama-prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Loads an existing session using its UUID, prepends conversation context, and updates the session with the new exchange. Requires a valid UUID for the --session-id flag. ```bash ollama-prompt --session-id f8e3c2a1-4b5d-6e7f-8g9h-0i1j2k3l4m5n \ --prompt "Now analyze the auth module" ``` -------------------------------- ### Command-Line Flags: Utilities Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Provides utility commands for managing sessions. These include listing all sessions, purging old sessions based on age, and retrieving detailed information about a specific session. ```bash --list-sessions # List all sessions --purge # Remove old sessions --session-info # Show session details ``` -------------------------------- ### Command-Line Flags: Model & Generation Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Configures model selection and generation parameters. Options include specifying the model name, temperature for creativity, and maximum tokens for response length. ```bash --model # Default: deepseek-v3.1:671b-cloud --temperature # Default: 0.1 --max_tokens # Default: 2048 --think # Enable thinking mode ``` -------------------------------- ### Basic Ollama-Prompt Subprocess Call Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/subprocess-best-practices.md A standard bash command template for invoking ollama-prompt as a subprocess. It includes essential parameters like model, temperature, max-tokens, and prompt, with output redirected to a JSON file. ```bash ollama-prompt --model deepseek-v3.1:671b-cloud \ --temperature 0.4 \ --max-tokens 6000 \ --prompt "Analysis prompt text here" \ > ./ollama-output/analysis01.json ``` -------------------------------- ### Troubleshoot Ollama Authentication Required Error Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/reference.md Instructions to resolve 'Authentication required' errors by signing into the Ollama account. ```bash # Solution: Sign in to Ollama account ollama signin ``` -------------------------------- ### File Reference Syntax for Ollama-Prompt Source: https://github.com/dansasser/ollama-prompt/blob/main/docs/subprocess-best-practices.md Demonstrates the syntax for using the '--file-reference' flag in ollama-prompt to include the content of local files in the prompt. Supports both single and multiple file references. ```bash --file-reference ./path/to/file # Single file --file-reference ./file1 \ # Multiple files --file-reference ./file2 ```