Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Use Local / Remote Ollama with PowerShell 7 on Windows

#1
How to Use Local / Remote Ollama with PowerShell 7 on Windows

This guide shows you how to set up a custom PowerShell command to interact with your local/remote Ollama server from the Windows console.


Step 1: Install PowerShell 7
  • Go to PowerShell GitHub Releases.
  • Download the latest MSI installer for Windows (e.g., PowerShell-7.x.x-win-x64.msi).
  • Run the installer and follow the prompts.
  • Start PowerShell 7 by typing pwsh in your Start menu or terminal.

Step 2: Set Up Your PowerShell Profile
  • Open PowerShell 7 (pwsh).
  • Type:
    Code:
    notepad $PROFILE
  • If prompted, create the file.
  • Paste the following function into the file: (replace model and uri with custom parameters)
    Code:
    function ollama {
        param(
            [Parameter(ValueFromRemainingArguments=$true)]
            $PromptArgs
        )
        $prompt = $PromptArgs -join " "
        $body = @{ model = "llama3.2"; prompt = $prompt } | ConvertTo-Json
        $response = Invoke-RestMethod -Uri "http://192.168.1.69:7869/api/generate" -Method POST -Body $body -ContentType "application/json"
        $lines = $response -split "`n"
        $answer = ($lines | ForEach-Object {
            try { ($_.Trim() | ConvertFrom-Json).response } catch {}
        }) -join ""
        Write-Host $answer
    }
  • Save and close Notepad.
  • Reload your profile by typing:
    Code:
    . $PROFILE

Note*
When you define a function (like ollama) in your profile, you can call it by typing its name in the console—this is known as a function-based command in PowerShell.

Step 3: Use Your Custom Command (Or alias)
  • In PowerShell 7, type:
    Code:
    ollama Your prompt here
  • Example:
    Code:
    ollama What is the capital of France?
  • You’ll see the combined response from your Ollama server.

Notes:
  • Make sure your Ollama server is running and accessible at the IP and port you specified.
  • You can change the model name or server address in the function as needed.
  • This command only sends text prompts and returns text responses.
[Image: RvghcKs.png]
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Microsoft - New steps to preserve and protect journalism and local newsrooms xSicKxBot 0 1,384 10-07-2020, 06:27 PM
Last Post: xSicKxBot
  Microsoft - How research can enable more effective remote work xSicKxBot 0 1,423 04-11-2020, 12:49 AM
Last Post: xSicKxBot
  Microsoft - Enabling Remote Work in Response to COVID-19 xSicKxBot 0 1,396 04-02-2020, 03:38 AM
Last Post: xSicKxBot
  Microsoft - PowerShell 7.0 now generally available xSicKxBot 0 1,465 03-04-2020, 08:50 PM
Last Post: xSicKxBot
  Microsoft - How state and local governments are using chatbots to improve operations xSicKxBot 0 2,729 03-18-2019, 07:20 PM
Last Post: xSicKxBot
  Microsoft - Windows 10 Tip: Set up Windows Hello from your lock screen xSicKxBot 0 1,813 09-12-2018, 11:50 PM
Last Post: xSicKxBot

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016