Skip to content

Commit b7f7d94

Browse files
committed
Rebuild with run_llm working
1 parent 6c890fa commit b7f7d94

File tree

3 files changed

+76
-36
lines changed

3 files changed

+76
-36
lines changed

shuffle-ai/1.0.0/Dockerfile

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
FROM python:3.10-slim
22

3+
### Install Tesseract
4+
ENV SHELL=/bin/bash
5+
ENV CC /usr/bin/clang
6+
ENV CXX /usr/bin/clang++
7+
ENV LANG=C.UTF-8
8+
ENV TESSDATA_PREFIX=/usr/local/share/tessdata
9+
310
# Install all build tools needed for our pip installs
411
RUN apt update
512
RUN apt install -y clang g++ make automake autoconf libtool cmake
613

14+
## Install the same packages with apt as with apk, but ensure they exist in apt
15+
RUN apt install -y jq git curl
16+
RUN apt install -y file openssl bash tini libpng-dev aspell-en
17+
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
20+
RUN wget https://huggingface.co/QuantFactory/Llama-3.2-3B-GGUF/resolve/main/Llama-3.2-3B.Q8_0.gguf?download=true -O /models/Llama-3.2-3B.Q8_0.gguf
21+
722
# Install all of our pip packages in a single directory that we can copy to our base image later
823
RUN mkdir /install
924
WORKDIR /install
1025

1126
# Switch back to our base image and copy in all of our built packages and source code
12-
#COPY --from=builder /install /usr/local
13-
COPY src /app
1427
COPY requirements.txt /requirements.txt
1528
RUN python3 -m pip install -r /requirements.txt
1629

1730
# Install any binary dependencies needed in our final image
18-
# RUN apk --no-cache add --update my_binary_dependency
19-
#RUN apk --no-cache add jq git curl
20-
RUN apt install -y jq git curl
2131

22-
ENV SHELL=/bin/bash
23-
24-
### Install Tesseract
25-
ENV CC /usr/bin/clang
26-
ENV CXX /usr/bin/clang++
27-
ENV LANG=C.UTF-8
28-
ENV TESSDATA_PREFIX=/usr/local/share/tessdata
2932

3033
# Dev tools
3134
WORKDIR /tmp
3235
#RUN apk update
3336
#RUN apk upgrade
3437

35-
## Install the same packages with apt as with apk, but ensure they exist in apt
36-
RUN apt install -y file openssl bash tini libpng-dev aspell-en
37-
RUN apt install -y git clang g++ make automake autoconf libtool cmake
38-
RUN apt install -y autoconf-archive wget
3938

4039
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h
4140

@@ -56,20 +55,26 @@ RUN git clone --depth 1 https://github.com/tesseract-ocr/tesseract.git
5655

5756
#RUN curl -fsSL https://ollama.com/install.sh | sh
5857
# Install to /usr/local
59-
RUN wget https://ollama.com/install.sh -O /usr/local/bin/ollama-install
60-
RUN chmod +x /usr/local/bin/ollama-install
61-
RUN ls /usr/local/bin
62-
RUN sh /usr/local/bin/ollama-install
58+
#RUN wget https://ollama.com/install.sh -O /usr/local/bin/ollama-install
59+
#RUN chmod +x /usr/local/bin/ollama-install
60+
#RUN sh /usr/local/bin/ollama-install
61+
#
62+
#RUN ls -alh /usr/bin
63+
#RUN ollama serve & sleep 2 && ollama pull nezahatkorkmaz/deepseek-v3
64+
#CMD ["sh", "-c", "ollama serve & sleep 2 && python app.py --log-level DEBUG"]
6365

64-
RUN ls -alh /usr/bin
65-
RUN which ollama
66+
#RUN wget https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q4_K_M.gguf
67+
RUN python3 -m pip install ctransformers --no-binary ctransformers
6668

67-
#RUN /usr/local/bin/ollama pull llama3.2
68-
RUN ollama serve & sleep 2 && ollama pull nezahatkorkmaz/deepseek-v3
69+
# Finally, lets run our app!
70+
ENV GIN_MODE=release
71+
ENV SHUFFLE_APP_SDK_TIMEOUT=300
72+
#ENV LD_LIBRARY_PATH=/usr/local/lib/python3.10/site-packages/ctransformers/lib/basic/libctransformers.so
73+
#RUN chmod 755 /usr/local/lib/python3.10/site-packages/ctransformers/lib/basic/libctransformers.so
6974

70-
#RUN rm /usr/local/bin/ollama
71-
#RUN cd tesseract && ./autogen.sh && ./configure --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl && make && make install && cd /tmp/src
75+
#RUN apt install -y libffi-dev
7276

73-
# Finally, lets run our app!
77+
78+
COPY src /app
7479
WORKDIR /app
7580
CMD ["python", "app.py", "--log-level", "DEBUG"]

shuffle-ai/1.0.0/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ pytesseract
33
pdf2image
44
pypdf2
55
requests
6-
ollama
76

7+
llama-cpp-python

shuffle-ai/1.0.0/src/app.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import json
23
import tempfile
34
import requests
@@ -18,9 +19,9 @@
1819
print("Skipping pdf2image import: %s" % e)
1920

2021
try:
21-
import ollama
22+
import llama_cpp
2223
except Exception as e:
23-
print("Skipping ollama import: %s" % e)
24+
print("Skipping llama_cpp import: %s" % e)
2425

2526
from shuffle_sdk import AppBase
2627

@@ -32,14 +33,48 @@ def __init__(self, redis, logger, console_logger=None):
3233
super().__init__(redis, logger, console_logger)
3334

3435
#def run_llm(self, question, model="llama3.2"):
35-
def run_llm(self, question, model="deepseek-v3"):
36-
response = ollama.chat(model=model, messages=[
37-
{
38-
"role": "user", "content": question,
36+
#def run_llm(self, question, model="deepseek-v3"):
37+
def run_llm(self, question, model="/models/Llama-3.2-3B.Q8_0.gguf"):
38+
self.logger.info("[DEBUG] Running LLM with model '%s'" % model)
39+
40+
if not os.path.exists(model):
41+
return {
42+
"success": False,
43+
"reason": "Model not found at path %s" % model,
44+
"details": "Ensure the model path is correct"
3945
}
40-
])
4146

42-
return response["message"]["content"]
47+
llm = llama_cpp.Llama(model_path=model)
48+
49+
# https://github.com/abetlen/llama-cpp-python
50+
output = llm.create_chat_completion(
51+
messages = [
52+
{"role": "system", "content": "You are an assistant who outputs in JSON format.."},
53+
{
54+
"role": "user",
55+
"content": question,
56+
}
57+
]
58+
)
59+
60+
return output
61+
62+
63+
#model = ctransformers.AutoModelForCausalLM.from_pretrained(
64+
# model_path_or_repo_id=model,
65+
# #model_type="deepseek-v3"
66+
#)
67+
68+
#resp = model(full_question)
69+
#return resp
70+
71+
#response = ollama.chat(model=model, messages=[
72+
# {
73+
# "role": "user", "content": question,
74+
# }
75+
#])
76+
77+
#return response["message"]["content"]
4378

4479
def security_assistant(self):
4580
# Currently testing outside the Shuffle environment

0 commit comments

Comments
 (0)