Add How to Use Local / Remote Ollama with PowerShell 7 on Windows
@@ -0,0 +1,74 @@
|
||||
# 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 Ollama server from the Windows console.
|
||||
|
||||
---
|
||||
|
||||
## Step 1: Install PowerShell 7
|
||||
|
||||
1. Go to [PowerShell GitHub Releases](https://github.com/PowerShell/PowerShell/releases).
|
||||
2. Download the latest MSI installer for Windows (e.g., PowerShell-7.x.x-win-x64.msi).
|
||||
3. Run the installer and follow the prompts.
|
||||
4. Start PowerShell 7 by typing `pwsh` in your Start menu or terminal.
|
||||
|
||||
---
|
||||
|
||||
## Step 2: Set Up Your PowerShell Profile
|
||||
|
||||
1. Open PowerShell 7 (`pwsh`).
|
||||
2. Run:
|
||||
```
|
||||
notepad $PROFILE
|
||||
```
|
||||
If prompted, create the file.
|
||||
3. Paste the following function into the file: (replace model and uri with custom parameters)
|
||||
|
||||
```powershell
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
4. Save and close Notepad.
|
||||
5. Reload your profile by running:
|
||||
```
|
||||
. $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:
|
||||
```
|
||||
ollama Your prompt here
|
||||
```
|
||||
- Example:
|
||||
```
|
||||
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.
|
||||
|
||||
---
|
||||
Reference in New Issue
Block a user