Skip to content

Commit 12c365e

Browse files
committed
Lint
1 parent 4d44d02 commit 12c365e

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

services/chatbot/src/chatbot_api.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
vulnerable_app_qa = None
2323
target_source_chunks = int(os.environ.get("TARGET_SOURCE_CHUNKS", 4))
2424
loaded_model_lock = threading.Lock()
25-
loaded_model = False
25+
loaded_model = threading.Event()
2626
logger = logging.getLogger(__name__)
2727
logger.setLevel(logging.DEBUG)
2828

@@ -93,28 +93,29 @@ def init_bot():
9393
try:
9494
with loaded_model_lock:
9595
if "openai_api_key" in request.json:
96-
print("Initializing bot", request.json["openai_api_key"])
96+
logger.debug("Initializing bot %s", request.json["openai_api_key"])
9797
os.environ["OPENAI_API_KEY"] = request.json["openai_api_key"]
9898
global vulnerable_app_qa, retriever
9999
retriever = document_loader()
100100
llm = get_llm()
101101
vulnerable_app_qa = get_qa_chain(llm, retriever)
102-
loaded_model = True
102+
loaded_model.set()
103103
return jsonify({"message": "Model Initialized"}), 200
104104
else:
105105
return jsonify({"message": "openai_api_key not provided"}, 400)
106106
except Exception as e:
107-
print("Error initializing bot ", e)
107+
logger.error("Error initializing bot ", e)
108+
logger.debug("Error initializing bot ", e, exc_info=True)
108109
return jsonify({"message": "Not able to initialize model " + str(e)}), 400
109110

110111

111112
@app.route("/chatbot/genai/state", methods=["GET"])
112113
def state_bot():
113114
try:
114-
if loaded_model:
115+
if loaded_model.is_set():
115116
return jsonify({"message": "Model already loaded"})
116117
except Exception as e:
117-
print("Error checking state ", e)
118+
logger.error("Error checking state ", e)
118119
return jsonify({"message": "Error checking state " + str(e)}), 400
119120
return jsonify({"message": "Model Error"}), 400
120121

@@ -124,10 +125,10 @@ def ask_bot():
124125
question = request.json["question"]
125126
global vulnerable_app_qa
126127
answer = qa_app(vulnerable_app_qa, question)
127-
print("###########################################")
128-
print("Test Attacker Question: " + str(question))
129-
print("Vulnerability App Answer: " + str(answer))
130-
print("###########################################")
128+
logger.info("###########################################")
129+
logger.info("Test Attacker Question: %s", question)
130+
logger.info("Vulnerability App Answer: %s", answer)
131+
logger.info("###########################################")
131132
return jsonify({"answer": answer}), 200
132133

133134

services/web/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "crapi-web",
33
"version": "0.1.0",
44
"private": true,
5-
"proxy": "http://localhost:5002",
65
"dependencies": {
76
"@ant-design/icons": "^4.8.3",
87
"@testing-library/jest-dom": "^4.2.4",

services/web/src/components/bot/ActionProvider.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class ActionProvider {
9797
},
9898
);
9999
this.addMessageToState(successmessage);
100-
this.addNotInitializingToState();
100+
this.addInitializedToState();
101101
});
102102
return;
103103
};
@@ -123,7 +123,7 @@ class ActionProvider {
123123
return;
124124
}
125125
console.log(res);
126-
const successmessage = this.createChatBotMessage(res.body.response, {
126+
const successmessage = this.createChatBotMessage(res.body.answer, {
127127
loading: true,
128128
terminateLoading: true,
129129
});
@@ -188,10 +188,11 @@ class ActionProvider {
188188
}));
189189
};
190190

191-
addNotInitializingToState = () => {
191+
addInitializedToState = () => {
192192
this.setState((state) => ({
193193
...state,
194194
initializing: false,
195+
initializationRequired: false,
195196
}));
196197
};
197198

services/web/src/components/bot/MessageParser.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,17 @@ class MessageParser {
2929
.set("Content-Type", "application/json")
3030
.end((err, res) => {
3131
if (err) {
32+
console.log("Error:");
3233
console.log(err);
33-
console.log("Initialization required");
34+
console.log("Initialization required prefetch error");
3435
return true;
3536
}
3637
console.log(res);
37-
if ((res.status = 200)) {
38+
if (res.status == 200) {
3839
console.log("Initialization not required");
3940
return false;
4041
}
4142
});
42-
console.log("Initialization required");
43-
return true;
4443
}
4544

4645
parse(message) {

0 commit comments

Comments
 (0)