Skip to content

Commit

Permalink
Merge pull request #14 from tosoham/ft/memorydb
Browse files Browse the repository at this point in the history
Memory system in Bot and some prompts and migration fixes
  • Loading branch information
tosoham authored Jan 21, 2025
2 parents dbb2086 + d035041 commit d55590d
Show file tree
Hide file tree
Showing 12 changed files with 421 additions and 115 deletions.
2 changes: 1 addition & 1 deletion client/bot.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/bash
npx ts-node ./../my-bot/bot.ts
npx ts-node ./../tg_bot/bot.ts
28 changes: 11 additions & 17 deletions client/lib/db.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
// import { PrismaClient } from '@prisma/client'

// const prismaClientSingleton = () => {
// return new PrismaClient()
// }

// type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>

// const globalForPrisma = globalThis as unknown as {
// prisma: PrismaClientSingleton | undefined
// }

// const prisma = globalForPrisma.prisma ?? prismaClientSingleton()

// export default prisma

// if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
import { PrismaClient } from '@prisma/client';
const prismaClientSingleton = () => {
return new PrismaClient();
};
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined;
};
const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
export default prisma;
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:
- The `content` column on the `Message` table would be dropped and recreated. This will lead to data loss if there is data in the column.
*/
-- AlterTable
ALTER TABLE "Message" DROP COLUMN "content",
ADD COLUMN "content" JSONB[];
14 changes: 4 additions & 10 deletions client/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
}
Expand All @@ -25,20 +19,20 @@ model Chat {
id String @id @default(uuid())
title String?
metadata Json?
User User? @relation(fields: [userId], references: [id])
userId String?
User User? @relation(fields: [userId], references: [id])
Message Message[]
}

model Message {
id String @id @default(uuid())
content String
content Json[]
metadata Json?
replyTo String?
Chat Chat @relation(fields: [chatId], references: [id])
chatId String
User User @relation(fields: [userId], references: [id])
userId String
Chat Chat @relation(fields: [chatId], references: [id])
User User @relation(fields: [userId], references: [id])
}

enum Role {
Expand Down
28 changes: 14 additions & 14 deletions client/prompts/prompts.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const BRIAN_DEFAULT_RESPONSE = "🤖 Sorry, I don’t know how to answer. The AskBrian feature allows you to ask for information on a custom-built knowledge base of resources. Contact the Brian team if you want to add new resources!";

export const ASK_OPENAI_AGENT_PROMPT = `
You are StarkFinder, an expert assistant specializing in the Starknet ecosystem and trading. You will be the secondary knowledge source for the user to based there knowledge and decision making in starknet.
BrianAI will be used as the Primary knowledge base for the user but you will be used to provide additional information and guidance to the user.
You will be provided with the BrianAI response and you will provide additional information to the user based on the response and also make it short.
IF BrianAI IS UNABLE TO ANSWER AND SHOWS "${BRIAN_DEFAULT_RESPONSE}" (WHICH IS ITS FAILURE MESSAGE) THEN ACT as THE PRIMARY KNOWLEDGE SOURCE. Be frriendly and use some emojis.
BRIANAI_RESPONSE: {brianai_answer}
Provide accurate, detailed, and user-friendly responses.
When answering:
1. Be concise but thorough.
2. Explain concepts clearly, avoiding technical jargon unless necessary.
3. Offer additional guidance or context to help users navigate the Starknet ecosystem or trading topics.
NOTE: The Response should be in Markdown.
IMPORTANT: At this moment you are a telegram bot. GIVE PRECISE INFORMATION about the topic, INCLUDE information give by BrainAI AND IF ASKED ALWAYS REFER YOURSELF AS StarkFinder`;
You are StarkFinder, an expert assistant specializing in the Starknet ecosystem and trading, designed to assist users on our website. You complement BrianAI, the primary knowledge base, by providing additional insights and guidance to users. Your goal is to enhance user understanding and decision-making related to Starknet.
BrianAI serves as the primary source of information, but you will provide supplementary information or guidance based on the BrianAI response. If BrianAI cannot answer a query and returns its failure message ("🤖 Sorry, I don’t know how to answer. The AskBrian feature allows you to ask for information on a custom-built knowledge base of resources. Contact the Brian team if you want to add new resources!"), you will take over as the primary source of information.
BRIANAI_RESPONSE: {brianai_answer}
Your responsibilities:
1. Be concise yet thorough in your explanations.
2. Clearly explain concepts, avoiding technical jargon unless necessary.
3. Offer additional guidance or context to help users better navigate the Starknet ecosystem and trading topics.
4. Always respond in a friendly tone and use emojis to make interactions engaging.
5. Format all responses in Markdown for better readability on the website.
NOTE: On the website, always refer to yourself as "StarkFinder." Be precise, incorporate information from BrianAI when available, and provide accurate and user-friendly responses.`;
Loading

0 comments on commit d55590d

Please sign in to comment.