Skip to content

Commit 74e9a49

Browse files
authored
Option to use Azure search with the chatbot (#1330)
* WIP * Make precommit hooks lighter and introduce bin/git-run-precommit-checks * Sqlx prepare * WIP * WIP * WIP * WIP * WIP * WIP * Chatbot ui refactoring * Refactoring * Fix button location * Refactoring * WIP * WIP * Move chatbot into its own crate * Make errors more flexible * Fix * WIP azure blob storage * WIP * Implement delteting old pages * Refactoring * WIP * WIP * Resolving problems * Logging improvements * Fixes * Fixes * WIP using the search index * Refactoring * Refactoring * Make token estimation take sent message into account * Fix request guard being dropped before the stream is ready and use correct parameters for the search * Add configuration, and finalizing * Add deployment * Fix * Don't crash if azure not configured
1 parent 6559037 commit 74e9a49

File tree

78 files changed

+4017
-798
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4017
-798
lines changed

.husky/lint-staged.config.js renamed to .husky/lint-staged.branch-ready.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
// Runs when you run bin/git-run-branch-ready-checks.
2+
// These checks are slower and more likely to fail than the precommit checks.
3+
// See lint-staged.precommit.config.js for precommit checks.
4+
module.exports = {
25
"*.{js,jsx,ts,tsx}": ["eslint --cache --fix", "stylelint --fix"],
36
"services/example-exercise/src/**/*.{js,jsx,ts,tsx}": () =>
47
"npx tsc -p services/example-exercise/ --noEmit",
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Runs on precommit.
2+
// Focuses on tests that are fast to run don't fail often. For other checks, see bin/git-run-branch-ready-checks and lint-staged.branch-ready.config.js
3+
module.exports = {
4+
"*.{js,jsx,ts,tsx}": ["eslint --cache --fix", "stylelint --fix"],
5+
"*.{md,json,scss,css}": "prettier --write",
6+
"*.rs": () => [
7+
"cargo fmt --manifest-path services/headless-lms/Cargo.toml --all -- --files-with-diff",
8+
],
9+
"system-tests/src/**/*.{js,jsx,ts,tsx}": () => [
10+
`./bin/check-no-test-only-in-system-tests`,
11+
],
12+
"shared-module/packages/common/src/locales/**/*.json": () => ["./bin/translations-sort"],
13+
}

.husky/post-commit

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
#!/bin/sh
2-
LAST_TIME_PRECOMMIT_SUCCESSFUL=".husky/_/saved-hashes/last-time-precommit-succesful"
3-
# Read the the saved UNIX timestamp from the file and check if the timestamp is recent
4-
if [ -f "$LAST_TIME_PRECOMMIT_SUCCESSFUL" ] && [ $(($(date +%s) - $(cat "$LAST_TIME_PRECOMMIT_SUCCESSFUL"))) -lt 3000 ]; then
5-
# The precommit checks were successful recently so no need to print the warning
6-
rm "$LAST_TIME_PRECOMMIT_SUCCESSFUL" 2> /dev/null || true
7-
exit 0
8-
fi
92

10-
rm "$LAST_TIME_PRECOMMIT_SUCCESSFUL" 2> /dev/null || true
11-
12-
echo "ℹ️ Detected you used git commit with --no-verify. This may be fine if you don't want to wait for the checks to complete, but you'll need to ensure all the skipped checks pass before you create a pull request or your branch is merged."
133
echo ""
144
echo "👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇"
155
echo ""
16-
printf "\033[1;31m⚠️ ONCE YOU'RE READY WITH THE BRANCH, RUN bin/git-run-precommit-checks AND MAKE SURE EVERYTHING PASSES ⚠️\033[0m\n"
6+
printf "\033[1;31m⚠️ ONCE YOU'RE READY WITH THE BRANCH, RUN bin/git-run-branch-ready-checks AND MAKE SURE EVERYTHING PASSES ⚠️\033[0m\n"
177
echo ""
188
echo "👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆"
199
echo ""

.husky/pre-commit

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,4 @@
44
# Makes the check faster, and the database does not have to be running to commit
55
export SQLX_OFFLINE=1
66

7-
npx lint-staged -c ./.husky/lint-staged.config.js
8-
9-
# Save the last time this was succesfully ran so that we can detect in post-commit if this script was skipped with --no-verify
10-
LAST_TIME_PRECOMMIT_SUCCESSFUL=".husky/_/saved-hashes/last-time-precommit-succesful"
11-
date +%s > "$LAST_TIME_PRECOMMIT_SUCCESSFUL"
7+
npx lint-staged -c ./.husky/lint-staged.precommit.config.js

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Secret Project 331
2+
23
## Development environment setup
34

45
Read [Development.md](https://github.com/rage/secret-project-331/blob/master/docs/Development.md) on how to setup using Windows or Linux.
@@ -12,7 +13,7 @@ bin/seed
1213
## Code style:
1314

1415
```bash
15-
npm run eslint
16+
bin/git-run-branch-ready-checks
1617
```
1718

1819
## Documentation

bin/git-run-precommit-checks renamed to bin/git-run-branch-ready-checks

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -euo pipefail
33
source "$(dirname "$0")/.common"
44

5-
echo -e "${BLUE}Runs precommit checks manually by comparing what has changed in this branch. You have to use this command if you have used git commit with --no-verify at some point.${RESET_EVERYTHING}"
5+
echo -e "${BLUE}Checks code for common issues. This script should be used when you're done with branch, and you want to do finishing touches to it..${RESET_EVERYTHING}"
66
echo -e "${BLUE}It might be a good idea to also run ${BOLD}bin/git-merge-origin-master${RESET_EVERYTHING}"
77
echo ""
88

@@ -15,6 +15,6 @@ run_command cd "$RELATIVE_PATH"
1515
CURRENT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
1616
MERGE_BASE=$(git merge-base origin/master "$CURRENT_BRANCH_NAME")
1717

18-
run_command npx lint-staged -c ./.husky/lint-staged.config.js --diff "$MERGE_BASE" "$@"
18+
run_command npx lint-staged -c ./.husky/lint-staged.branch-ready.config.js --diff "$MERGE_BASE" "$@"
1919

2020
echo -e "${GREEN}✅ All precommit checks passed.${RESET_EVERYTHING}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: chatbot-syncer
5+
labels:
6+
app: chatbot-syncer
7+
deploymentType: with-init-container
8+
needs-db: "true"
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
app: chatbot-syncer
14+
template:
15+
metadata:
16+
annotations:
17+
linkerd.io/inject: enabled
18+
labels:
19+
app: chatbot-syncer
20+
spec:
21+
containers:
22+
- name: chatbot-syncer
23+
image: headless-lms
24+
command: ["bin/run", "chatbot-syncer"]
25+
resources:
26+
requests:
27+
memory: 100Mi
28+
cpu: 20m
29+
limits:
30+
memory: 300Mi
31+
cpu: 200m
32+
envFrom:
33+
- secretRef:
34+
name: headless-lms-secrets
35+
initContainers:
36+
- name: headless-lms-wait-for-db
37+
image: headless-lms
38+
command:
39+
- bash
40+
- "-c"
41+
- |
42+
echo Waiting for postgres to be available
43+
timeout 120 ./wait-for-db.sh
44+
./wait-for-db-migrations.sh
45+
resources:
46+
requests:
47+
memory: 100Mi
48+
cpu: 20m
49+
limits:
50+
memory: 300Mi
51+
cpu: 200m
52+
envFrom:
53+
- secretRef:
54+
name: headless-lms-secrets

kubernetes/base/kustomization.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ resources:
1717
- headless-lms/regrader.yml
1818
- headless-lms/peer-review-updater.yml
1919
- headless-lms/sync-tmc-users.yml
20+
- headless-lms/chatbot-syncer.yml

services/course-material/src/components/chatbot/ChatbotDialog.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { css, keyframes } from "@emotion/css"
22
import { useQuery } from "@tanstack/react-query"
3-
import { useEffect, useState } from "react"
3+
import React, { useEffect, useState } from "react"
44

55
import ChatbotDialogBody from "./ChatbotDialogBody"
66
import ChatbotDialogHeader from "./ChatbotDialogHeader"
@@ -39,6 +39,8 @@ const ChatbotDialog: React.FC<ChatbotDialogProps> = (props) => {
3939
const { dialogOpen, chatbotConfigurationId } = props
4040
const [shouldRender, setShouldRender] = useState(dialogOpen)
4141

42+
const [error, setError] = useState<Error | null>(null)
43+
4244
const currentConversationInfoQuery = useQuery({
4345
queryKey: ["currentConversationInfo", chatbotConfigurationId],
4446
queryFn: () => getChatbotCurrentConversationInfo(chatbotConfigurationId),
@@ -83,7 +85,12 @@ const ChatbotDialog: React.FC<ChatbotDialogProps> = (props) => {
8385
onAnimationEnd={handleAnimationEnd}
8486
>
8587
<ChatbotDialogHeader {...props} currentConversationInfo={currentConversationInfoQuery} />
86-
<ChatbotDialogBody {...props} currentConversationInfo={currentConversationInfoQuery} />
88+
<ChatbotDialogBody
89+
{...props}
90+
currentConversationInfo={currentConversationInfoQuery}
91+
error={error}
92+
setError={setError}
93+
/>
8794
</div>
8895
)
8996
}

0 commit comments

Comments
 (0)