Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.8.2 #256

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.8.1",
"version": "1.8.2",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
1 change: 1 addition & 0 deletions app/ui/src/@types/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type BotSettings = {
public_id: string;
temperature: number;
embedding: string;
noOfDocumentsToRetrieve: number;
qaPrompt: string;
questionGeneratorPrompt: string;
streaming: boolean;
Expand Down
44 changes: 41 additions & 3 deletions app/ui/src/components/Bot/Settings/SettingsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Form, Input, notification, Select, Slider, Switch } from "antd";
import {
Form,
Input,
InputNumber,
notification,
Select,
Slider,
Switch,
} from "antd";
import { useNavigate, useParams } from "react-router-dom";
import api from "../../../services/api";
import { useMutation, useQueryClient } from "@tanstack/react-query";
Expand Down Expand Up @@ -155,6 +163,7 @@ export const SettingsCard: React.FC<BotSettings> = ({
bot_protect: data.bot_protect,
use_rag: data.use_rag,
bot_model_api_key: data.bot_model_api_key,
noOfDocumentsToRetrieve: data.noOfDocumentsToRetrieve,
}}
form={form}
requiredMark={false}
Expand Down Expand Up @@ -252,14 +261,43 @@ export const SettingsCard: React.FC<BotSettings> = ({
/>
</Form.Item>

<Form.Item label={"Embedding Method"} name="embedding">
<Form.Item
label={"Embedding Method"}
name="embedding"
help={
<>
<p className="text-xs text-gray-500 dark:text-gray-400">
If you change the embedding method, make sure to
re-fetch the data source or choose a model with the same
dimensions
</p>
</>
}
>
<Select
disabled
placeholder="Select an embedding method"
options={embeddingModel}
/>
</Form.Item>

<Form.Item
name="noOfDocumentsToRetrieve"
label="Number of documents to retrieve"
rules={[
{
required: true,
message:
"Please input a number of documents to retrieve!",
},
]}
>
<InputNumber
min={0}
style={{ width: "100%" }}
placeholder="Enter number of documents to retrieve"
/>
</Form.Item>

<Form.Item
label={"Question Answering Prompt (System Prompt)"}
name="qaPrompt"
Expand Down
4 changes: 3 additions & 1 deletion app/ui/src/components/Dashboard/DashboardGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export const DashboardGrid = () => {
<div className="w-full">
<div className="flex items-end justify-between">
<span className="text-xs lowercase text-scale-1000 text-gray-600 dark:text-gray-400">
{bot.model.replace("-dbase", "")}
{bot.model
.replace("-dbase", "")
.replace(/_dialoqbase_[0-9]+$/, "")}
</span>
</div>
</div>
Expand Down
82 changes: 79 additions & 3 deletions app/ui/src/routes/settings/application.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Form, InputNumber, Switch, notification, Select } from "antd";
import { Form, InputNumber, Switch, notification, Select, Input } from "antd";
import React from "react";
import api from "../../services/api";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
Expand All @@ -25,6 +25,9 @@ export default function SettingsApplicationRoot() {
defaultChunkOverlap: number;
defaultChatModel: string;
defaultEmbeddingModel: string;
hideDefaultModels: boolean;
dynamicallyFetchOllamaModels: boolean;
ollamaURL: string;
};
});

Expand Down Expand Up @@ -63,6 +66,22 @@ export default function SettingsApplicationRoot() {
}
);

