Skip to content

Commit 7442e46

Browse files
authored
Merge pull request #278 from n4ze3m/next
v1.9.0
2 parents 4b65f4a + 6af5b2b commit 7442e46

Some content is hidden

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

48 files changed

+7651
-6025
lines changed

app/ui/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "app",
33
"private": true,
4-
"version": "1.8.6",
4+
"version": "1.9.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
@@ -23,6 +23,7 @@
2323
"d3": "^7.8.5",
2424
"dayjs": "^1.11.10",
2525
"eventsource-parser": "^1.0.0",
26+
"framer-motion": "^11.3.2",
2627
"js-cookie": "^3.0.5",
2728
"localforage": "^1.10.0",
2829
"match-sorter": "^6.3.1",

app/ui/src/@types/bot.ts

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
export type BotSettings = {
22
data: {
33
id: string;
4-
name: string;
5-
model: string;
6-
public_id: string;
7-
temperature: number;
8-
embedding: string;
9-
noOfDocumentsToRetrieve: number;
10-
qaPrompt: string;
11-
questionGeneratorPrompt: string;
12-
streaming: boolean;
13-
showRef: boolean;
14-
use_hybrid_search: boolean;
15-
bot_protect: boolean;
16-
use_rag: boolean;
17-
bot_model_api_key: string;
18-
noOfChatHistoryInContext: number;
19-
semanticSearchSimilarityScore: string
20-
},
4+
name: string;
5+
model: string;
6+
public_id: string;
7+
temperature: number;
8+
embedding: string;
9+
noOfDocumentsToRetrieve: number;
10+
qaPrompt: string;
11+
questionGeneratorPrompt: string;
12+
streaming: boolean;
13+
showRef: boolean;
14+
use_hybrid_search: boolean;
15+
publicBotPwdProtected: boolean;
16+
publicBotPwd: string;
17+
bot_protect: boolean;
18+
use_rag: boolean;
19+
bot_model_api_key: string;
20+
noOfChatHistoryInContext: number;
21+
semanticSearchSimilarityScore: string;
22+
};
2123
chatModel: {
2224
label: string;
2325
value: string;
2426
stream: boolean;
25-
}[],
27+
}[];
2628
embeddingModel: {
2729
label: string;
2830
value: string;
29-
}[],
31+
}[];
3032
};
3133

32-
3334
export type BotIntegrationAPI = {
3435
is_api_enabled: boolean;
3536
data: {
3637
public_url: string | null;
3738
api_key: string | null;
3839
};
39-
}
40+
};

app/ui/src/components/Bot/Playground/HistoryList.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import React from "react";
77
import { useMessage } from "../../../hooks/useMessage";
88
import { Empty, Skeleton } from "antd";
99
import { useStoreMessage } from "../../../store";
10+
import { motion } from "framer-motion";
1011

