Skip to content

Commit 5467e3b

Browse files
committed
Added a new test mechanism for shuffle tools
1 parent 8f819c2 commit 5467e3b

File tree

8 files changed

+119
-43
lines changed

8 files changed

+119
-43
lines changed

email/1.3.0/src/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ def remove_similar_items(self, items):
427427
return result
428428

429429
def parse_eml(self, filedata, extract_attachments=False):
430+
if filedata.startswith("file_"):
431+
return self.parse_email_file(filedata, extract_attachments)
432+
430433
parsedfile = {
431434
"success": True,
432435
"filename": "email.eml",

http/1.4.0/api.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,20 @@ actions:
8888
returns:
8989
schema:
9090
type: string
91-
example: "404 NOT FOUND"
91+
example: |
92+
{
93+
"status": 200,
94+
"body": {
95+
"example": "json"
96+
"data": "json"
97+
},
98+
"url": "https://example.com",
99+
"headers": {
100+
"Content-Type": "application/json"
101+
},
102+
"cookies": {},
103+
"success": true
104+
}
92105
- name: POST
93106
description: Runs a POST request towards the specified endpoint
94107
parameters:

shuffle-ai/1.0.0/Dockerfile

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,34 @@ RUN apt install -y clang g++ make automake autoconf libtool cmake
1515
RUN apt install -y jq git curl
1616
RUN apt install -y file openssl bash tini libpng-dev aspell-en
1717
RUN apt install -y git clang g++ make automake autoconf libtool cmake
18-
RUN apt install -y autoconf-archive wget
19-
RUN mkdir -p /models
18+
RUN apt install -y autoconf-archive wget
19+
20+
# Install cuda toolkit
21+
#RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-archive-keyring.gpg
22+
#RUN dpkg -i cuda-archive-keyring.gpg
23+
#RUN rm cuda-archive-keyring.gpg
24+
#RUN apt update
25+
#RUN apt install -y cuda
26+
#RUN echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
27+
#RUN echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
28+
#RUN source ~/.bashrc
2029

2130
# Larger model
22-
RUN wget https://huggingface.co/unsloth/DeepSeek-R1-Distill-Llama-8B-GGUF/resolve/main/DeepSeek-R1-Distill-Llama-8B-Q2_K.gguf
23-
ENV MODEL_PATH="/models/DeepSeek-R1-Distill-Llama-8B-Q2_K.gguf"
31+
RUN mkdir -p /models
32+
33+
# Fails. 6 bit, 8B model.
34+
#RUN wget https://huggingface.co/RichardErkhov/meta-llama_-_Meta-Llama-3-8B-gguf/blob/main/Meta-Llama-3-8B.Q6_K.gguf?download=true -O /models/Meta-Llama-3-8B.Q6_K.gguf
35+
#ENV MODEL_PATH="/models/Meta-Llama-3-8B.Q6_K.gguf"
36+
37+
# Simple small Llama wrapper
38+
RUN wget https://huggingface.co/unsloth/DeepSeek-R1-Distill-Llama-8B-GGUF/resolve/main/DeepSeek-R1-Distill-Llama-8B-Q2_K.gguf?download=true -O /models/DeepSeek-R1-Distill-Llama.gguf
39+
# Larger one
40+
#RUN wget https://huggingface.co/unsloth/DeepSeek-R1-Distill-Llama-8B-GGUF/resolve/main/DeepSeek-R1-Distill-Llama-8B-Q8_0.gguf?download=true -O /models/DeepSeek-R1-Distill-Llama.gguf
41+
ENV MODEL_PATH="/models/DeepSeek-R1-Distill-Llama.gguf"
42+
43+
# Failing? Bad magic bytes.
44+
#RUN wget https://huggingface.co/QuantFactory/Llama-3.2-3B-GGUF/resolve/main/Llama-3.2-3B.Q2_K.gguf?download=true -O /models/Llama-3.2-3B.Q2_K.gguf
2445

25-
# https://huggingface.co/unsloth/DeepSeek-R1-Distill-Llama-8B-GGUF/resolve/main/DeepSeek-R1-Distill-Llama-8B-Q8_0.gguf
26-
#RUN wget https://huggingface.co/QuantFactory/Llama-3.2-3B-GGUF/resolve/main/Llama-3.2-3B.Q2_K.gguf?download=true -O /models/Llama-3.2-3B.Q8_0.gguf
27-
#RUN wget https://huggingface.co/QuantFactory/Llama-3.2-3B-GGUF/resolve/main/Llama-3.2-3B.Q2_K.gguf?download=true -O /models/Llama-3.2-3B.Q8_0.gguf
2846

2947
# Install all of our pip packages in a single directory that we can copy to our base image later
3048
RUN mkdir /install
@@ -33,6 +51,8 @@ WORKDIR /install
3351
# Switch back to our base image and copy in all of our built packages and source code
3452
COPY requirements.txt /requirements.txt
3553
RUN python3 -m pip install -r /requirements.txt
54+
RUN CMAKE_ARGS="-DLLAMA_CUBLAS=on" python3 -m pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir
55+
3656

3757
# Install any binary dependencies needed in our final image
3858

shuffle-ai/1.0.0/docker-compose.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

shuffle-ai/1.0.0/src/app.py

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,29 @@
1818
except Exception as e:
1919
print("Skipping pdf2image import: %s" % e)
2020

21+
2122
try:
2223
import llama_cpp
2324
except Exception as e:
2425
print("Skipping llama_cpp import: %s" % e)
2526

27+
print("LD Library: '%s'" % os.environ.get("LD_LIBRARY_PATH", ""))
28+
2629
from shuffle_sdk import AppBase
2730

2831
#model = "/models/Llama-3.2-3B.Q8_0.gguf" # Larger
2932
#model = "/models/Llama-3.2-3B.Q2_K.gguf" # Smol
3033

31-
#model = "/models/DeepSeek-R1-Distill-Llama-8B-Q8_0.gguf" # Larger 8-bit
32-
model = "/models/DeepSeek-R1-Distill-Llama-8B-Q2_K.gguf" # Smaller
34+
#model = "/models/DeepSeek-R1-Distill-Llama-8B-Q2_K.gguf" # Smaller
35+
#model = "/models/Meta-Llama-3-8B.Q6_K.gguf"
36+
model = "/models/DeepSeek-R1-Distill-Llama.gguf"
3337
if os.getenv("MODEL_PATH"):
3438
model = os.getenv("MODEL_PATH")
3539

3640
def load_llm_model(model):
41+
print("Using model path '%s'" % model)
3742
if not os.path.exists(model):
43+
print("Could not find model at path %s" % model)
3844
model_name = model.split("/")[-1]
3945
# Check $HOME/downloads/{model}
4046

@@ -54,20 +60,34 @@ def load_llm_model(model):
5460
innerllm = None
5561
gpu_layers = os.getenv("GPU_LAYERS")
5662
if gpu_layers:
63+
print("GPU Layers: %s" % gpu_layers)
64+
5765
gpu_layers = int(gpu_layers)
5866
if gpu_layers > 0:
59-
print("GPU Layers: %s" % gpu_layers)
6067
innerllm = llama_cpp.Llama(model_path=model, n_gpu_layers=gpu_layers)
6168
else:
62-
innerllm = llama_cpp.Llama(model_path=model)
69+
innerllm = llama_cpp.Llama(model_path=model, n_gpu_layers=8)
6370
else:
6471
# Check if GPU available
65-
#print("No GPU layers set.")
66-
innerllm = llama_cpp.Llama(model_path=model)
72+
print("No GPU layers set.")
73+
#innerllm = llama_cpp.Llama(model_path=model)
74+
75+
return {
76+
"success": False,
77+
"reason": "GPU layers not set",
78+
"details": "Set GPU_LAYERS environment variable to the number of GPU layers to use (e.g. 8)."
79+
}
6780

6881
return innerllm
6982

70-
llm = load_llm_model(model)
83+
try:
84+
llm = load_llm_model(model)
85+
except Exception as e:
86+
print("[ERROR] Failed to load LLM model: %s" % e)
87+
llm = {
88+
"success": False,
89+
"reason": "Failed to load LLM model %s" % model,
90+
}
7191

7292
class Tools(AppBase):
7393
__version__ = "1.0.0"
@@ -80,13 +100,35 @@ def run_llm(self, input, system_message=""):
80100
global llm
81101
global model
82102

103+
self.logger.info("[DEBUG] LD LIbrary: '%s'. If this is empty, GPU's may not work." % os.environ.get("LD_LIBRARY_PATH", ""))
104+
83105
if not system_message:
84-
system_message = "Be a friendly assistant",
106+
system_message = "Answer their question directly. Don't use HTML or Markdown",
85107

86108
self.logger.info("[DEBUG] Running LLM with model '%s'. To overwrite path, use environment variable MODEL_PATH=<path>" % model)
87109

110+
# Check if llm is a dict or not and look for success and reason in it
111+
if not llm:
112+
return {
113+
"success": False,
114+
"reason": "LLM model not loaded",
115+
"details": "Ensure the LLM model is loaded",
116+
"gpu_layers": os.getenv("GPU_LAYERS"),
117+
}
118+
119+
if isinstance(llm, dict):
120+
if "success" in llm and not llm["success"]:
121+
# List files in /model folder
122+
llm["folder"] = os.listdir("/models")
123+
llm["gpu_layers"] = os.getenv("GPU_LAYERS")
124+
return llm
125+
126+
self.logger.info("[DEBUG] Running LLM with input '%s' and system message '%s'. GPU Layers: %s" % (input, system_message, os.getenv("GPU_LAYERS")))
127+
88128
# https://github.com/abetlen/llama-cpp-python
89129
try:
130+
print("LLM: ", llm)
131+
90132
self.logger.info("[DEBUG] LLM: %s" % llm)
91133
output = llm.create_chat_completion(
92134
max_tokens=100,
@@ -117,14 +159,19 @@ def run_llm(self, input, system_message=""):
117159
parsed_output = {
118160
"success": True,
119161
"model": output["model"],
120-
"tokens": output["tokens"],
121162
"output": new_message,
122163
}
123164

165+
if "tokens" in output:
166+
parsed_output["tokens"] = output["tokens"]
167+
168+
if "usage" in output:
169+
parsed_output["tokens"] = output["usage"]
170+
124171
if not os.getenv("GPU_LAYERS"):
125172
parsed_output["debug"] = "GPU_LAYERS not set. Running on CPU. Set GPU_LAYERS to the number of GPU layers to use (e.g. 8)."
126173

127-
return output
174+
return parsed_output
128175

129176
def security_assistant(self):
130177
# Currently testing outside the Shuffle environment

shuffle-ai/1.0.0/upload.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
gcloud config set project shuffler
12

2-
gcloud run deploy shuffle-ai-1-0-0 \
3-
--region=europe-west2 \
4-
--max-instances=5 \
5-
--memory=2Gi \
6-
--set-env-vars=SHUFFLE_APP_EXPOSED_PORT=8080,SHUFFLE_SWARM_CONFIG=run,SHUFFLE_LOGS_DISABLED=true,SHUFFLE_APP_SDK_TIMEOUT=120 --source=./ \
3+
gcloud beta run deploy shuffle-ai-1-0-0 \
4+
--project=shuffler \
5+
--region=europe-west4 \
6+
--source=./ \
7+
--max-instances=1 \
8+
--concurrency=64 \
9+
--gpu 1 --gpu-type=nvidia-l4 \
10+
--cpu 4 \
11+
--memory=16Gi \
12+
--no-cpu-throttling \
13+
--set-env-vars=MODEL_PATH=/models/DeepSeek-R1-Distill-Llama.gguf,GPU_LAYERS=64,SHUFFLE_APP_EXPOSED_PORT=8080,SHUFFLE_SWARM_CONFIG=run,SHUFFLE_LOGS_DISABLED=true,SHUFFLE_APP_SDK_TIMEOUT=300,LD_LIBRARY_PATH=/usr/local/lib:/usr/local/nvidia/lib64:$LD_LIBRARY_PATH \
14+
--source=./ \
15+
716
--timeout=120s

shuffle-tools/1.2.0/src/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,9 @@ def merge_incoming_branches(self, input_type="list"):
29312931

29322932
return results
29332933

2934+
def bodyparse_test(self, body):
2935+
return body
2936+
29342937
def list_cidr_ips(self, cidr):
29352938
defaultreturn = {
29362939
"success": False,

yara/1.0.0/upload.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ gcloud run deploy yara \
2626
--region=europe-west2 \
2727
--max-instances=1 \
2828
--set-env-vars=SHUFFLE_APP_EXPOSED_PORT=8080,SHUFFLE_SWARM_CONFIG=run,SHUFFLE_LOGS_DISABLED=true --source=./ \
29+
2930
--timeout=1800s
3031

3132
# With image

0 commit comments

Comments
 (0)