const { mutateAsync: updateModelSettings, isLoading: isModelLoading } =
useMutation(onUpdateApplicatoon, {
onSuccess: (data) => {
queryClient.invalidateQueries(["fetchBotCreateConfig"]);
notification.success({
message: "Success",
description: data.message,
});
},
onError: (error: any) => {
notification.error({
message: "Error",
description: error?.response?.data?.message || "Something went wrong",
});
},
});
const { mutateAsync: updateRagSettings, isLoading: isRagLoading } =
useMutation(onRagApplicationUpdate, {
onSuccess: (data) => {
Expand Down Expand Up @@ -135,6 +154,33 @@ export default function SettingsApplicationRoot() {
>
<Switch />
</Form.Item>
</div>
<div className="bg-gray-50 border-x border-b rounded-b-md rounded-x-md px-4 py-3 text-right sm:px-6 dark:bg-[#141414] dark:border-gray-600">
<button
disabled={isLoading}
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>
</ApplicationCard>

<ApplicationCard
title="Models Settings"
description="Configure your models settings"
>
<Form
initialValues={{
...data,
}}
layout="vertical"
onFinish={updateModelSettings}
>
<div className="sm:overflow-hidden ">
<div className="space-y-6 border-t border rounded-t-md bg-white px-4 py-5 sm:p-6 dark:bg-[#171717] dark:border-gray-600">
<Form.Item
label="Default Chat Model"
name="defaultChatModel"
Expand Down Expand Up @@ -195,19 +241,49 @@ export default function SettingsApplicationRoot() {
loading={modeStatus === "loading"}
/>
</Form.Item>
<Form.Item
label="Ollama URL"
name="ollamaURL"
rules={[
{
required: true,
message: "Please input ollama url!",
},
]}
>
<Input size="large" placeholder="Enter ollama url" />
</Form.Item>

<Form.Item
label="Hide Default Models"
name="hideDefaultModels"
valuePropName="checked"
help="This will hide all the default models and only show the models that are locally added or from ollama."
>
<Switch />
</Form.Item>
<Form.Item
label="Dynamically Fetch Ollama Models"
name="dynamicallyFetchOllamaModels"
valuePropName="checked"
help="This will dynamically fetch the models from ollama. You don't need to manually add the models."
>
<Switch />
</Form.Item>
</div>
<div className="bg-gray-50 border-x border-b rounded-b-md rounded-x-md px-4 py-3 text-right sm:px-6 dark:bg-[#141414] dark:border-gray-600">
<button
disabled={isLoading}
disabled={isModelLoading}
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"}
{isModelLoading ? "Saving..." : "Save"}
</button>
</div>
</div>
</Form>
</ApplicationCard>

<ApplicationCard
title="RAG Settings"
description="Configure your RAG settings"
Expand Down
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.8.1",
"version": "1.8.2",
"description": "Create chatbots with ease",
"scripts": {
"ui:dev": "pnpm run --filter ui dev",
Expand Down
2 changes: 2 additions & 0 deletions server/prisma/migrations/q_12_3/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "DialoqbaseSettings" ADD COLUMN "ollamaURL" TEXT DEFAULT 'http://host.docker.internal:11434';
2 changes: 2 additions & 0 deletions server/prisma/migrations/q_26/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Bot" ADD COLUMN "noOfDocumentsToRetrieve" INTEGER DEFAULT 4;
2 changes: 2 additions & 0 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ model Bot {
description String?
createdAt DateTime @default(now())
temperature Float @default(0.7)
noOfDocumentsToRetrieve Int? @default(4)
model String @default("gpt-3.5-turbo")
provider String @default("openai")
embedding String @default("openai")
Expand Down Expand Up @@ -95,6 +96,7 @@ model DialoqbaseSettings {
hideDefaultModels Boolean? @default(false)
defaultChatModel String @default("gpt-3.5-turbo-dbase")
defaultEmbeddingModel String @default("dialoqbase_eb_text-embedding-ada-002")
ollamaURL String? @default("http://host.docker.internal:11434")
}

model BotIntegration {
Expand Down
35 changes: 22 additions & 13 deletions server/src/handlers/api/v1/admin/model.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "./type";
import axios from "axios";
import { removeTrailingSlash } from "../../../../utils/url";
import { getSettings } from "../../../../utils/common";

const _getModelFromUrl = async (url: string, apiKey?: string) => {
try {
Expand Down Expand Up @@ -130,21 +131,29 @@ export const getAllModelsHandler = async (
request: FastifyRequest,
reply: FastifyReply
) => {
try {
const prisma = request.server.prisma;
const user = request.user;
const prisma = request.server.prisma;
const user = request.user;

if (!user.is_admin) {
return reply.status(403).send({
message: "Forbidden",
});
}
const allModels = await prisma.dialoqbaseModels.findMany({
where: {
deleted: false,
},
if (!user.is_admin) {
return reply.status(403).send({
message: "Forbidden",
});
}

const settings = await getSettings(prisma);

const not_to_hide_providers = settings?.hideDefaultModels
? [ "Local", "local", "ollama", "transformer", "Transformer"]
: undefined;
const allModels = await prisma.dialoqbaseModels.findMany({
where: {
deleted: false,
model_provider: {
in: not_to_hide_providers,
},
},
});
try {
return {
data: allModels.filter((model) => model.model_type !== "embedding"),
embedding: allModels.filter((model) => model.model_type === "embedding"),
Expand Down Expand Up @@ -245,7 +254,7 @@ export const saveModelFromInputedUrlHandler = async (
});
}

let newModelId = model_id.trim() + `_custom_${new Date().getTime()}`;
let newModelId = model_id.trim() + `_dialoqbase_${new Date().getTime()}`;
await prisma.dialoqbaseModels.create({
data: {
name: isModelExist.name,
Expand Down
36 changes: 10 additions & 26 deletions server/src/handlers/api/v1/bot/bot/api.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
uniqueNamesGenerator,
} from "unique-names-generator";
import { validateDataSource } from "../../../../../utils/datasource-validation";
import { getModelInfo } from "../../../../../utils/get-model-info";

export const createBotAPIHandler = async (
request: FastifyRequest<CreateBotAPIRequest>,
Expand Down Expand Up @@ -55,19 +56,11 @@ export const createBotAPIHandler = async (
message: `Reach maximum limit of ${maxBotsAllowed} bots per user`,
});
}
const modelInfo = await prisma.dialoqbaseModels.findFirst({
where: {
hide: false,
deleted: false,
OR: [
{
model_id: model,
},
{
model_id: `${model}-dbase`,
},
],
},

const modelInfo = await getModelInfo({
model,
prisma,
type: "chat",
});

if (!modelInfo) {
Expand All @@ -76,19 +69,10 @@ export const createBotAPIHandler = async (
});
}

const embeddingInfo = await prisma.dialoqbaseModels.findFirst({
where: {
OR: [
{
model_id: embedding,
},
{
model_id: `dialoqbase_eb_${embedding}`,
},
],
hide: false,
deleted: false,
},
const embeddingInfo = await getModelInfo({
model: embedding,
prisma,
type: "embedding",
});

if (!embeddingInfo) {
Expand Down
Loading