From 198ccf108c55131ee8a0aec69c1aa53531e8c964 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Tue, 5 Mar 2024 16:30:44 +0530 Subject: [PATCH 1/5] Update package versions and add copy bot functionality --- app/ui/package.json | 2 +- .../components/Bot/Settings/SettingsCard.tsx | 60 +- package.json | 2 +- server/prisma/seed.ts | 678 +++++++++--------- .../handlers/api/v1/bot/bot/copy.handler.ts | 110 +++ server/src/handlers/api/v1/bot/bot/index.ts | 3 +- server/src/handlers/api/v1/bot/bot/types.ts | 7 + server/src/routes/api/v1/bot/root.ts | 13 + server/src/schema/api/v1/bot/bot/index.ts | 21 + 9 files changed, 562 insertions(+), 334 deletions(-) create mode 100644 server/src/handlers/api/v1/bot/bot/copy.handler.ts diff --git a/app/ui/package.json b/app/ui/package.json index f206b3bb..e6dc0950 100644 --- a/app/ui/package.json +++ b/app/ui/package.json @@ -1,7 +1,7 @@ { "name": "app", "private": true, - "version": "1.7.4", + "version": "1.7.5", "type": "module", "scripts": { "dev": "vite", diff --git a/app/ui/src/components/Bot/Settings/SettingsCard.tsx b/app/ui/src/components/Bot/Settings/SettingsCard.tsx index 4851ab94..6a56de8a 100644 --- a/app/ui/src/components/Bot/Settings/SettingsCard.tsx +++ b/app/ui/src/components/Bot/Settings/SettingsCard.tsx @@ -55,6 +55,10 @@ export const SettingsCard: React.FC = ({ return response.data; }; + const onCopy = async () => { + const response = await api.post(`/bot/${params.id}/copy`); + return response.data; + }; const { mutate: deleteBot, isLoading: isDeleting } = useMutation(onDelete, { onSuccess: () => { client.invalidateQueries(["getAllBots"]); @@ -80,6 +84,29 @@ export const SettingsCard: React.FC = ({ }, }); + const { mutate: copyBot, isLoading: isCopying } = useMutation(onCopy, { + onSuccess: (data) => { + client.invalidateQueries(["getAllBots"]); + navigate(`/bot/${data.id}`); + notification.success({ + message: "Bot copied 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", + }); + }, + }); + const currentModel = Form.useWatch("model", form); const isStreamingSupported = (model: string) => { @@ -113,7 +140,7 @@ export const SettingsCard: React.FC = ({ {/* centerize the div */} -
+
= ({
+
+
+

+ Make a copy of your bot +

+
+

+ This action will create a new bot with the same settings as this + bot, except for the Integration settings that need to be + reconfigured{" "} +

+
+
+ +
+
+
+

diff --git a/package.json b/package.json index 77e3a876..eb6f6b84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dialoqbase", - "version": "1.7.4", + "version": "1.7.5", "description": "Create chatbots with ease", "scripts": { "ui:dev": "pnpm run --filter ui dev", diff --git a/server/prisma/seed.ts b/server/prisma/seed.ts index 387b2141..0438dcda 100644 --- a/server/prisma/seed.ts +++ b/server/prisma/seed.ts @@ -10,268 +10,286 @@ const LLMS: { local_model?: boolean; config?: string; }[] = [ - { - name: 'GPT-3.5 Turbo (OpenAI)', - model_id: 'gpt-3.5-turbo-dbase', - model_type: 'chat', - model_provider: 'OpenAI', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'GPT-3.5 Turbo 16K (OpenAI)', - model_id: 'gpt-3.5-turbo-16k-dbase', - model_type: 'chat', - model_provider: 'OpenAI', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'GPT-4 (OpenAI)', - model_id: 'gpt-4-dbase', - model_type: 'chat', - model_provider: 'OpenAI', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'GPT-4 0613 (OpenAI)', - model_id: 'gpt-4-0613-dbase', - model_type: 'chat', - model_provider: 'OpenAI', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'GPT-3.5 Turbo Instruct (OpenAI)', - model_id: 'gpt-3.5-turbo-instruct-dbase', - model_type: 'instruct', - model_provider: 'openai-instruct', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Claude 1 (Anthropic)', - model_id: 'claude-1-dbase', - model_type: 'chat', - model_provider: 'Anthropic', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Claude 2 (Anthropic)', - model_id: 'claude-2-dbase', - model_type: 'chat', - model_provider: 'Anthropic', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Claude Instant (Anthropic)', - model_id: 'claude-instant-1-dbase', - model_type: 'chat', - model_provider: 'Anthropic', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Google chat-bison-001', - model_id: 'google-bison-dbase', - model_type: 'chat', - model_provider: 'Google', - stream_available: false, - local_model: false, - config: '{}' - }, - { - name: 'Llama v2 7B (Fireworks)', - model_id: 'accounts/fireworks/models/llama-v2-7b-chat', - model_type: 'chat', - model_provider: 'Fireworks', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Llama v2 13B (Fireworks)', - model_id: 'accounts/fireworks/models/llama-v2-13b-chat', - model_type: 'chat', - model_provider: 'Fireworks', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Llama v2 70B (Fireworks)', - model_id: 'accounts/fireworks/models/llama-v2-70b-chat', - model_type: 'chat', - model_provider: 'Fireworks', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Llama v2 7B Chat int8 (Fireworks)', - model_id: 'accounts/fireworks/models/llama-v2-7b-chat-w8a16', - model_type: 'chat', - model_provider: 'Fireworks', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Llama v2 13B Chat int8 (Fireworks)', - model_id: 'accounts/fireworks/models/llama-v2-13b-chat-w8a16', - model_type: 'chat', - model_provider: 'Fireworks', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Llama v2 13B Code Instruct (Fireworks)', - model_id: 'accounts/fireworks/models/llama-v2-13b-code-instruct', - model_type: 'instruct', - model_provider: 'Fireworks', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Llama v2 34B Code Instruct int8 (Fireworks)', - model_id: 'accounts/fireworks/models/llama-v2-34b-code-instruct-w8a16', - model_type: 'instruct', - model_provider: 'Fireworks', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'Mistral 7B Instruct 4K (Fireworks)', - model_id: 'accounts/fireworks/models/mistral-7b-instruct-4k', - model_type: 'instruct', - model_provider: 'Fireworks', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'GPT-3.5 Turbo 1106 (OpenAI)', - model_id: 'gpt-3.5-turbo-1106-dbase', - model_type: 'chat', - model_provider: 'OpenAI', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'GPT-4 Turbo (OpenAI)', - model_id: 'gpt-4-1106-preview-dbase', - model_type: 'chat', - model_provider: 'OpenAI', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: 'GPT-4 Turbo with vision (OpenAI)', - model_id: 'gpt-4-vision-preview-dbase', - model_type: 'chat', - model_provider: 'OpenAI', - stream_available: true, - local_model: false, - config: '{}' - }, - { - name: "Claude 2.1 (Anthropic)", - model_id: "claude-2.1-dbase", - model_type: "chat", - model_provider: "Anthropic", - stream_available: true, - local_model: false, - config: "{}", - }, - { - name: "Claude Instant 1.2 (Anthropic)", - model_id: "claude-instant-1.2-dbase", - model_type: "chat", - model_provider: "Anthropic", - stream_available: true, - local_model: false, - config: "{}", - }, - { - name: "Yi 34B 200k (Fireworks)", - model_id: "accounts/fireworks/models/yi-34b-200k", - model_type: "instruct", - stream_available: true, - model_provider: "Fireworks", - local_model: false, - config: "{}", - }, - { - model_id: "accounts/fireworks/models/yi-34b-200k-capybara", - name: "Capybara 34B (Fireworks)", - model_type: "chat", - stream_available: true, - model_provider: "Fireworks", - local_model: false, - config: "{}", - }, - { - model_id: "accounts/fireworks/models/zephyr-7b-beta", - name: "Zephyr 7B Beta (Fireworks)", - model_type: "instruct", - stream_available: true, - model_provider: "Fireworks", - local_model: false, - config: "{}", - }, - { - model_id: "accounts/fireworks/models/mixtral-8x7b-instruct", - name: "Mixtral MoE 8x7B Instruct (Fireworks)", - model_type: "instruct", - stream_available: true, - model_provider: "Fireworks", - local_model: false, - config: "{}", - }, - { - model_id: "gemini-pro", - name: "Gemini Pro (Google)", - model_type: "chat", - stream_available: false, - model_provider: "Google", - local_model: false, - config: "{}", - }, - { - model_id: "accounts/fireworks/models/qwen-72b-chat", - name: "Qwen 72b chat (Fireworks)", - model_type: "chat", - stream_available: true, - model_provider: "Fireworks", - local_model: false, - config: "{}", - }, - { - model_id: "gpt-3.5-turbo-0125-dbase", - name: "GPT-3.5 Turbo 0125 (OpenAI)", - model_type: "chat", - stream_available: true, - model_provider: "OpenAI", - local_model: false, - config: "{}", - }, -]; + { + name: 'GPT-3.5 Turbo (OpenAI)', + model_id: 'gpt-3.5-turbo-dbase', + model_type: 'chat', + model_provider: 'OpenAI', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'GPT-3.5 Turbo 16K (OpenAI)', + model_id: 'gpt-3.5-turbo-16k-dbase', + model_type: 'chat', + model_provider: 'OpenAI', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'GPT-4 (OpenAI)', + model_id: 'gpt-4-dbase', + model_type: 'chat', + model_provider: 'OpenAI', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'GPT-4 0613 (OpenAI)', + model_id: 'gpt-4-0613-dbase', + model_type: 'chat', + model_provider: 'OpenAI', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'GPT-3.5 Turbo Instruct (OpenAI)', + model_id: 'gpt-3.5-turbo-instruct-dbase', + model_type: 'instruct', + model_provider: 'openai-instruct', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Claude 1 (Anthropic)', + model_id: 'claude-1-dbase', + model_type: 'chat', + model_provider: 'Anthropic', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Claude 2 (Anthropic)', + model_id: 'claude-2-dbase', + model_type: 'chat', + model_provider: 'Anthropic', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Claude Instant (Anthropic)', + model_id: 'claude-instant-1-dbase', + model_type: 'chat', + model_provider: 'Anthropic', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Google chat-bison-001', + model_id: 'google-bison-dbase', + model_type: 'chat', + model_provider: 'Google', + stream_available: false, + local_model: false, + config: '{}' + }, + { + name: 'Llama v2 7B (Fireworks)', + model_id: 'accounts/fireworks/models/llama-v2-7b-chat', + model_type: 'chat', + model_provider: 'Fireworks', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Llama v2 13B (Fireworks)', + model_id: 'accounts/fireworks/models/llama-v2-13b-chat', + model_type: 'chat', + model_provider: 'Fireworks', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Llama v2 70B (Fireworks)', + model_id: 'accounts/fireworks/models/llama-v2-70b-chat', + model_type: 'chat', + model_provider: 'Fireworks', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Llama v2 7B Chat int8 (Fireworks)', + model_id: 'accounts/fireworks/models/llama-v2-7b-chat-w8a16', + model_type: 'chat', + model_provider: 'Fireworks', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Llama v2 13B Chat int8 (Fireworks)', + model_id: 'accounts/fireworks/models/llama-v2-13b-chat-w8a16', + model_type: 'chat', + model_provider: 'Fireworks', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Llama v2 13B Code Instruct (Fireworks)', + model_id: 'accounts/fireworks/models/llama-v2-13b-code-instruct', + model_type: 'instruct', + model_provider: 'Fireworks', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Llama v2 34B Code Instruct int8 (Fireworks)', + model_id: 'accounts/fireworks/models/llama-v2-34b-code-instruct-w8a16', + model_type: 'instruct', + model_provider: 'Fireworks', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'Mistral 7B Instruct 4K (Fireworks)', + model_id: 'accounts/fireworks/models/mistral-7b-instruct-4k', + model_type: 'instruct', + model_provider: 'Fireworks', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'GPT-3.5 Turbo 1106 (OpenAI)', + model_id: 'gpt-3.5-turbo-1106-dbase', + model_type: 'chat', + model_provider: 'OpenAI', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'GPT-4 Turbo (OpenAI)', + model_id: 'gpt-4-1106-preview-dbase', + model_type: 'chat', + model_provider: 'OpenAI', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: 'GPT-4 Turbo with vision (OpenAI)', + model_id: 'gpt-4-vision-preview-dbase', + model_type: 'chat', + model_provider: 'OpenAI', + stream_available: true, + local_model: false, + config: '{}' + }, + { + name: "Claude 2.1 (Anthropic)", + model_id: "claude-2.1-dbase", + model_type: "chat", + model_provider: "Anthropic", + stream_available: true, + local_model: false, + config: "{}", + }, + { + name: "Claude Instant 1.2 (Anthropic)", + model_id: "claude-instant-1.2-dbase", + model_type: "chat", + model_provider: "Anthropic", + stream_available: true, + local_model: false, + config: "{}", + }, + { + name: "Yi 34B 200k (Fireworks)", + model_id: "accounts/fireworks/models/yi-34b-200k", + model_type: "instruct", + stream_available: true, + model_provider: "Fireworks", + local_model: false, + config: "{}", + }, + { + model_id: "accounts/fireworks/models/yi-34b-200k-capybara", + name: "Capybara 34B (Fireworks)", + model_type: "chat", + stream_available: true, + model_provider: "Fireworks", + local_model: false, + config: "{}", + }, + { + model_id: "accounts/fireworks/models/zephyr-7b-beta", + name: "Zephyr 7B Beta (Fireworks)", + model_type: "instruct", + stream_available: true, + model_provider: "Fireworks", + local_model: false, + config: "{}", + }, + { + model_id: "accounts/fireworks/models/mixtral-8x7b-instruct", + name: "Mixtral MoE 8x7B Instruct (Fireworks)", + model_type: "instruct", + stream_available: true, + model_provider: "Fireworks", + local_model: false, + config: "{}", + }, + { + model_id: "gemini-pro", + name: "Gemini Pro (Google)", + model_type: "chat", + stream_available: false, + model_provider: "Google", + local_model: false, + config: "{}", + }, + { + model_id: "accounts/fireworks/models/qwen-72b-chat", + name: "Qwen 72b chat (Fireworks)", + model_type: "chat", + stream_available: true, + model_provider: "Fireworks", + local_model: false, + config: "{}", + }, + { + model_id: "gpt-3.5-turbo-0125-dbase", + name: "GPT-3.5 Turbo 0125 (OpenAI)", + model_type: "chat", + stream_available: true, + model_provider: "OpenAI", + local_model: false, + config: "{}", + }, + // { + // name: "Claude 3 Opus 20240229 (Anthropic)", + // model_id: "claude-3-opus-20240229-dbase", + // model_type: "chat", + // model_provider: "Anthropic", + // stream_available: true, + // local_model: false, + // config: "{}", + // }, + // { + // name: "Claude 3 Sonnet 20240229 (Anthropic)", + // model_id: "claude-3-sonnet-20240229-dbase", + // model_type: "chat", + // model_provider: "Anthropic", + // stream_available: true, + // local_model: false, + // config: "{}", + // }, + ]; const EMBEDDING_MODELS: { name: string; @@ -282,73 +300,73 @@ const EMBEDDING_MODELS: { local_model?: boolean; config?: string; }[] = [ - { - model_id: "dialoqbase_eb_text-embedding-ada-002", - name: "text-embedding-ada-002", - model_provider: "OpenAI", - model_type: "embedding", - }, - { - model_id: "dialoqbase_eb_small", - name: "Cohere", - model_provider: "Cohere", - model_type: "embedding", - }, - { - model_id: "dialoqbase_eb_Xenova/all-MiniLM-L6-v2", - name: "all-MiniLM-L6-v2 (cpu)", - model_type: "embedding", - model_provider: "Transformer", - }, - { - model_id: "dialoqbase_eb_dialoqbase-ollama", - name: "Ollama Embeddings", - model_type: "embedding", - model_provider: "Ollama", - }, - { - model_id: "dialoqbase_eb_models/embedding-gecko-001", - name: "Google text-gecko-001", - model_type: "embedding", - model_provider: "Google PaLM", - }, - { - model_id: "dialoqbase_eb_jina-embeddings-v2-base-en", - name: "jina-embeddings-v2-base-en (API)", - model_type: "embedding", - model_provider: "Jina", - }, - { - model_id: "dialoqbase_eb_Xenova/jina-embeddings-v2-small-en", - name: "jina-embeddings-v2-small-en (cpu)", - model_type: "embedding", - model_provider: "Transformer", - }, - { - model_id: "dialoqbase_eb_embedding-001", - name: "Google embedding-001", - model_type: "embedding", - model_provider: "Google", - }, - { - model_id: "dialoqbase_eb_text-embedding-3-small", - name: "text-embedding-3-small (OpenAI)", - model_type: "embedding", - model_provider: "OpenAI", - }, - { - model_id: "dialoqbase_eb_text-embedding-3-large", - name: "text-embedding-3-large (OpenAI)", - model_type: "embedding", - model_provider: "OpenAI", - }, - { - model_provider: "Fireworks", - model_type: "embedding", - model_id: "dialoqbase_eb_nomic-ai/nomic-embed-text-v1.5", - name: "nomic-ai/nomic-embed-text-v1.5 (Fireworks)", - } -]; + { + model_id: "dialoqbase_eb_text-embedding-ada-002", + name: "text-embedding-ada-002", + model_provider: "OpenAI", + model_type: "embedding", + }, + { + model_id: "dialoqbase_eb_small", + name: "Cohere", + model_provider: "Cohere", + model_type: "embedding", + }, + { + model_id: "dialoqbase_eb_Xenova/all-MiniLM-L6-v2", + name: "all-MiniLM-L6-v2 (cpu)", + model_type: "embedding", + model_provider: "Transformer", + }, + { + model_id: "dialoqbase_eb_dialoqbase-ollama", + name: "Ollama Embeddings", + model_type: "embedding", + model_provider: "Ollama", + }, + { + model_id: "dialoqbase_eb_models/embedding-gecko-001", + name: "Google text-gecko-001", + model_type: "embedding", + model_provider: "Google PaLM", + }, + { + model_id: "dialoqbase_eb_jina-embeddings-v2-base-en", + name: "jina-embeddings-v2-base-en (API)", + model_type: "embedding", + model_provider: "Jina", + }, + { + model_id: "dialoqbase_eb_Xenova/jina-embeddings-v2-small-en", + name: "jina-embeddings-v2-small-en (cpu)", + model_type: "embedding", + model_provider: "Transformer", + }, + { + model_id: "dialoqbase_eb_embedding-001", + name: "Google embedding-001", + model_type: "embedding", + model_provider: "Google", + }, + { + model_id: "dialoqbase_eb_text-embedding-3-small", + name: "text-embedding-3-small (OpenAI)", + model_type: "embedding", + model_provider: "OpenAI", + }, + { + model_id: "dialoqbase_eb_text-embedding-3-large", + name: "text-embedding-3-large (OpenAI)", + model_type: "embedding", + model_provider: "OpenAI", + }, + { + model_provider: "Fireworks", + model_type: "embedding", + model_id: "dialoqbase_eb_nomic-ai/nomic-embed-text-v1.5", + name: "nomic-ai/nomic-embed-text-v1.5 (Fireworks)", + } + ]; const newModels = async () => { console.log("Seeding new models..."); @@ -430,7 +448,7 @@ const replaceOldEmbeddings = async () => { embedding: "dialoqbase_eb_jina-embeddings-v2-base-en", }, }) - + await prisma.bot.updateMany({ where: { embedding: "jina", diff --git a/server/src/handlers/api/v1/bot/bot/copy.handler.ts b/server/src/handlers/api/v1/bot/bot/copy.handler.ts new file mode 100644 index 00000000..64e88347 --- /dev/null +++ b/server/src/handlers/api/v1/bot/bot/copy.handler.ts @@ -0,0 +1,110 @@ +import { FastifyRequest, FastifyReply } from "fastify"; +import { GetBotById } from "./types"; +import { generateAPIKey } from "../../../../../utils/api"; + + +export const createCopyHandler = async ( + request: FastifyRequest, + reply: FastifyReply +) => { + const prisma = request.server.prisma; + const bot_id = request.params.bot_id; + + const bot = await prisma.bot.findFirst({ + where: { + id: bot_id, + user_id: request.user.user_id, + }, + include: { + BotAppearance: true, + source: true, + } + }); + + if (!bot) { + return reply.status(404).send({ + message: "Bot not found", + }); + } + + + if(process.env.DB_COPY_BOT_DISABLED === "true") { + return reply.status(400).send({ + message: "Bot copying is disabled", + }); + } + + let bot_api_key: string | undefined + + if (bot.bot_api_key) { + bot_api_key = generateAPIKey() + } + + + + const newBot = await prisma.bot.create({ + data: { + name: `${bot.name} - Copy`, + temperature: bot.temperature, + model: bot.model, + bot_protect: bot.bot_protect, + description: bot.description, + options: bot.options || {}, + embedding: bot.embedding, + provider: bot.provider, + qaPrompt: bot.qaPrompt, + questionGeneratorPrompt: bot.questionGeneratorPrompt, + showRef: bot.showRef, + voice_to_text_type: bot.voice_to_text_type, + haveDataSourcesBeenAdded: bot.haveDataSourcesBeenAdded, + use_rag: bot.use_rag, + user_id: request.user.user_id, + text_to_voice_enabled: bot.text_to_voice_enabled, + text_to_voice_type: bot.text_to_voice_type, + streaming: bot.streaming, + text_to_voice_type_metadata: bot.text_to_voice_type_metadata || {}, + use_hybrid_search: bot.use_hybrid_search, + bot_api_key, + bot_model_api_key: bot.bot_model_api_key, + BotAppearance: { + createMany: { + data: bot.BotAppearance.map((appearance) => { + return { + bot_name: appearance.bot_name, + first_message: appearance.first_message, + background_color: appearance.background_color, + chat_bot_bubble_style: appearance.chat_bot_bubble_style || {}, + chat_human_bubble_style: appearance.chat_human_bubble_style || {}, + id: undefined, + } + }) + } + } + } + }) + + for (const source of bot.source) { + const newSource = await prisma.botSource.create({ + data: { + botId: newBot.id, + content: source.content, + type: source.type, + location: source.location, + options: source.options || {}, + status: source.status, + isPending: false, + } + }) + + await prisma.$executeRaw`INSERT INTO "BotDocument" ("sourceId", "content", "embedding", "metadata", "botId") + SELECT ${newSource.id}, content, embedding::vector, metadata, ${newBot.id} + FROM "BotDocument" + WHERE "sourceId" = ${source.id};` + } + + + return { + message: "Bot copied successfully", + id: newBot.id, + } +} \ No newline at end of file diff --git a/server/src/handlers/api/v1/bot/bot/index.ts b/server/src/handlers/api/v1/bot/bot/index.ts index ebf543b9..c3d832b2 100644 --- a/server/src/handlers/api/v1/bot/bot/index.ts +++ b/server/src/handlers/api/v1/bot/bot/index.ts @@ -2,4 +2,5 @@ export * from "./post.handler"; export * from "./get.handler"; export * from "./upload.handler"; export * from "./delete.handler"; -export * from "./put.handler"; \ No newline at end of file +export * from "./put.handler"; +export * from "./copy.handler"; \ No newline at end of file diff --git a/server/src/handlers/api/v1/bot/bot/types.ts b/server/src/handlers/api/v1/bot/bot/types.ts index a202aec3..407cbf35 100644 --- a/server/src/handlers/api/v1/bot/bot/types.ts +++ b/server/src/handlers/api/v1/bot/bot/types.ts @@ -69,3 +69,10 @@ export interface UpdateBotById { bot_model_api_key: string }; } + + +export interface GetBotById { + Params: { + bot_id: string; + }; +} \ No newline at end of file diff --git a/server/src/routes/api/v1/bot/root.ts b/server/src/routes/api/v1/bot/root.ts index e6e4f11d..71def82f 100644 --- a/server/src/routes/api/v1/bot/root.ts +++ b/server/src/routes/api/v1/bot/root.ts @@ -14,12 +14,14 @@ import { updateBotByIdHandler, getCreateBotConfigHandler, getBotByIdSettingsHandler, + createCopyHandler } from "../../../../handlers/api/v1/bot/bot"; import { addNewSourceByIdSchema, createBotSchema, getBotByIdSchema, updateBotByIdSchema, + createCopyBotSchema } from "../../../../schema/api/v1/bot/bot"; const root: FastifyPluginAsync = async (fastify, _): Promise => { @@ -194,6 +196,17 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { }, getBotByIdSettingsHandler ); + + + // create copy bot + fastify.post( + "/:bot_id/copy", + { + schema: createCopyBotSchema, + onRequest: [fastify.authenticate], + }, + createCopyHandler + ); }; export default root; diff --git a/server/src/schema/api/v1/bot/bot/index.ts b/server/src/schema/api/v1/bot/bot/index.ts index 081797f6..a2675910 100644 --- a/server/src/schema/api/v1/bot/bot/index.ts +++ b/server/src/schema/api/v1/bot/bot/index.ts @@ -163,3 +163,24 @@ export const updateBotByIdSchema: FastifySchema = { }, }, }; + + +export const createCopyBotSchema: FastifySchema = { + tags: ["Bot"], + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, + params: { + type: "object", + required: ["bot_id"], + properties: { + bot_id: { + type: "string", + }, + }, + }, +}; \ No newline at end of file From 5f6a0ed7496415e42733586e6bd0d7d6c3681584 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Tue, 5 Mar 2024 19:44:13 +0530 Subject: [PATCH 2/5] Add typing indicator to form --- app/ui/src/components/Bot/Playground/Form.tsx | 14 ++++++++++---- app/widget/src/components/BotForm.tsx | 11 ++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/ui/src/components/Bot/Playground/Form.tsx b/app/ui/src/components/Bot/Playground/Form.tsx index 2853062b..e8cdfcba 100644 --- a/app/ui/src/components/Bot/Playground/Form.tsx +++ b/app/ui/src/components/Bot/Playground/Form.tsx @@ -1,7 +1,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; import { useMessage } from "../../../hooks/useMessage"; import { useForm } from "@mantine/form"; -import React from "react"; +import React, { useState } from "react"; import { useStoreMessage } from "../../../store"; import { useSpeechRecognition } from "../../../hooks/useSpeechRecognition"; import { Tooltip } from "antd"; @@ -19,6 +19,7 @@ export const PlaygroundgForm = () => { const client = useQueryClient(); const textareaRef = React.useRef(null); + const [typing, setTyping] = useState(false); const { defaultSpeechToTextLanguage, @@ -69,8 +70,6 @@ export const PlaygroundgForm = () => { form.setFieldValue("message", transcript); }, [transcript]); - - const { mutateAsync: sendMessage, isLoading: isSending } = useMutation( onSubmit, { @@ -101,7 +100,12 @@ export const PlaygroundgForm = () => {