Skip to content

Commit

Permalink
Changed runtimes to run ollama on app start
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanleung committed Aug 15, 2024
1 parent e19ff33 commit 8a06387
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build_assets/macOS/README_MACOS_DEV_BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ For Intel (x86_64)

5. Build App for Local Installation
```shell
$ pyinstaller --windowed --add-data --name="MORagents" --icon="images/moragents.icns" --osx-entitlements-file "build_assets/macOS/MORagents.entitlements" main.py
$ pyinstaller --windowed --name="MORagents" --icon="images/moragents.icns" --osx-entitlements-file "build_assets/macOS/MORagents.entitlements" main.py
```
# If you have issues, try
python -m PyInstaller --windowed --runtime-hook runtime_hook.py --name="MORagents" --icon="moragents.icns" main.py
Expand Down
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import logging
import webbrowser

from runtime_setup_macos import docker_setup as docker_setup_macos
from runtime_setup_windows import docker_setup as docker_setup_windows
from runtime_setup_macos import main as macos_setup
from runtime_setup_windows import main as windows_setup
from utils.logger_config import setup_logger
from utils.host_utils import get_os_and_arch

Expand All @@ -17,9 +17,9 @@
os_name, arch = get_os_and_arch()

if os_name == "macOS":
docker_setup_macos()
macos_setup()
elif os_name == "Windows":
docker_setup_windows()
windows_setup()
elif os_name == "Linux":
raise RuntimeError(
f"MORagents needs Linux support! Would you like to help?\n"
Expand Down
20 changes: 19 additions & 1 deletion runtime_setup_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ def pull_docker_images(docker_path):
logger.error(f"Failed to pull image {image}: {e}")
raise

def start_ollama_server():
ollama_path = '/usr/local/bin/ollama'

try:
# Start Ollama server
logger.info("Starting Ollama server...")
subprocess.Popen([ollama_path, "serve"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
logger.info("Ollama server started successfully.")
except Exception as e:
logger.info("Failed to start Ollama server.")
logger.error(f"Failed to start Ollama server: {e}")

def docker_setup():
docker_path = get_docker_path()
logger.info(f"Docker path: {docker_path}")
Expand Down Expand Up @@ -141,5 +153,11 @@ def docker_setup():
AgentDockerConfig.get_current_image_names()[0] # nginx image
], check=True)

def main():
# main() called every time the app is opened (from main.py). Put all app open code here.
logger.info("Starting app...")
start_ollama_server()
docker_setup()

if __name__ == "__main__":
docker_setup()
main()
19 changes: 19 additions & 0 deletions runtime_setup_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ def pull_docker_images():
logger.error(f"Failed to pull image {image_name}: {e}")
raise

def start_ollama_server():
ollama_path = "ollama"

try:
print(f"Attempting to start Ollama server using: {ollama_path}")
subprocess.Popen([ollama_path, "serve"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
creationflags=subprocess.CREATE_NO_WINDOW)
print("Ollama server started successfully.")
except Exception as e:
print(f"Failed to start Ollama server: {e}")


def docker_setup():
if not check_docker_installed():
print("Docker is not installed. Please install Docker Desktop.")
Expand Down Expand Up @@ -139,5 +153,10 @@ def docker_setup():
AgentDockerConfig.get_current_image_names()[0] # nginx image
], check=True)

def main():
# main() called every time the app is opened (from main.py). Put all app open code here.
start_ollama_server()
docker_setup()

if __name__ == "__main__":
docker_setup()

0 comments on commit 8a06387

Please sign in to comment.