diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..ffa9ead --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +OPENAI_API_KEY=123456ABCDEF \ No newline at end of file diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml new file mode 100644 index 0000000..0b54460 --- /dev/null +++ b/.gitea/workflows/main.yml @@ -0,0 +1,32 @@ +name: Build and Push AI Image + +on: + push: + branches: + - master + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker smoke test + run: docker ps -a + + - name: Docker login + run: | + echo "${{ secrets.REGISTRY_PASSWORD }}" \ + | docker login git.petyi.eu \ + -u "${{ secrets.REGISTRY_USER }}" \ + --password-stdin + + - name: Docker build + run: | + docker build -t git.petyi.eu/szakdolgozat/ai:latest . + + - name: Docker push + run: | + docker push git.petyi.eu/szakdolgozat/ai:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b8316be --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM python:3.11-slim + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y --no-install-recommends \ + curl \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY requirements.txt /app/requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +COPY ai.py /app/ai.py + +CMD ["python", "ai.py"] diff --git a/README.md b/README.md index e75de15..b4aa19b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # AI -Az AI Engine, ami segít eldönteni, hogy hogyan változzon a K8S konfigurációja \ No newline at end of file +Az AI Engine, ami segít eldönteni, hogy hogyan változzon a K8S konfigurációja + +## .ENV + +A helyes működéshez le kell másolni a `.env.example` filet `.env` névre és az api kulcsot a megfelelő helyre bemásolni. \ No newline at end of file diff --git a/ai.py b/ai.py new file mode 100644 index 0000000..f7762c6 --- /dev/null +++ b/ai.py @@ -0,0 +1,34 @@ +import os +import sys +from openai import OpenAI + + +def main(): + api_key = os.getenv("OPENAI_API_KEY") + if not api_key: + print("ERROR: OPENAI_API_KEY environment variable is not set.", file=sys.stderr) + sys.exit(1) + + # Az új OpenAI kliens automatikusan az OPENAI_API_KEY env-ből dolgozik + client = OpenAI() + + prompt = "Please respond with exactly the string: hello world" + + try: + response = client.responses.create( + model="gpt-4.1-mini", + input=prompt, + ) + + # Egyszerű, „naivan” kiszedjük a szöveget + msg = response.output[0].content[0].text + + print("Model response:", msg) + + except Exception as e: + print(f"ERROR while calling OpenAI API: {e}", file=sys.stderr) + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..282e1c3 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,8 @@ +version: "3.9" + +services: + ai-helper: + build: . + container_name: ai-helper + environment: + OPENAI_API_KEY: "${OPENAI_API_KEY}" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..34a32f5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +openai>=1.52.0 +PyYAML>=6.0.2 +requests>=2.32.3