Add initial project structure with configuration, utilities, and API endpoints

This commit is contained in:
2025-02-07 19:24:57 +06:00
parent 480f6f06c2
commit 87e7b99daa
21 changed files with 513 additions and 159 deletions
+71 -22
View File
@@ -1,42 +1,91 @@
from langchain.retrievers import ContextualCompressionRetriever
from langchain.retrievers.document_compressors import CrossEncoderReranker
from langchain_community.cross_encoders import HuggingFaceCrossEncoder
from langchain_groq import ChatGroq
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough
from chroma_manager import ChromaManager
from config import RERANKER_NAME, GROQ_MODEL, GROQ_API_KEY
from config import settings
from utils import CustomEmbeddings, CustomCrossEncoder
from langchain_chroma import Chroma
class RAGSystem:
def __init__(self):
self.chroma_manager = ChromaManager()
self.embeddings = CustomEmbeddings(settings.MODEL_NAME)
self.reranker = CrossEncoderReranker(
model=CustomCrossEncoder(settings.RERANKER_NAME),
top_n=5
)
self.vector_store = Chroma(
collection_name=settings.COLLECTION_NAME,
persist_directory=settings.CHROMA_PATH,
embedding_function=self.embeddings
)
self.retriever = ContextualCompressionRetriever(
base_compressor=self.reranker,
base_retriever=self.vector_store.as_retriever(search_kwargs={"k": 10})
)
self.llm = ChatGroq(
temperature=0.01,
groq_api_key=GROQ_API_KEY,
model_name=GROQ_MODEL
groq_api_key=settings.GROQ_API_KEY,
model_name=settings.GROQ_MODEL
)
self._init_retriever()
self._init_chain()
def _init_retriever(self):
model = HuggingFaceCrossEncoder(model_name=RERANKER_NAME)
reranker = CrossEncoderReranker(model=model, top_n=5)
self.retriever = ContextualCompressionRetriever(
base_compressor=reranker,
base_retriever=self.chroma_manager.vector_store.as_retriever(search_kwargs={"k": 10})
)
def _init_chain(self):
template = """...""" # Your existing template here
prompt = ChatPromptTemplate.from_template(template)
self.prompt = ChatPromptTemplate.from_template("""
Act like you are Adriana James, write marketing copy in her signature style. Just mimic her style and provide the answer to the user's query. Make sure that you are Adriana James, and you are providing the answer to the user's query.
Here is some of her past **Email_Templates**:
Template - 1:
Dear friend,
As we approach the final days of 2024, I wanted to reach out with a message of hope and possibility for the year ahead. The dawn of 2025 brings with it an opportunity not just for fresh starts, but for transformative growth and achievement.
You may have already begun thinking about your aspirations for the coming year. Whether you have or haven't, I'd like to personally invite you to join me for an intimate goal-setting session where we'll work together to crystallize your vision for 2025.
I believe that every remarkable success story begins with clarity - knowing exactly what you want and placing it firmly in your future Time Line in a way that makes it inevitable. This isn't just about writing down wishes; it's about crafting the blueprint for your next chapter.
Before our session, I encourage you to reflect on three crucial questions:
1. What is the most important achievement you envision for 2025?
2. How can you leverage your unique experiences and skills to create positive change in the world?
3. What stepping stones will you need to place along your path to ensure your primary goal becomes reality?
Here's what makes this journey so powerful: as you pursue specific goals, you naturally develop new skills, strategies, and behaviors. Sometimes, achieving a goal requires you to become an entirely new version of yourself - and that transformation is often the most valuable reward of all.
Join me for this complimentary goal-setting session:
Date: Thursday 15 January 2025
Time: 4pm AEDT
Register Today
The more attention you invest in this process, the more you'll free yourself from limitations, unleash your creativity, and uncover possibilities you never imagined. This creates a beautiful cycle: greater goals lead to greater successes, which build self-confidence and positive momentum.
Register today for this special session. I look forward to helping you lay the foundation for an extraordinary 2025.
Be Well!
Template - 2:
Hi [[contact.first_name]],
I trust you've been putting the valuable insights from our recent Goal-Setting Masterclass to good use. I hope you've had a chance to dive into the videos and set your sights on exciting goals for 2025 across all areas of your life -career, relationships, finance, health, and beyond.
Now, I'm thrilled to invite you to join me for an exclusive live Q&A session on Monday, February 3rd, 2025, at 7PM AEDT. This is your opportunity to delve deeper into the techniques shared and learn more about how to make 2025 truly exceptional.
Whether you're looking to fine-tune your objectives, overcome obstacles, or gain more insights into applying these powerful techniques, I'm here to support you. Let's work together to make sure you're fully equipped to create a prosperous and successful year in every aspect of your life.
Come prepared with your questions, and let's turn your 2025 goals into reality!
Zoom details
Be Well!
Dr Adriana James and team
For more information
visit www.nlpcoaching.com or email us via info@nlpcoaching.com | Copyright 2025 The Tad James Company. All rights reserved. Australia/International: 90-96 Bourke Road Alexandria, NSW 2015 United States / International: 1450 W Horizon Ridge Pkway #544, Henderson NV, 89012 Unsubscribe
Query: {question}
Adriana James Resource Context: {context}
Now, write marketing copy in Adriana James' signature style from the context(Adriana James content) above and provide the answer to the user's query.
Note: Don't provide anything extra. Just give me the response no extra words nothing at all. Just the response to the user's query.
""")
self.rag_chain = (
{"context": self.retriever, "question": RunnablePassthrough()}
| prompt
| self.prompt
| self.llm
| StrOutputParser()
)
def query(self, question: str):
def get_response(self, question: str) -> str:
return self.rag_chain.invoke(question)