Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Example to use Ollama Manager #6

Open
igorbenav opened this issue Nov 1, 2024 · 0 comments
Open

Update Example to use Ollama Manager #6

igorbenav opened this issue Nov 1, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@igorbenav
Copy link
Owner

Here in the example, instead of defining this function:

import subprocess
import time
import requests
import logging

logging.basicConfig(level=logging.INFO)

def start_ollama_server(timeout: int = 30, check_interval: float = 1.0):
    """
    Start the Ollama server and wait for it to be ready.
    """
    logging.info("Starting Ollama server...")

    try:
        process = subprocess.Popen(
            ['ollama', 'serve'],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True
        )
    except subprocess.SubprocessError as e:
        logging.error(f"Failed to start Ollama process: {e}")
        raise

    start_time = time.time()
    while time.time() - start_time < timeout:
        try:
            response = requests.get('http://localhost:11434', timeout=5)
            if response.status_code == 200:
                logging.info("Ollama server is ready.")
                return process
        except requests.ConnectionError:
            pass
        except requests.RequestException as e:
            logging.error(f"Unexpected error when checking Ollama server: {e}")
            process.terminate()
            raise

        if process.poll() is not None:
            stdout, stderr = process.communicate()
            logging.error(f"Ollama process terminated unexpectedly. stdout: {stdout}, stderr: {stderr}")
            raise subprocess.SubprocessError("Ollama process terminated unexpectedly")

        time.sleep(check_interval)

    process.terminate()
    raise TimeoutError(f"Ollama server did not start within {timeout} seconds")

We should just use the Ollama Manager.

Plus, this should also be updated in other parts of the example and the github repo.

@igorbenav igorbenav added documentation Improvements or additions to documentation good first issue Good for newcomers labels Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant