From 73f0234cabdffd3d3b6d6d01473299409a1fb5cc Mon Sep 17 00:00:00 2001 From: Christian U Date: Mon, 26 Feb 2024 23:07:56 +0100 Subject: [PATCH 1/3] Master (#1) * ollama image * add webui --------- Co-authored-by: Chris --- .gitignore | 3 +++ compose.yaml | 31 ++++++++++++++++++++++ source/bot.py | 10 +++++++ source/requirements.txt | 1 + source/wol.py | 59 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 .gitignore create mode 100644 compose.yaml create mode 100644 source/bot.py create mode 100644 source/requirements.txt create mode 100644 source/wol.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b1eb2ad --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.venv +llm-data/* +webgui/* \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..e293224 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,31 @@ +services: + ollama: + image: docker.io/ollama/ollama + container_name: llm + volumes: + - ./llm-data:/root/.ollama + ports: ["11434:11434"] + + ollama-webui: + image: ghcr.io/open-webui/open-webui:main + container_name: ollama-webui + ports: ["10200:8080"] + volumes: + - ./webui:/app/backend/data + depends_on: + - ollama + restart: always + environment: + - 'OLLAMA_API_BASE_URL=http://ollama:11434/api' + restart: unless-stopped + #app: + # build: + # context: source + # container_name: matrix_llm_bot + # restart: always + # env_file: + # - .env + # volumes: + # - ./source:/app + # dns: + # - 192.168.177.105 diff --git a/source/bot.py b/source/bot.py new file mode 100644 index 0000000..c5744d0 --- /dev/null +++ b/source/bot.py @@ -0,0 +1,10 @@ +import ollama +ollama.pull('llama2') +ollama.list() +response = ollama.chat(model='llama2', messages=[ + { + 'role': 'user', + 'content': 'Why is the sky blue?', + }, +]) +print(response['message']['content']) \ No newline at end of file diff --git a/source/requirements.txt b/source/requirements.txt new file mode 100644 index 0000000..9585b03 --- /dev/null +++ b/source/requirements.txt @@ -0,0 +1 @@ +ollama \ No newline at end of file diff --git a/source/wol.py b/source/wol.py new file mode 100644 index 0000000..fb05c50 --- /dev/null +++ b/source/wol.py @@ -0,0 +1,59 @@ +import sys, struct, socket + +# Configuration variables +broadcast = ['192.168.177.255'] +wol_port = 9 + + +def WakeOnLan(ethernet_address): + + # Construct 6 byte hardware address + add_oct = ethernet_address.split(':') + if len(add_oct) != 6: + print("\n*** Illegal MAC address\n") + print("MAC should be written as 00:11:22:33:44:55\n") + return + hwa = struct.pack('BBBBBB', int(add_oct[0],16), + int(add_oct[1],16), + int(add_oct[2],16), + int(add_oct[3],16), + int(add_oct[4],16), + int(add_oct[5],16)) + + # Build magic packet + + msg = b'\xff' * 6 + hwa * 16 + + # Send packet to broadcast address using UDP port 9 + + soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + soc.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1) + for i in broadcast: + soc.sendto(msg,(i,wol_port)) + soc.close() + +def wol(*macs): + if len(macs) == 0: + print("\n*** No computer given to power up\n") + print("Use: 'wol computername' or 'wol 00:11:22:33:44:55'") + else: + for i in macs: + if i[0] != '/': + if ":" in i: + # Wake up using MAC address + WakeOnLan(i) + else: + # Wake up known computers + if i in known_computers: + WakeOnLan(known_computers[i]) + else: + print("\n*** Unknown computer " + i + "\n") + quit() + + if len(macs) == 2: + print("\nDone! The computer should be up and running in a short while.") + else: + print("\nDone! The computers should be up and running in a short while.") + print + +wol('74:56:3c:92:c4:cc') \ No newline at end of file From c036972844746e4a28bf6f9172a63cb3d703dba3 Mon Sep 17 00:00:00 2001 From: Christian U Date: Tue, 27 Feb 2024 04:33:43 +0100 Subject: [PATCH 2/3] Create python-app.yml --- .github/workflows/python-app.yml | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..f3d4fca --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From 0f5d2cb6859034da2e4e90258026b7ffffbac113 Mon Sep 17 00:00:00 2001 From: Christian U Date: Tue, 27 Feb 2024 05:44:20 +0100 Subject: [PATCH 3/3] Create docker-image.yml --- .github/workflows/docker-image.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..d657a63 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,18 @@ +name: Docker Image CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)