Skip to content

Commit 6cde831

Browse files
Merge pull request #36 from DefangLabs/jordan/devex
Developer experience improvements
2 parents 9cab00a + 545e3b3 commit 6cde831

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__pycache__
2+
sentence-transformers
13
myenv/
24
.tmp/*
35
!.tmp/prebuild.sh

app/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ COPY . /app
3939
# Make the prebuild.sh script executable
4040
RUN chmod +x .tmp/prebuild.sh
4141

42-
# Expose port 5000 for the Flask application
43-
EXPOSE 5000
42+
# Expose port 5050 for the Flask application
43+
EXPOSE 5050
4444

4545
# Define environment variable for Flask
4646
ENV FLASK_APP=app.py
4747

4848
# Run the application using uWSGI
49-
CMD ["uwsgi", "--http", "0.0.0.0:5000", "--wsgi-file", "app.py", "--callable", "app", "--processes", "4", "--threads", "2"]
49+
CMD ["uwsgi", "--http", "0.0.0.0:5050", "--wsgi-file", "app.py", "--callable", "app", "--processes", "4", "--threads", "2"]

app/app.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def ask():
4040

4141
if not query:
4242
return jsonify({"error": "No query provided"}), 400
43-
43+
4444
# For analytics tracking, generates an anonymous id and uses it for the session
4545
if 'anonymous_id' not in session:
4646
session['anonymous_id'] = str(uuid.uuid4())
@@ -59,12 +59,13 @@ def generate():
5959
if not full_response:
6060
full_response = "No response generated"
6161

62-
# Track the query and response
63-
analytics.track(
64-
anonymous_id=anonymous_id,
65-
event='Chatbot Question submitted',
66-
properties={'query': query, 'response': full_response, 'source': 'Ask Defang'}
67-
)
62+
if analytics.write_key:
63+
# Track the query and response
64+
analytics.track(
65+
anonymous_id=anonymous_id,
66+
event='Chatbot Question submitted',
67+
properties={'query': query, 'response': full_response, 'source': 'Ask Defang'}
68+
)
6869

6970
return Response(stream_with_context(generate()), content_type='text/markdown')
7071

@@ -98,4 +99,4 @@ def trigger_rebuild():
9899
return jsonify({"error": "Internal Server Error"}), 500
99100

100101
if __name__ == '__main__':
101-
app.run(host='0.0.0.0', port=5000)
102+
app.run(host='0.0.0.0', port=5050)

app/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Werkzeug==2.0.3
44
scikit-learn==0.24.2
55
segment-analytics-python==2.3.3
66
numpy==1.22.0
7-
sentence-transformers==2.1.0
7+
sentence-transformers==2.2.1
88
torch==1.10.0
99
huggingface_hub==0.8.1
1010
openai==0.28.0

compose.dev.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ services:
44
context: ./app
55
shm_size: "16gb"
66
ports:
7-
- target: 5000
8-
published: 5001 # MacOS AirPlay uses port 5000
7+
- target: 5050
8+
published: 5050 # MacOS AirPlay uses port 5000
99
protocol: tcp
1010
mode: ingress
1111
environment:
@@ -14,7 +14,12 @@ services:
1414
SEGMENT_WRITE_KEY: ${SEGMENT_WRITE_KEY} # Set your Segment write key here or in the .env file
1515
SESSION_COOKIE_SECURE: 0
1616
OPENAI_API_KEY: ${OPENAI_API_KEY} # Set your OpenAI API key here or in the .env file
17-
command: flask run --host=0.0.0.0
17+
SENTENCE_TRANSFORMERS_HOME: /app/sentence-transformers
18+
volumes:
19+
- type: bind
20+
source: ./app
21+
target: /app
22+
command: flask run --host=0.0.0.0 --port=5050
1823
deploy:
1924
resources:
2025
reservations:

compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ services:
77
context: ./app
88
shm_size: "16gb"
99
ports:
10-
- target: 5000
11-
published: 5000
10+
- target: 5050
11+
published: 5050
1212
protocol: tcp
1313
mode: ingress
1414
environment:
@@ -17,13 +17,13 @@ services:
1717
SEGMENT_WRITE_KEY:
1818
SESSION_COOKIE_SECURE: 1
1919
OPENAI_API_KEY: ${OPENAI_API_KEY} # Set your OpenAI API key here or in the .env file
20-
command: uwsgi --http 0.0.0.0:5000 --wsgi-file app.py --callable app --processes 4 --threads 2
20+
command: uwsgi --http 0.0.0.0:5050 --wsgi-file app.py --callable app --processes 4 --threads 2
2121
deploy:
2222
resources:
2323
reservations:
2424
memory: 4G
2525
healthcheck:
26-
test: ["CMD", "curl", "-f", "http://localhost:5000/"]
26+
test: ["CMD", "curl", "-f", "http://localhost:5050/"]
2727
interval: 30s
2828
timeout: 10s
2929
retries: 5

0 commit comments

Comments
 (0)