Spaces:
Running
Running
Commit
·
5d0417f
1
Parent(s):
333660b
change to GROQ
Browse files- Dockerfile +21 -21
- app.py +11 -6
- requirements.txt +2 -1
- start.sh +19 -19
Dockerfile
CHANGED
|
@@ -3,31 +3,31 @@
|
|
| 3 |
|
| 4 |
FROM python:3.11-slim
|
| 5 |
|
| 6 |
-
RUN apt-get update && apt-get install -y curl && \
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
RUN useradd -m -u 1000 user
|
| 11 |
-
USER user
|
| 12 |
-
ENV HOME=/home/user \
|
| 13 |
-
|
| 14 |
|
| 15 |
-
# Création des répertoires nécessaires
|
| 16 |
-
RUN mkdir -p $HOME/docker_ollama $HOME/logs
|
| 17 |
-
WORKDIR $HOME/docker_ollama
|
| 18 |
|
| 19 |
-
COPY --chown=user requirements.txt .
|
| 20 |
-
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 21 |
-
COPY --chown=user . .
|
| 22 |
-
RUN chmod +x start.sh
|
| 23 |
-
EXPOSE 7860 11434
|
| 24 |
|
| 25 |
-
CMD ["./start.sh"]
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 3 |
|
| 4 |
FROM python:3.11-slim
|
| 5 |
|
| 6 |
+
# RUN apt-get update && apt-get install -y curl && \
|
| 7 |
+
# curl -fsSL https://ollama.ai/install.sh | sh && \
|
| 8 |
+
# apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 9 |
|
| 10 |
+
# RUN useradd -m -u 1000 user
|
| 11 |
+
# USER user
|
| 12 |
+
# ENV HOME=/home/user \
|
| 13 |
+
# PATH="/home/user/.local/bin:$PATH"
|
| 14 |
|
| 15 |
+
# # Création des répertoires nécessaires
|
| 16 |
+
# RUN mkdir -p $HOME/docker_ollama $HOME/logs
|
| 17 |
+
# WORKDIR $HOME/docker_ollama
|
| 18 |
|
| 19 |
+
# COPY --chown=user requirements.txt .
|
| 20 |
+
# RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 21 |
+
# COPY --chown=user . .
|
| 22 |
+
# RUN chmod +x start.sh
|
| 23 |
+
# EXPOSE 7860 11434
|
| 24 |
|
| 25 |
+
# CMD ["./start.sh"]
|
| 26 |
|
| 27 |
+
WORKDIR /app
|
| 28 |
|
| 29 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 30 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 31 |
|
| 32 |
+
COPY --chown=user . /app
|
| 33 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -11,12 +11,15 @@ from langchain_core.messages import SystemMessage, HumanMessage, AnyMessage
|
|
| 11 |
from langchain_ollama import ChatOllama
|
| 12 |
from langgraph.pregel import RetryPolicy
|
| 13 |
import json
|
| 14 |
-
import pandas as pd
|
| 15 |
from google.oauth2 import service_account
|
| 16 |
import os
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
sheet_url =
|
| 19 |
GOOGLESHEETS_CREDENTIALS = os.getenv("GOOGLESHEETS_CREDENTIALS")
|
|
|
|
|
|
|
| 20 |
|
| 21 |
class TransactionParser(BaseModel):
|
| 22 |
"""This Pydantic class is used to parse the transaction message."""
|
|
@@ -35,8 +38,8 @@ class Agent:
|
|
| 35 |
def __init__(self, model, system=""):
|
| 36 |
self.system = system
|
| 37 |
graph = StateGraph(AgentState)
|
| 38 |
-
graph.add_node("classify_txn_type", self.classify_txn_type)
|
| 39 |
-
graph.add_node("parse_message", self.parse_message)
|
| 40 |
graph.add_node("write_message", self.write_message)
|
| 41 |
graph.add_conditional_edges(
|
| 42 |
"classify_txn_type",
|
|
@@ -119,14 +122,16 @@ def greetings():
|
|
| 119 |
@app.post("/write_message")
|
| 120 |
def write_message(data: dict):
|
| 121 |
message = data['message']
|
| 122 |
-
model =
|
|
|
|
| 123 |
transaction_bot = Agent(model, system=prompt)
|
| 124 |
transaction_bot.graph.invoke({"messages": [message]})
|
| 125 |
return {"message": "Transaction completed successfully"}
|
| 126 |
|
| 127 |
@app.get("/ask")
|
| 128 |
def ask(prompt: str):
|
| 129 |
-
model =
|
|
|
|
| 130 |
return model.invoke(prompt)
|
| 131 |
|
| 132 |
if __name__ == "__main__":
|
|
|
|
| 11 |
from langchain_ollama import ChatOllama
|
| 12 |
from langgraph.pregel import RetryPolicy
|
| 13 |
import json
|
|
|
|
| 14 |
from google.oauth2 import service_account
|
| 15 |
import os
|
| 16 |
+
from langchain_groq import ChatGroq
|
| 17 |
+
import groq
|
| 18 |
|
| 19 |
+
sheet_url = os.getenv("SHEET_URL")
|
| 20 |
GOOGLESHEETS_CREDENTIALS = os.getenv("GOOGLESHEETS_CREDENTIALS")
|
| 21 |
+
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
| 22 |
+
MODEL = "meta-llama/llama-4-scout-17b-16e-instruct"
|
| 23 |
|
| 24 |
class TransactionParser(BaseModel):
|
| 25 |
"""This Pydantic class is used to parse the transaction message."""
|
|
|
|
| 38 |
def __init__(self, model, system=""):
|
| 39 |
self.system = system
|
| 40 |
graph = StateGraph(AgentState)
|
| 41 |
+
graph.add_node("classify_txn_type", self.classify_txn_type, retry=RetryPolicy(retry_on=[groq.BadRequestError], max_attempts=2))
|
| 42 |
+
graph.add_node("parse_message", self.parse_message, retry=RetryPolicy(retry_on=[groq.BadRequestError], max_attempts=2))
|
| 43 |
graph.add_node("write_message", self.write_message)
|
| 44 |
graph.add_conditional_edges(
|
| 45 |
"classify_txn_type",
|
|
|
|
| 122 |
@app.post("/write_message")
|
| 123 |
def write_message(data: dict):
|
| 124 |
message = data['message']
|
| 125 |
+
model = ChatGroq(temperature=1, groq_api_key=GROQ_API_KEY, model_name=MODEL)
|
| 126 |
+
# model = ChatOllama(model="gemma3:1b", temperature=1)
|
| 127 |
transaction_bot = Agent(model, system=prompt)
|
| 128 |
transaction_bot.graph.invoke({"messages": [message]})
|
| 129 |
return {"message": "Transaction completed successfully"}
|
| 130 |
|
| 131 |
@app.get("/ask")
|
| 132 |
def ask(prompt: str):
|
| 133 |
+
model = ChatGroq(temperature=1, groq_api_key=GROQ_API_KEY, model_name=MODEL)
|
| 134 |
+
# model = ChatOllama(model="gemma3:1b", temperature=1)
|
| 135 |
return model.invoke(prompt)
|
| 136 |
|
| 137 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
|
@@ -3,4 +3,5 @@ uvicorn[standard]
|
|
| 3 |
langchain-ollama
|
| 4 |
langgraph
|
| 5 |
pygsheets
|
| 6 |
-
pandas
|
|
|
|
|
|
| 3 |
langchain-ollama
|
| 4 |
langgraph
|
| 5 |
pygsheets
|
| 6 |
+
pandas
|
| 7 |
+
langchain-groq
|
start.sh
CHANGED
|
@@ -9,27 +9,27 @@ export OMP_NUM_THREADS=2
|
|
| 9 |
export MKL_NUM_THREADS=2
|
| 10 |
export CUDA_VISIBLE_DEVICES=-1
|
| 11 |
|
| 12 |
-
# Start Ollama in the background
|
| 13 |
-
ollama serve &
|
| 14 |
|
| 15 |
-
# Pull the model if not already present
|
| 16 |
-
echo "gemma3:1b will be download"
|
| 17 |
-
if ! ollama list | grep -q "gemma3:1b"; then
|
| 18 |
-
|
| 19 |
-
fi
|
| 20 |
|
| 21 |
-
# Wait for Ollama to start up
|
| 22 |
-
max_attempts=30
|
| 23 |
-
attempt=0
|
| 24 |
-
while ! curl -s http://localhost:11434/api/tags >/dev/null; do
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
done
|
| 32 |
|
| 33 |
-
echo "Ollama is Ready - gemma3:1b is Loaded"
|
| 34 |
|
| 35 |
python app.py
|
|
|
|
| 9 |
export MKL_NUM_THREADS=2
|
| 10 |
export CUDA_VISIBLE_DEVICES=-1
|
| 11 |
|
| 12 |
+
# # Start Ollama in the background
|
| 13 |
+
# ollama serve &
|
| 14 |
|
| 15 |
+
# # Pull the model if not already present
|
| 16 |
+
# echo "gemma3:1b will be download"
|
| 17 |
+
# if ! ollama list | grep -q "gemma3:1b"; then
|
| 18 |
+
# ollama pull gemma3:1b
|
| 19 |
+
# fi
|
| 20 |
|
| 21 |
+
# # Wait for Ollama to start up
|
| 22 |
+
# max_attempts=30
|
| 23 |
+
# attempt=0
|
| 24 |
+
# while ! curl -s http://localhost:11434/api/tags >/dev/null; do
|
| 25 |
+
# sleep 1
|
| 26 |
+
# attempt=$((attempt + 1))
|
| 27 |
+
# if [ $attempt -eq $max_attempts ]; then
|
| 28 |
+
# echo "Ollama failed to start within 30 seconds. Exiting."
|
| 29 |
+
# exit 1
|
| 30 |
+
# fi
|
| 31 |
+
# done
|
| 32 |
|
| 33 |
+
# echo "Ollama is Ready - gemma3:1b is Loaded"
|
| 34 |
|
| 35 |
python app.py
|