1112
export const PlaygroundHistoryList = () => {
1213
const params = useParams<{ id: string; history_id?: string }>();
@@ -72,9 +73,16 @@ export const PlaygroundHistoryList = () => {
7273
</div>
7374
)}
7475
<div className="flex flex-col gap-2 overflow-hidden text-gray-100 text-sm dark:text-gray-400">
75-
{data.history.map((item, index) => {
76-
return <PlaygroundHistoryCard key={index} item={item} />;
77-
})}
76+
{data.history.map((item, index) => (
77+
<motion.div
78+
key={item.id || index}
79+
initial={{ opacity: 0, y: 20 }}
80+
animate={{ opacity: 1, y: 0 }}
81+
transition={{ duration: 0.3, delay: index * 0.1 }}
82+
>
83+
<PlaygroundHistoryCard item={item} />
84+
</motion.div>
85+
))}
7886
</div>
7987
</div>
8088
)}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { Form, Switch, Input, notification } from "antd";
2+
import { useParams } from "react-router-dom";
3+
import api from "../../../services/api";
4+
import { useMutation, useQueryClient } from "@tanstack/react-query";
5+
import axios from "axios";
6+
7+
type Props = {
8+
publicBotPwdProtected: boolean;
9+
publicBotPwd: string;
10+
};
11+
12+
export const SettingsPwdP: React.FC<Props> = ({
13+
publicBotPwd,
14+
publicBotPwdProtected,
15+
}) => {
16+
const params = useParams<{ id: string }>();
17+
const [form] = Form.useForm();
18+
const isEnabled = Form.useWatch("publicBotPwdProtected", form);
19+
const client = useQueryClient();
20+
const onFinish = async (values: any) => {
21+
const response = await api.put(`/bot/${params.id}/password`, values);
22+
return response.data;
23+
};
24+
25+
const { mutate, isLoading } = useMutation(onFinish, {
26+
onSuccess: () => {
27+
client.invalidateQueries(["getBotSettings", params.id]);
28+
29+
notification.success({
30+
message: "Bot settings updated successfully",
31+
});
32+
},
33+
onError: (error: any) => {
34+
if (axios.isAxiosError(error)) {
35+
const message = error.response?.data?.message || "Something went wrong";
36+
notification.error({
37+
message,
38+
});
39+
return;
40+
}
41+
notification.error({
42+
message: "Something went wrong",
43+
});
44+
},
45+
});
46+
return (
47+
<Form
48+
form={form}
49+
initialValues={{
50+
publicBotPwdProtected,
51+
publicBotPwd,
52+
}}
53+
layout="vertical"
54+
onFinish={mutate}
55+
>
56+
<div className="px-4 py-5 bg-white border sm:rounded-lg sm:p-6 dark:bg-[#1e1e1e] dark:border-gray-700">
57+
<div className="md:grid md:grid-cols-3 md:gap-6">
58+
<div className="md:col-span-1">
59+
<h3 className="text-lg font-medium leading-6 text-gray-900 dark:text-white">
60+
Password Protection
61+
</h3>
62+
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400">
63+
Proctect bot's public access with a password.
64+
</p>
65+
</div>
66+
<div className="mt-5 space-y-6 md:col-span-2 md:mt-0">
67+
<Form.Item
68+
name="publicBotPwdProtected"
69+
valuePropName="checked"
70+
label="Enable Password Protection"
71+
>
72+
<Switch />
73+
</Form.Item>
74+
75+
<Form.Item
76+
name="publicBotPwd"
77+
label="Password"
78+
rules={[
79+
{
80+
required: isEnabled,
81+
message: "Please input your password!",
82+
},
83+
]}
84+
>
85+
<Input.Password
86+
placeholder="Password"
87+
disabled={!isEnabled}
88+
size="large"
89+
/>
90+
</Form.Item>
91+
92+
<div className="text-sm text-gray-500 dark:text-gray-400">
93+
This feature is in preview and only works with web interface for
94+
now
95+
</div>
96+
</div>
97+
</div>
98+
99+
<div className="mt-3 text-right">
100+
<button
101+
type="submit"
102+
className="inline-flex justify-center rounded-md border border-transparent bg-indigo-600 py-2 px-4 text-sm font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
103+
>
104+
{isLoading ? "Saving..." : "Save"}
105+
</button>
106+
</div>
107+
</div>
108+
</Form>
109+
);
110+
};

app/ui/src/components/Bot/Settings/SettingsCard.tsx renamed to app/ui/src/components/Bot/Settings/SettingsBody.tsx

+12-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import {
1717
HELPFUL_ASSISTANT_WITHOUT_CONTEXT_PROMPT,
1818
} from "../../../utils/prompts";
1919
import { BotSettings } from "../../../@types/bot";
20+
import { SettingsPwdP } from "./SettingPwdP";
2021

