Skip to content

Commit ec8014f

Browse files
committed
Minor fixes
1 parent 12c365e commit ec8014f

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

services/chatbot/build-image.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ set -x
1717
cd "$(dirname $0)"
1818
mkdir -p retrieval
1919
cp -Rv ../../docs retrieval/
20+
cp -Rv ../../deploy/docker/*.yml retrieval/docs/
21+
cp -Rv ../../deploy/docker/*.yaml retrieval/docs/
22+
2023
docker build -t crapi/crapi-chatbot:${VERSION:-latest} .
2124
retVal=$?
2225
if [ $retVal -ne 0 ]; then

services/chatbot/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ langchain_community==0.0.34
55
langchain_core==0.1.45
66
langchain_openai==0.1.3
77
python-dotenv==1.0.1
8-
unstructured==0.13.3
8+
unstructured
99
gunicorn==22.0.0
1010
markdown==3.6

services/chatbot/src/chatbot_api.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def document_loader():
3232
load_dir = "retrieval"
3333
logger.debug("Loading documents from %s", load_dir)
3434
loader = DirectoryLoader(
35-
load_dir, glob="**/*.md", loader_cls=UnstructuredMarkdownLoader
35+
load_dir,
36+
exclude=["**/*.png", "**/images/**", "**/images/*", "**/*.pdf"],
37+
recursive=True,
38+
loader_cls=UnstructuredMarkdownLoader,
3639
)
3740
documents = loader.load()
3841
logger.debug("Loaded %s documents", len(documents))
@@ -113,11 +116,14 @@ def init_bot():
113116
def state_bot():
114117
try:
115118
if loaded_model.is_set():
116-
return jsonify({"message": "Model already loaded"})
119+
return jsonify({"initialized": "true", "message": "Model already loaded"})
117120
except Exception as e:
118121
logger.error("Error checking state ", e)
119-
return jsonify({"message": "Error checking state " + str(e)}), 400
120-
return jsonify({"message": "Model Error"}), 400
122+
return jsonify({"message": "Error checking state " + str(e)}), 200
123+
return (
124+
jsonify({"initialized": "false", "message": "Model needs to be initialized"}),
125+
200,
126+
)
121127

122128

123129
@app.route("/chatbot/genai/ask", methods=["POST"])

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class ActionProvider {
151151
terminateLoading: true,
152152
},
153153
);
154+
this.addMessageToState(message);
154155
}
155156
};
156157

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,54 @@
1313
* limitations under the License.
1414
*/
1515
import { APIService } from "../../constants/APIConstant";
16-
const superagent = require("superagent");
16+
import request from "superagent";
1717

1818
class MessageParser {
1919
constructor(actionProvider, state) {
2020
this.actionProvider = actionProvider;
2121
this.state = state;
2222
}
2323

24-
initializationRequired() {
24+
async initializationRequired() {
2525
const stateUrl = APIService.CHATBOT_SERVICE + "genai/state";
26-
superagent
26+
let initRequired = false;
27+
// Wait for the response
28+
await request
2729
.get(stateUrl)
2830
.set("Accept", "application/json")
2931
.set("Content-Type", "application/json")
30-
.end((err, res) => {
31-
if (err) {
32-
console.log("Error:");
33-
console.log(err);
34-
console.log("Initialization required prefetch error");
35-
return true;
36-
}
37-
console.log(res);
38-
if (res.status == 200) {
39-
console.log("Initialization not required");
40-
return false;
32+
.then((res) => {
33+
console.log("I response:", res.body);
34+
if (res.status === 200) {
35+
if (res.body.initialized === "true") {
36+
initRequired = false;
37+
} else {
38+
initRequired = true;
39+
}
4140
}
41+
})
42+
.catch((err) => {
43+
console.log("Error prefetch: ", err);
4244
});
45+
console.log("Initialization required:", initRequired);
46+
return initRequired;
4347
}
4448

45-
parse(message) {
49+
async parse(message) {
4650
console.log("State:", this.state);
4751
console.log("Message:", message);
4852
const message_l = message.toLowerCase();
4953
if (this.state.initializationRequired === undefined) {
50-
this.state.initializationRequired = this.initializationRequired();
54+
this.state.initializationRequired = await this.initializationRequired();
55+
console.log("State:", this.state);
5156
}
5257
if (message_l === "help") {
53-
this.state.initializationRequired = this.initializationRequired();
58+
this.state.initializationRequired = await this.initializationRequired();
59+
console.log("State help:", this.state);
5460
return this.actionProvider.handleHelp(this.state.initializationRequired);
5561
} else if (message_l === "init" || message_l === "initialize") {
56-
this.state.initializationRequired = this.initializationRequired();
62+
this.state.initializationRequired = await this.initializationRequired();
63+
console.log("State init:", this.state);
5764
return this.actionProvider.handleInitialize(
5865
this.state.initializationRequired,
5966
);

0 commit comments

Comments
 (0)