Skip to content

Commit

Permalink
Merge pull request #111 from n4ze3m/next
Browse files Browse the repository at this point in the history
v1.0.4
  • Loading branch information
n4ze3m authored Oct 12, 2023
2 parents d96b4ea + 1b88dd4 commit 087fd28
Show file tree
Hide file tree
Showing 18 changed files with 907 additions and 434 deletions.
2 changes: 1 addition & 1 deletion app/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "app",
"private": true,
"version": "1.0.4",
"version": "1.1.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
15 changes: 15 additions & 0 deletions app/ui/src/@types/bot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export type BotSettings = {
id: string;
name: string;
model: string;
public_id: string;
temperature: number;
embedding: string;
qaPrompt: string;
questionGeneratorPrompt: string;
streaming: boolean;
showRef: boolean;
use_hybrid_search: boolean;
bot_protect: boolean;
use_rag: boolean;
};
38 changes: 21 additions & 17 deletions app/ui/src/components/Bot/Settings/SettingsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,9 @@ import {
HELPFUL_ASSISTANT_WITH_CONTEXT_PROMPT,
HELPFUL_ASSISTANT_WITHOUT_CONTEXT_PROMPT,
} from "../../../utils/prompts";
import { BotSettings } from "../../../@types/bot";

export const SettingsCard = ({
data,
}: {
data: {
id: string;
name: string;
model: string;
public_id: string;
temperature: number;
embedding: string;
qaPrompt: string;
questionGeneratorPrompt: string;
streaming: boolean;
showRef: boolean;
use_hybrid_search: boolean;
};
}) => {
export const SettingsCard = ({ data }: { data: BotSettings }) => {
const [form] = Form.useForm();
const [disableStreaming, setDisableStreaming] = React.useState(false);
const params = useParams<{ id: string }>();
Expand Down Expand Up @@ -133,6 +118,8 @@ export const SettingsCard = ({
streaming: data.streaming,
showRef: data.showRef,
use_hybrid_search: data.use_hybrid_search,
bot_protect: data.bot_protect,
use_rag: data.use_rag
}}
form={form}
requiredMark={false}
Expand Down Expand Up @@ -317,6 +304,23 @@ export const SettingsCard = ({
>
<Switch />
</Form.Item>

<Form.Item
name="bot_protect"
label="Activate Public Bot Protection (Beta)"
valuePropName="checked"
tooltip="This will activate the public bot protection using session to avoid misuse of the bot"
>
<Switch />
</Form.Item>

<Form.Item
name="use_rag"
label="Use Retrieval Augmented Generation (RAG)"
valuePropName="checked"
>
<Switch />
</Form.Item>
</div>
</div>

Expand Down
16 changes: 2 additions & 14 deletions app/ui/src/routes/bot/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import api from "../../services/api";
import React from "react";
import { SkeletonLoading } from "../../components/Common/SkeletonLoading";
import { SettingsCard } from "../../components/Bot/Settings/SettingsCard";
import { BotSettings } from "../../@types/bot";

export default function BotSettingsRoot() {
const param = useParams<{ id: string }>();
Expand All @@ -14,19 +15,7 @@ export default function BotSettingsRoot() {
async () => {
const response = await api.get(`/bot/${param.id}`);
return response.data as {
data: {
id: string;
name: string;
model: string;
public_id: string;
temperature: number;
embedding: string;
qaPrompt: string;
questionGeneratorPrompt: string;
streaming: boolean;
showRef: boolean;
use_hybrid_search: boolean;
};
data: BotSettings
};
},
{
Expand All @@ -41,7 +30,6 @@ export default function BotSettingsRoot() {
}, [status]);
return (
<div className="mx-auto my-3 w-full max-w-7xl">

{status === "loading" && <SkeletonLoading />}
{status === "success" && <SettingsCard data={data.data} />}
</div>
Expand Down
75 changes: 38 additions & 37 deletions app/ui/src/services/api.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
import axios from 'axios';
import { getToken } from './cookie';
import axios from "axios";
import { getToken } from "./cookie";

export const baseURL = import.meta.env.VITE_API_URL || '/api/v1';
export const baseURL = import.meta.env.VITE_API_URL || "/api/v1";

const instance = axios.create({
baseURL,
headers: {
"Content-Type": "application/json",
},
baseURL,
headers: {
"Content-Type": "application/json",
},
});

instance.interceptors.request.use(
(config) => {
const token = getToken()
if (token) {
config.headers!.Authorization = `Bearer ${token}`;
}
return config;
},
(error) => {
return Promise.reject(error);
(config) => {
const token = getToken();
if (token) {
config.headers!.Authorization = `Bearer ${token}`;
}
return config;
},
(error) => {
return Promise.reject(error);
},
);

instance.interceptors.response.use(
(res) => {
return res;
},
async (err) => {
const originalConfig = err.config;
if (err.response) {
if (err.response.status === 401 && !originalConfig._retry) {
originalConfig._retry = true;
try {
return instance(originalConfig);
} catch (_error) {

return Promise.reject(_error);
}
}

if (err.response.status === 403 && err.response.data) {
return Promise.reject(err.response.data);
}
(res) => {
return res;
},
async (err) => {
const originalConfig = err.config;
if (err.response) {
if (err.response.status === 401 && !originalConfig._retry) {
originalConfig._retry = true;
try {
return instance(originalConfig);
} catch (_error) {
return Promise.reject(_error);
}
} else if (err.response.status === 401 && originalConfig._retry) {
window.location.href = "/#/login";
}

return Promise.reject(err);
if (err.response.status === 403 && err.response.data) {
return Promise.reject(err.response.data);
}
}

return Promise.reject(err);
},
);

export default instance;
export default instance;
6 changes: 5 additions & 1 deletion docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ GOOGLE_API_KEY=""
# Eleven labs API Key -> https://elevenlabs.io/
ELEVENLABS_API_KEY=""
# Dialoqbase Q Concurency
DB_QUEUE_CONCURRENCY=1
DB_QUEUE_CONCURRENCY=1
# Dialoqbase Session Secret
DB_SESSION_SECRET="super-secret-key"
# Dialoqbase Session Secure
DB_SESSION_SECURE="false"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dialoqbase",
"version": "1.0.4",
"version": "1.1.0",
"description": "Create chatbots with ease",
"scripts": {
"ui:dev": "pnpm run --filter ui dev",
Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"license": "MIT",
"dependencies": {
"@fastify/autoload": "^5.0.0",
"@fastify/cookie": "^9.1.0",
"@fastify/cors": "^8.3.0",
"@fastify/jwt": "^7.0.0",
"@fastify/multipart": "^7.6.0",
Expand Down
8 changes: 8 additions & 0 deletions server/prisma/migrations/q_14/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- AlterTable
ALTER TABLE "Bot" ADD COLUMN "options" JSON DEFAULT '{}',
ADD COLUMN "use_rag" BOOLEAN NOT NULL DEFAULT false;

ALTER TABLE "Bot" ADD COLUMN "bot_protect" BOOLEAN NOT NULL DEFAULT false;


ALTER TABLE "Bot" ADD COLUMN "bot_api_key" TEXT NULL DEFAULT NULL;
14 changes: 9 additions & 5 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ model Bot {
text_to_voice_type_metadata Json @default("{}") @db.Json
use_hybrid_search Boolean @default(false)
haveDataSourcesBeenAdded Boolean @default(false)
use_rag Boolean @default(false)
bot_protect Boolean @default(false)
bot_api_key String?
options Json? @default("{}") @db.Json
BotAppearance BotAppearance[]
document BotDocument[]
BotIntegration BotIntegration[]
Expand Down Expand Up @@ -103,12 +107,12 @@ model BotIntegration {
}

model BotTelegramHistory {
id Int @id @default(autoincrement())
chat_id Int?
id Int @id @default(autoincrement())
chat_id Int?
new_chat_id String?
identifier String?
human String?
bot String?
identifier String?
human String?
bot String?
}

model BotDiscordHistory {
Expand Down
27 changes: 22 additions & 5 deletions server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import cors from "@fastify/cors";
import fastifyStatic from "@fastify/static";
import fastifyMultipart from "@fastify/multipart";
import { FastifySSEPlugin } from "@waylaidwanderer/fastify-sse-v2";
import fastifyCookie from "@fastify/cookie";
import fastifySession from "@fastify/session";
import { getSessionSecret, isCookieSecure } from "./utils/session";

declare module "fastify" {
interface Session {
is_bot_allowed: boolean;
}
}

export type AppOptions = {} & Partial<AutoloadPluginOptions>;

Expand Down Expand Up @@ -40,13 +49,21 @@ const app: FastifyPluginAsync<AppOptions> = async (
preCompressed: true,
});

await fastify.register(import('fastify-raw-body'), {
field: 'rawBody', // change the default request.rawBody property name
fastify.register(fastifyCookie);
fastify.register(fastifySession, {
secret: getSessionSecret(),
cookie: {
secure: isCookieSecure(),
},
});

await fastify.register(import("fastify-raw-body"), {
field: "rawBody", // change the default request.rawBody property name
global: false, // add the rawBody to every request. **Default true**
encoding: 'utf8', // set it to false to set rawBody as a Buffer **Default utf8**
encoding: "utf8", // set it to false to set rawBody as a Buffer **Default utf8**
runFirst: true, // get the body before any preParsing hook change/uncompress it. **Default false**
routes: [] // array of routes, **`global`** will be ignored, wildcard routes not supported
})
routes: [], // array of routes, **`global`** will be ignored, wildcard routes not supported
});
};

export default app;
Expand Down
2 changes: 2 additions & 0 deletions server/src/routes/api/v1/bot/handlers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ export interface UpdateBotById {
streaming: boolean;
showRef: boolean;
use_hybrid_search: boolean;
bot_protect: boolean;
use_rag: boolean;
};
}
Loading

0 comments on commit 087fd28

Please sign in to comment.