21-
export const SettingsCard: React.FC<BotSettings> = ({
22+
export const SettingsBody: React.FC<BotSettings> = ({
2223
data,
2324
chatModel,
2425
embeddingModel,
@@ -147,7 +148,6 @@ export const SettingsCard: React.FC<BotSettings> = ({
147148
</p>
148149
</div>
149150
</div>
150-
{/* centerize the div */}
151151
<div className="mt-6 space-y-4">
152152
<Form
153153
initialValues={{
@@ -299,9 +299,9 @@ export const SettingsCard: React.FC<BotSettings> = ({
299299
placeholder="Enter number of documents to retrieve"
300300
/>
301301
</Form.Item>
302-
{/* <Form.Item
302+
<Form.Item
303303
name="noOfChatHistoryInContext"
304-
label="Number of chat history in context"
304+
label="Number of chat histories in context"
305305
rules={[
306306
{
307307
required: true,
@@ -315,7 +315,7 @@ export const SettingsCard: React.FC<BotSettings> = ({
315315
style={{ width: "100%" }}
316316
placeholder="Enter number of chat history in context"
317317
/>
318-
</Form.Item> */}
318+
</Form.Item>
319319
<Form.Item
320320
label={"Semantic Search Similarity Score"}
321321
name="semanticSearchSimilarityScore"
@@ -439,6 +439,13 @@ export const SettingsCard: React.FC<BotSettings> = ({
439439
</div>
440440
</Form>
441441

442+
<div className="bg-white border sm:rounded-lg dark:bg-[#1e1e1e] dark:border-gray-700">
443+
<SettingsPwdP
444+
publicBotPwd={data.publicBotPwd}
445+
publicBotPwdProtected={data.publicBotPwdProtected}
446+
/>
447+
</div>
448+
442449
<div className="bg-white border sm:rounded-lg dark:bg-[#1e1e1e] dark:border-gray-700">
443450
<div className="px-4 py-5 sm:p-6">
444451
<h3 className="text-lg font-medium leading-6 text-gray-900 dark:text-white">

app/ui/src/components/Dashboard/DashboardGrid.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export const DashboardGrid = () => {
6666
</div>
6767

6868
<div className="px-4 my-3 flex flex-wrap gap-2 text-gray-500 text-xs dark:text-gray-400">
69-
{bot.source.map((source: any) => (
70-
<span title={`${source.type} source`}>
69+
{bot.source.map((source: any, idx: number) => (
70+
<span title={`${source.type} source`} key={idx}>
7171
{sources[source.type as keyof typeof sources]}
7272
</span>
7373
))}

app/ui/src/routes/bot/settings.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useNavigate, useParams } from "react-router-dom";
33
import api from "../../services/api";
44
import React from "react";
55
import { SkeletonLoading } from "../../components/Common/SkeletonLoading";
6-
import { SettingsCard } from "../../components/Bot/Settings/SettingsCard";
6+
import { SettingsBody } from "../../components/Bot/Settings/SettingsBody";
77
import { BotSettings } from "../../@types/bot";
88

99
export default function BotSettingsRoot() {
@@ -14,8 +14,7 @@ export default function BotSettingsRoot() {
1414
["getBotSettings", param.id],
1515
async () => {
1616
const response = await api.get(`/bot/${param.id}/settings`);
17-
return response.data as BotSettings
18-
17+
return response.data as BotSettings;
1918
},
2019
{
2120
refetchInterval: 1000,
@@ -28,9 +27,11 @@ export default function BotSettingsRoot() {
2827
}
2928
}, [status]);
3029
return (
31-
<div className="mx-auto my-3 w-full max-w-7xl">
32-
{status === "loading" && <SkeletonLoading />}
33-
{status === "success" && <SettingsCard {...data} />}
30+
<div className="flex-1 py-8 md:py-12 px-4 md:px-6">
31+
<div className="max-w-6xl mx-auto grid gap-8">
32+
{status === "loading" && <SkeletonLoading />}
33+
{status === "success" && <SettingsBody {...data} />}
34+
</div>
3435
</div>
3536
);
3637
}

app/widget/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"antd": "^5.5.2",
1818
"axios": "^1.4.0",
1919
"react": "^18.2.0",
20+
"react-cookie": "^7.1.4",
2021
"react-dom": "^18.2.0",
2122
"react-markdown": "^8.0.7",
2223
"react-syntax-highlighter": "^15.5.0",

0 commit comments

Comments
 (0)