Skip to content

Commit fa250e0

Browse files
committed
use config.json to provide env var & prompt
1 parent 3b9edad commit fa250e0

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

Dockerfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ FROM python:3.9-slim
22

33
WORKDIR /app
44

5+
# remember first prepare the config.json with OPENAI_API_KEY & SYSTEM_PROMPT
56
COPY . /app
67

7-
ARG OPENAI_API_KEY
8-
ENV OPENAI_API_KEY=${OPENAI_API_KEY}
9-
108
RUN pip install --no-cache-dir -r requirements.txt
119

1210
EXPOSE 5000

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Python Flask Chatbot Web-App using OpenAI API
22

33
## Requirements
4+
> python 3.9 \
45
> pip install --no-cache-dir -r requirements.txt
56
67

@@ -13,6 +14,10 @@
1314
/templates --- HTML template files, used together with Backend framework
1415

1516

17+
## /config.json (to be customized and placed in working dir)
18+
A dict of OPENAI_API_KEY & SYSTEM_PROMPT
19+
20+
1621
## main.py
1722
Python Script for Flask (A lightweight backend framework) Web-App
1823

main.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import os
1+
import json
22
from flask import Flask, request, render_template
33
from openai import OpenAI
44

5-
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
5+
66
server = Flask(__name__)
7-
system_prompt = "You are the personal assistant of Kangdong Jin! He is a recent master's graduate with excellent " \
8-
"bilingual English and German communication skills of TU Braunschweig with a specialization " \
9-
"in Deep Learning, Generative AI, Computer Vision, and autonomous driving, with extensive " \
10-
"experience in these fields. He is currently seeking challenging projects and opportunities, " \
11-
"especially in AI-related areas."
7+
8+
with open('./config.json') as f:
9+
config = json.load(f)
10+
OPENAI_API_KEY = config['OPENAI_API_KEY']
11+
SYSTEM_PROMPT = config['SYSTEM_PROMPT']
12+
print(SYSTEM_PROMPT)
13+
14+
client = OpenAI(api_key=OPENAI_API_KEY)
15+
system_prompt = SYSTEM_PROMPT
1216

1317

1418
def send_gpt(prompt):
@@ -43,5 +47,6 @@ def get_request_json():
4347
return render_template('chat4o.html', question=question, res=str(res))
4448
return render_template('chat4o.html', question=0)
4549

50+
4651
if __name__ == '__main__':
4752
server.run(debug=True, host='0.0.0.0', port=5000)

0 commit comments

Comments
 (0)