Firas Ali commited on
Commit
0c91bd2
·
1 Parent(s): 5bf995f

init commit

Browse files
Files changed (3) hide show
  1. Dockerfile +34 -0
  2. app.py +17 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ollama/ollama:latest
2
+
3
+ RUN apt-get update && apt-get install -y \
4
+ python3 python3-pip tini && \
5
+ rm -rf /var/lib/apt/lists/*
6
+
7
+ ENV PYTHONUNBUFFERED=1
8
+ ENV HF_HOME=/app/.huggingface_cache
9
+ ENV OLLAMA_HOME=/app/.ollama
10
+ ENV OLLAMA_HOST=0.0.0.0:8000
11
+ ENV OLLAMA_ORIGIN=*
12
+
13
+ RUN mkdir -p /app/.huggingface_cache /app/.ollama \
14
+ && chmod -R 777 /app
15
+
16
+ RUN adduser --disabled-password --gecos "" ollama-user \
17
+ && chown -R ollama-user:ollama-user /app
18
+
19
+ WORKDIR /src
20
+
21
+ COPY requirements.txt .
22
+
23
+ RUN python3 -m pip install --no-cache-dir -r requirements.txt
24
+
25
+ USER ollama-user
26
+
27
+ COPY . .
28
+
29
+ # Expose ports
30
+ EXPOSE 8000
31
+ EXPOSE 7860
32
+
33
+ ENTRYPOINT ["/usr/bin/tini", "--"]
34
+ CMD ["sh", "-c", "ollama serve & sleep 5 && ollama pull llama3 && ollama run llama3 < /dev/null & uvicorn app:app --host 0.0.0.0 --port 7860 --workers 4"]
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request, HTTPException
2
+ from fastapi.responses import Response
3
+ import ollama
4
+
5
+ app = FastAPI()
6
+
7
+ @app.get('/')
8
+ def home():
9
+ return "Hello world"
10
+
11
+ @app.post("/chat")
12
+ async def chat(query: str):
13
+ if not query:
14
+ return {"error": "Message cannot be empty."}
15
+
16
+ response = ollama.chat(model="llama3", messages=[{"role": "user", "content": query}])
17
+ return {"response": response['message']['content']}
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ ollama