Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ env:

jobs:
build-and-push:
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
# Fixed conditional logic to handle both push and PR events properly
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main')
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down Expand Up @@ -72,7 +75,6 @@ jobs:
with:
images: ${{ env.DOCKER_IMAGE }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
Expand All @@ -82,7 +84,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
Expand All @@ -107,25 +109,47 @@ jobs:

- name: Validate Coolify variables
env:
COOLIFY_URL: ${{env.COOLIFY_URL}}
COOLIFY_URL: ${{ env.COOLIFY_URL }}
run: |
echo "Validating that coolify_url doesn't end in '/'"
echo "$COOLIFY_URL" | grep -P '[^/]$'
echo "Validating required environment variables are set"
if [ -z "$COOLIFY_URL" ] || [ -z "${{ env.COOLIFY_RESOURCE_ID }}" ] || [ -z "${{ env.COOLIFY_API_TOKEN }}" ]; then
echo "Error: Missing required Coolify environment variables"
exit 1
fi

- name: Update source commit SHA in Coolify
uses: fjogeleit/http-request-action@v1
with:
url: ${{env.COOLIFY_URL}}/api/v1/applications/${{env.COOLIFY_RESOURCE_ID}}
url: ${{ env.COOLIFY_URL }}/api/v1/applications/${{ env.COOLIFY_RESOURCE_ID }}
method: PATCH
bearerToken: ${{env.COOLIFY_API_TOKEN}}
bearerToken: ${{ env.COOLIFY_API_TOKEN }}
data: >-
{
"git_commit_sha": "${{github.sha}}"
"git_commit_sha": "${{ github.sha }}"
}
continue-on-error: false

- name: Trigger Coolify deployment via webhook
uses: fjogeleit/http-request-action@v1
with:
url: ${{env.COOLIFY_URL}}/api/v1/deploy?uuid=${{env.COOLIFY_RESOURCE_ID}}&force=false
url: ${{ env.COOLIFY_URL }}/api/v1/deploy?uuid=${{ env.COOLIFY_RESOURCE_ID }}&force=false
method: GET
bearerToken: ${{env.COOLIFY_API_TOKEN}}
bearerToken: ${{ env.COOLIFY_API_TOKEN }}
continue-on-error: false

- name: Deployment status notification
if: success()
run: |
echo "✅ Docker image built and pushed successfully"
echo "✅ Coolify deployment triggered successfully"
echo "📦 Image: ${{ env.DOCKER_IMAGE }}"
echo "🏷️ Tags: ${{ steps.meta.outputs.tags }}"
echo "🔗 Commit SHA: ${{ github.sha }}"

- name: Failure notification
if: failure()
run: |
echo "❌ Workflow failed"
echo "🔍 Please check the logs above for details"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ Thumbs.db
*.sqlite3
media/
static/
uploads/
uploads/
reset_db.py
14 changes: 10 additions & 4 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,19 @@ async def add_conversation(self, user_id: str, message: str, response: str,
raise

async def check_repetition(self, user_id: str, new_message_embedding: List[float],
threshold: float = 0.8) -> Tuple[bool, Optional[Dict]]:
"""Check if the message is similar to previous conversations"""
current_timestamp: datetime, threshold: float = 0.8,
time_window_seconds: int = 30) -> Tuple[bool, Optional[Dict]]:
"""Check if the message is similar to previous conversations within a time window"""
try:
async with self.async_session() as session:
# Get recent conversations
time_threshold = current_timestamp - timedelta(seconds=time_window_seconds)

# Get recent conversations within the time window
query = select(Conversation).where(
Conversation.user_id == user_id
and_(
Conversation.user_id == user_id,
Conversation.timestamp >= time_threshold
)
).order_by(Conversation.timestamp.desc()).limit(10)

result = await session.execute(query)
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import os
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from datetime import datetime, timedelta
from typing import Dict, List, Optional, Tuple

import aiohttp
Expand Down Expand Up @@ -248,6 +248,7 @@ async def process_message(self, user_id: str, message: str, language: str) -> Di
is_repetition, similar_conv = await db.check_repetition(
user_id,
message_embedding.tolist(),
datetime.now(),
threshold=0.8
)
except Exception as e:
Expand Down