Skip to content

Commit daaa28b

Browse files
committed
Fix UI
1 parent e97a52f commit daaa28b

3 files changed

Lines changed: 34 additions & 23 deletions

File tree

services/chatbot/src/chatbot_api.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,6 @@ def state_bot():
164164
jsonify({"initialized": "true", "message": "Model already loaded"}),
165165
200,
166166
)
167-
else:
168-
if not request.json.get("openai_api_key"):
169-
return (
170-
jsonify(
171-
{
172-
"initialized": "false",
173-
"message": "API Key not set for OpenAI",
174-
}
175-
),
176-
200,
177-
)
178167
except Exception as e:
179168
app.logger.error("Error checking state ", e)
180169
return jsonify({"message": "Error checking state " + str(e)}, 200)

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,40 @@ class ActionProvider {
159159
}
160160
};
161161

162-
handleResetContext = () => {
162+
handleResetContext = (accessToken) => {
163163
localStorage.removeItem("chat_messages");
164164
this.clearMessages();
165-
const message = this.createChatBotMessage(
166-
"Chat context has been cleared.",
167-
{
168-
loading: true,
169-
terminateLoading: true,
170-
},
171-
);
172-
this.addMessageToState(message);
165+
const resetUrl = APIService.CHATBOT_SERVICE + "genai/reset";
166+
superagent
167+
.post(resetUrl)
168+
.set("Accept", "application/json")
169+
.set("Content-Type", "application/json")
170+
.set("Authorization", `Bearer ${accessToken}`)
171+
.end((err, res) => {
172+
if (err) {
173+
console.log(err);
174+
const errormessage = this.createChatBotMessage(
175+
"Failed to clear chat context.",
176+
{
177+
loading: true,
178+
terminateLoading: true,
179+
},
180+
);
181+
this.addMessageToState(errormessage);
182+
return;
183+
}
184+
console.log(res);
185+
const successmessage = this.createChatBotMessage(
186+
"Chat context has been cleared.",
187+
{
188+
loading: true,
189+
terminateLoading: true,
190+
},
191+
);
192+
this.addMessageToState(successmessage);
193+
this.addInitializedToState();
194+
});
195+
return;
173196
};
174197

175198
addMessageToState = (message) => {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,15 @@ class MessageParser {
6363
console.log("State init:", this.state);
6464
return this.actionProvider.handleInitialize(
6565
this.state.initializationRequired,
66-
this.state.accessToken,
6766
);
6867
} else if (
6968
message_l === "clear" ||
7069
message_l === "reset" ||
7170
message_l === "restart"
7271
) {
73-
return this.actionProvider.handleResetContext();
72+
return this.actionProvider.handleResetContext(this.state.accessToken);
7473
} else if (this.state.initializing) {
75-
return this.actionProvider.handleInitialized(message);
74+
return this.actionProvider.handleInitialized(message, this.state.accessToken);
7675
} else if (this.state.initializationRequired) {
7776
return this.actionProvider.handleNotInitialized();
7877
}

0 commit comments

Comments
 (0)