diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..33f4bd9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +.git +.gitignore +README.md +.env +.DS_Store +chromadb/ +chroma_db/ +raggr-frontend/node_modules/ +__pycache__/ +*.pyc +*.pyo +*.pyd +.Python +.venv/ +venv/ +.pytest_cache/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9176f9c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM python:3.13-slim + +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Copy dependency files +COPY pyproject.toml ./ + +# Install Python dependencies +RUN pip install --no-cache-dir -e . + +# Copy application code +COPY *.py ./ + +# Create ChromaDB directory +RUN mkdir -p /app/chromadb + +# Expose port +EXPOSE 8080 + +# Set environment variables +ENV PYTHONPATH=/app +ENV CHROMADB_PATH=/app/chromadb + +# Run the Flask application +CMD ["python", "app.py"] \ No newline at end of file diff --git a/app.py b/app.py index 9fe390b..211729e 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,6 @@ import os -from flask import Flask, request, jsonify, render_template +from flask import Flask, request, jsonify, render_template, send_from_directory from main import consult_simba_oracle @@ -30,4 +30,8 @@ def query(): def webhook(): data = request.get_json() print(data) + return jsonify({"status": "received"}) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8080, debug=True) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cd05d9a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3.8' + +services: + raggr: + build: . + ports: + - "8080:8080" + environment: + - PAPERLESS_TOKEN=${PAPERLESS_TOKEN} + - BASE_URL=${BASE_URL} + - OLLAMA_URL=${OLLAMA_URL:-http://ollama:11434} + - CHROMADB_PATH=/app/chromadb + - OPENAI_API_KEY=${OPENAI_API_KEY} + volumes: + - chromadb_data:/app/chromadb + depends_on: + - ollama + networks: + - raggr-network + + ollama: + image: ollama/ollama:latest + ports: + - "11434:11434" + volumes: + - ollama_data:/root/.ollama + networks: + - raggr-network + +volumes: + chromadb_data: + ollama_data: + +networks: + raggr-network: + driver: bridge \ No newline at end of file diff --git a/main.py b/main.py index 060bdb2..1070113 100644 --- a/main.py +++ b/main.py @@ -132,9 +132,12 @@ def consult_oracle(input: str, collection): # model="gemma3n:e4b", # prompt=f"You are a helpful assistant that understandings veterinary terms. Using the following data, help answer the user's query by providing as many details as possible. Using this data: {results}. Respond to this prompt: {input}", # ) - response = openai_client.responses.create( + response = openai_client.chat.completions.create( model="gpt-4o-mini", - input=f"You are a helpful assistant that understandings veterinary terms. Using the following data, help answer the user's query by providing as many details as possible. Using this data: {results}. Respond to this prompt: {input}", + messages=[ + {"role": "system", "content": "You are a helpful assistant that understands veterinary terms."}, + {"role": "user", "content": f"Using the following data, help answer the user's query by providing as many details as possible. Using this data: {results}. Respond to this prompt: {input}"} + ] ) llm_end = time.time() print(f"LLM generation took {llm_end - llm_start:.2f} seconds") @@ -142,7 +145,7 @@ def consult_oracle(input: str, collection): total_time = time.time() - start_time print(f"Total consult_oracle execution took {total_time:.2f} seconds") - return response.output_text + return response.choices[0].message.content def paperless_workflow(input):