diff --git a/groq.sh b/groq.sh new file mode 100644 index 00000000..ce1ac7f3 --- /dev/null +++ b/groq.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Determine the script's base directory +BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Load environment variables from .env file +if [ -f "$BASEDIR/.env" ]; then + source "$BASEDIR/.env" +fi + +# Ensure GROQ_API_KEY is set +if [ -z "$GROQ_API_KEY" ]; then + echo "Error: GROQ_API_KEY is not set. Please define it in $BASEDIR/.env" + exit 1 +fi + +# Validate input argument +if [ -z "$1" ] || [ ! -f "$BASEDIR/rpc/$1.yml" ]; then + echo "Error: Either no argument provided or $BASEDIR/rpc/$1.yml does not exist." + exit 1 +fi + +# Build the container +docker build -t rpc_sync_checker "$BASEDIR/groq" + +# Run logs.sh and feed logs into the sync checker container +"$BASEDIR/logs.sh" "$1" | docker run --rm -i -e GROQ_API_KEY="$GROQ_API_KEY" rpc_sync_checker diff --git a/groq/Dockerfile b/groq/Dockerfile new file mode 100644 index 00000000..ca66e307 --- /dev/null +++ b/groq/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.11 + +WORKDIR /app + +COPY rpc_sync_checker.py /app/ +RUN pip install groq + +CMD ["python", "/app/rpc_sync_checker.py"] \ No newline at end of file diff --git a/groq/rpc_sync_checker.py b/groq/rpc_sync_checker.py new file mode 100644 index 00000000..859928ed --- /dev/null +++ b/groq/rpc_sync_checker.py @@ -0,0 +1,21 @@ +import os +import sys +from groq import Groq + +def check_sync_progress(logs): + client = Groq(api_key=os.environ.get("GROQ_API_KEY")) + + response = client.chat.completions.create( + messages=[ + {"role": "system", "content": "You are an assistant trained to analyze blockchain RPC logs."}, + {"role": "user", "content": f"Based on the following logs, is the RPC node progressing in its sync? Answer only '0' for yes and '1' for no.\n\n{logs}"} + ], + model="llama-3.3-70b-versatile", + ) + + return response.choices[0].message.content.strip() + +if __name__ == "__main__": + logs = sys.stdin.read() # Read input from STDIN + result = check_sync_progress(logs) + print(result)