prestiva commited on
Commit
c22aebc
·
1 Parent(s): d8d616a

Files Upload

Browse files
Files changed (6) hide show
  1. .DS_Store +0 -0
  2. .gitattributes +4 -0
  3. Dockerfile +15 -0
  4. main.py +61 -0
  5. requirements.txt +9 -0
  6. vectorDB/chroma.sqlite3 +3 -0
.DS_Store ADDED
Binary file (8.2 kB). View file
 
.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.sqlite filter=lfs diff=lfs merge=lfs -text
37
+ vectorDB/.sqlite filter=lfs diff=lfs merge=lfs -text
38
+ vectorDB/*.sqlite filter=lfs diff=lfs merge=lfs -text
39
+ vectorDB/chroma.sqlite3 filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ COPY . /app
4
+
5
+ WORKDIR /app
6
+
7
+ USER root
8
+
9
+ RUN pip install -r requirements.txt
10
+
11
+ RUN chmod -R 777 /app
12
+
13
+ EXPOSE 7860
14
+
15
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_core.output_parsers import StrOutputParser
2
+ from langchain_core.runnables import RunnablePassthrough
3
+ from langchain_huggingface import HuggingFaceEmbeddings
4
+ from langchain_core.prompts import ChatPromptTemplate
5
+ from langchain_groq import ChatGroq
6
+ from langchain_chroma import Chroma
7
+ from fastapi import FastAPI
8
+
9
+ app = FastAPI(title = "VibbaAIEndpoints")
10
+
11
+ model_name = "BAAI/bge-large-en-v1.5"
12
+ model_kwargs = {'device': 'cpu', "trust_remote_code": True}
13
+ encode_kwargs = {'normalize_embeddings': False}
14
+ hf = HuggingFaceEmbeddings(
15
+ model_name=model_name,
16
+ model_kwargs=model_kwargs,
17
+ encode_kwargs=encode_kwargs
18
+ )
19
+
20
+ vectorStore = Chroma(
21
+ collection_name="collection",
22
+ embedding_function=hf,
23
+ persist_directory="./vectorDB",
24
+ )
25
+ vectorStore = vectorStore.as_retriever(search_kwargs={"k": 4})
26
+
27
+ llm = ChatGroq(model = "llama-3.3-70b-versatile", temperature = 0.75)
28
+ outputParser = StrOutputParser()
29
+
30
+ prompt = """
31
+ You are a highly specialized chatbot designed to assist users with queries related to a specific book about mathematics.
32
+ Your primary role is to answer user questions accurately and comprehensively using the retrieved context from the book.
33
+
34
+ - Accuracy is paramount: Your answers must be 100% accurate and based strictly on the context you have been provided.
35
+ - No additional information: Never introduce information or ideas outside the retrieved context. You must rely solely on the book's content to guide your responses.
36
+ - User satisfaction: Your goal is to provide complete satisfaction to users by solving their doubts and answering their questions
37
+ with clarity, precision, and politeness.
38
+ - Math expertise: The book revolves around mathematics, and you are an expert in math. Ensure all solutions and explanations are
39
+ flawless and easily understandable, offering correct guidance for any math-related queries.
40
+ - Off-topic queries: If a user asks a question unrelated to the book or mathematics, politely respond that you are not designed
41
+ to address topics beyond the scope of the book and math. You can assess the topic's relevance based on the context retrieved.
42
+
43
+ Example response for off-topic queries:
44
+ "I'm here to help with questions related to the mathematics book I was designed around. Unfortunately, I cannot assist with
45
+ topics outside that scope. Please feel free to ask any math-related questions!"
46
+
47
+ Always maintain professionalism, politeness, and clarity in every response. You are a reliable and expert guide for users
48
+ seeking help with math through the context of the book.
49
+
50
+ Here's the retrieved context:
51
+ {context}
52
+
53
+ Here's the question which user has asked:
54
+ {query}
55
+ """
56
+ prompt = ChatPromptTemplate.from_template(prompt)
57
+ chain = {"query": RunnablePassthrough(), "context": RunnablePassthrough() | vectorStore} | prompt | llm | outputParser
58
+
59
+ @app.get("/getResponse")
60
+ async def generateResponse(question: str):
61
+ return chain.invoke(question)
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ uvicorn
2
+ fastapi
3
+ pdfplumber
4
+ langchain
5
+ langchain-groq
6
+ langchain-chroma
7
+ langchain-community
8
+ langchain-huggingface
9
+ langchain_text_splitters
vectorDB/chroma.sqlite3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b79175bfd06557d58f916ff23ca13c5d444afe2f04b5737e23900a7a0727679
3
+ size 1916928