Skip to content

Commit

Permalink
chore: Update package.json with date-fns dependency version 3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
n4ze3m committed Jul 25, 2024
1 parent d01a9fa commit 1277b30
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"concurrently": "^7.0.0",
"copyfiles": "^2.4.1",
"d3-dsv": "2",
"date-fns": "^3.6.0",
"discord.js": "^14.11.0",
"fastify": "^4.26.2",
"fastify-cli": "6.1.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "Bot" ADD COLUMN "autoResetSession" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "inactivityTimeout" INTEGER DEFAULT 3600;
2 changes: 2 additions & 0 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ model Bot {
embedding String @default("openai")
streaming Boolean @default(false)
showRef Boolean @default(false)
inactivityTimeout Int? @default(3600)
autoResetSession Boolean @default(false)
questionGeneratorPrompt String @default("Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question. Chat History: {chat_history} Follow Up Input: {question} Standalone question:")
qaPrompt String @default("You are a helpful AI assistant. Use the following pieces of context to answer the question at the end. If you don't know the answer, just say you don't know. DO NOT try to make up an answer. If the question is not related to the context, politely respond that you are tuned to only answer questions that are related to the context. {context} Question: {question} Helpful answer in markdown:")
voice_to_text_type String @default("web_api")
Expand Down
13 changes: 13 additions & 0 deletions server/src/integration/handlers/discord.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Document } from "langchain/document";
import { BaseRetriever } from "@langchain/core/retrievers";
import { createChain } from "../../chain";
import { getModelInfo } from "../../utils/get-model-info";
import { differenceInSeconds } from "date-fns";
const prisma = new PrismaClient();

export const discordBotHandler = async (
Expand Down Expand Up @@ -48,6 +49,18 @@ export const discordBotHandler = async (
if (history.length > 20) {
history.splice(0, history.length - 20);
}
const lastMessageTimestamp = chat_history[chat_history.length - 1]?.createdAt || new Date().toISOString();

const inactivityPeriod = differenceInSeconds(
new Date(),
lastMessageTimestamp
);

if (bot.autoResetSession) {
if (inactivityPeriod > bot.inactivityTimeout) {
history = [];
}
}

const temperature = bot.temperature;

Expand Down
18 changes: 17 additions & 1 deletion server/src/integration/handlers/telegram.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { DialoqbaseHybridRetrival } from "../../utils/hybrid";
import { BaseRetriever } from "@langchain/core/retrievers";
import { createChain } from "../../chain";
import { getModelInfo } from "../../utils/get-model-info";
import { differenceInSeconds } from 'date-fns';

const prisma = new PrismaClient();

export const telegramBotHandler = async (
Expand Down Expand Up @@ -44,6 +46,20 @@ export const telegramBotHandler = async (
history.splice(0, history.length - 20);
}

const lastMessageTimestamp = chat_history[chat_history.length - 1]?.createdAt || new Date().toISOString();

const inactivityPeriod = differenceInSeconds(
new Date(),
lastMessageTimestamp
);

if (bot.autoResetSession) {
if (inactivityPeriod > bot.inactivityTimeout) {
history = [];
}
}


const temperature = bot.temperature;

const sanitizedQuestion = message.trim().replaceAll("\n", " ");
Expand Down Expand Up @@ -87,7 +103,7 @@ export const telegramBotHandler = async (
prisma,
type: "chat",
});

if (!modelinfo) {
return "Unable to find model";
}
Expand Down
15 changes: 15 additions & 0 deletions server/src/integration/handlers/whatsapp.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BaseRetriever } from "@langchain/core/retrievers";
import { DialoqbaseHybridRetrival } from "../../utils/hybrid";
import { createChain } from "../../chain";
import { getModelInfo } from "../../utils/get-model-info";
import { differenceInSeconds } from "date-fns";
const prisma = new PrismaClient();

export const whatsappBotHandler = async (
Expand Down Expand Up @@ -53,6 +54,20 @@ export const whatsappBotHandler = async (
ai: message.bot,
}));

const lastMessageTimestamp = chat_history[chat_history.length - 1]?.createdAt || new Date().toISOString();

const inactivityPeriod = differenceInSeconds(
new Date(),
lastMessageTimestamp
);

if (bot.autoResetSession) {
if (inactivityPeriod > bot.inactivityTimeout) {
history = [];
}
}


const temperature = bot.temperature;

const sanitizedQuestion = message.trim().replaceAll("\n", " ");
Expand Down
5 changes: 5 additions & 0 deletions server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,11 @@ date-fns@^2.29.1:
dependencies:
"@babel/runtime" "^7.21.0"

date-fns@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-3.6.0.tgz#f20ca4fe94f8b754951b24240676e8618c0206bf"
integrity sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==

dateformat@^4.6.3:
version "4.6.3"
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-4.6.3.tgz#556fa6497e5217fedb78821424f8a1c22fa3f4b5"
Expand Down

0 comments on commit 1277b30

Please sign in to comment.