-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for procted bot (beta)
- Loading branch information
Showing
33 changed files
with
1,058 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
export type BotSettings = { | ||
data: { | ||
id: string; | ||
name: string; | ||
model: string; | ||
public_id: string; | ||
temperature: number; | ||
embedding: string; | ||
noOfDocumentsToRetrieve: number; | ||
qaPrompt: string; | ||
questionGeneratorPrompt: string; | ||
streaming: boolean; | ||
showRef: boolean; | ||
use_hybrid_search: boolean; | ||
bot_protect: boolean; | ||
use_rag: boolean; | ||
bot_model_api_key: string; | ||
noOfChatHistoryInContext: number; | ||
semanticSearchSimilarityScore: string | ||
}, | ||
name: string; | ||
model: string; | ||
public_id: string; | ||
temperature: number; | ||
embedding: string; | ||
noOfDocumentsToRetrieve: number; | ||
qaPrompt: string; | ||
questionGeneratorPrompt: string; | ||
streaming: boolean; | ||
showRef: boolean; | ||
use_hybrid_search: boolean; | ||
publicBotPwdProtected: boolean; | ||
publicBotPwd: string; | ||
bot_protect: boolean; | ||
use_rag: boolean; | ||
bot_model_api_key: string; | ||
noOfChatHistoryInContext: number; | ||
semanticSearchSimilarityScore: string; | ||
}; | ||
chatModel: { | ||
label: string; | ||
value: string; | ||
stream: boolean; | ||
}[], | ||
}[]; | ||
embeddingModel: { | ||
label: string; | ||
value: string; | ||
}[], | ||
}[]; | ||
}; | ||
|
||
|
||
export type BotIntegrationAPI = { | ||
is_api_enabled: boolean; | ||
data: { | ||
public_url: string | null; | ||
api_key: string | null; | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Form, Switch, Input, notification } from "antd"; | ||
import { useParams } from "react-router-dom"; | ||
import api from "../../../services/api"; | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import axios from "axios"; | ||
|
||
type Props = { | ||
publicBotPwdProtected: boolean; | ||
publicBotPwd: string; | ||
}; | ||
|
||
export const SettingsPwdP: React.FC<Props> = ({ | ||
publicBotPwd, | ||
publicBotPwdProtected, | ||
}) => { | ||
const params = useParams<{ id: string }>(); | ||
const [form] = Form.useForm(); | ||
const isEnabled = Form.useWatch("publicBotPwdProtected", form); | ||
const client = useQueryClient(); | ||
const onFinish = async (values: any) => { | ||
const response = await api.put(`/bot/${params.id}/password`, values); | ||
return response.data; | ||
}; | ||
|
||
const { mutate, isLoading } = useMutation(onFinish, { | ||
onSuccess: () => { | ||
client.invalidateQueries(["getBotSettings", params.id]); | ||
|
||
notification.success({ | ||
message: "Bot settings updated successfully", | ||
}); | ||
}, | ||
onError: (error: any) => { | ||
if (axios.isAxiosError(error)) { | ||
const message = error.response?.data?.message || "Something went wrong"; | ||
notification.error({ | ||
message, | ||
}); | ||
return; | ||
} | ||
notification.error({ | ||
message: "Something went wrong", | ||
}); | ||
}, | ||
}); | ||
return ( | ||
<Form | ||
form={form} | ||
initialValues={{ | ||
publicBotPwdProtected, | ||
publicBotPwd, | ||
}} | ||
layout="vertical" | ||
onFinish={mutate} | ||
> | ||
<div className="px-4 py-5 bg-white border sm:rounded-lg sm:p-6 dark:bg-[#1e1e1e] dark:border-gray-700"> | ||
<div className="md:grid md:grid-cols-3 md:gap-6"> | ||
<div className="md:col-span-1"> | ||
<h3 className="text-lg font-medium leading-6 text-gray-900 dark:text-white"> | ||
Password Protection | ||
</h3> | ||
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400"> | ||
Proctect bot's public access with a password. | ||
</p> | ||
</div> | ||
<div className="mt-5 space-y-6 md:col-span-2 md:mt-0"> | ||
<Form.Item | ||
name="publicBotPwdProtected" | ||
valuePropName="checked" | ||
label="Enable Password Protection" | ||
> | ||
<Switch /> | ||
</Form.Item> | ||
|
||
<Form.Item | ||
name="publicBotPwd" | ||
label="Password" | ||
rules={[ | ||
{ | ||
required: isEnabled, | ||
message: "Please input your password!", | ||
}, | ||
]} | ||
> | ||
<Input.Password | ||
placeholder="Password" | ||
disabled={!isEnabled} | ||
size="large" | ||
/> | ||
</Form.Item> | ||
|
||
<div className="text-sm text-gray-500 dark:text-gray-400"> | ||
This feature is in preview and only works with web interface for | ||
now | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div className="mt-3 text-right"> | ||
<button | ||
type="submit" | ||
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" | ||
> | ||
{isLoading ? "Saving..." : "Save"} | ||
</button> | ||
</div> | ||
</div> | ||
</Form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.