How can I create a .bat file to automate my PowerShell commands for Ollama?

0
14
Asked By CuriousCat42 On

I need some guidance on creating a .bat file that will automate a few PowerShell commands for hosting my Ollama LLM server, which is set up on an external hard drive. The commands I'd like to automate are the following:

1. Change directory to the external drive: `cd h:`
2. Set an environment variable for the model path: `$env:OLLAMA_MODELS = ""`
3. Start the Ollama server: `ollama/ollama.exe serve`

I've found a template that seems useful, but I'm still encountering an error even after correctly editing the file paths. Here's the template I've been modifying:

```bat
@echo off
set DRIVE_LETTER=%~d0
set OLLAMA_MODELS=%DRIVE_LETTER%ollamamodels
echo Starting Ollama…
start "" %DRIVE_LETTER%ollamaollama.exe serve
:waitloop
rem Change the 11434 below to whatever port is actually used by ollama server
netstat -an | find "LISTENING" | find ":11434" >nul 2>&1
if errorlevel 1 (
timeout /t 1 /nobreak >nul goto waitloop
)
echo Starting AnythingLLM…
start "" %DRIVE_LETTER%anythingllmAnythingLLM.exe
```

I've ensured that my file paths are correct and that the port settings match, but whatever I'm doing is still resulting in some kind of error. Any help would be appreciated!

3 Answers

Answered By FormattingFanatic On

Your code formatting makes it a bit tricky to read—I’d recommend trying to indent it correctly. You can also use inline code formatting when posting. Highlight your code, hit tab to indent and post it again. Proper formatting will help others spot issues more easily!

Answered By TechieTinkerer On

It sounds like you may have copied the template with smart quotes. Make sure that your .bat file uses standard quotes instead of the fancy ones. If that’s the case, just replace all instances of smart quotes with regular straight quotes and see if that fixes the issue!

CuriousCat42 -

I changed the quotes, and that seems to have worked! Thanks a ton!

Answered By FrustratedDev On

I get what you're saying; it’s hard to provide help without knowing the specific error you’re getting. An error message can be caused by many factors, from simple typos to permission issues. Make sure to check those details because they can often lead to the solution!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.