Spaces:
Sleeping
Sleeping
UPDATE: docker permissions
Browse files- config.py +1 -1
- llm_chain.py +42 -18
- main.py +47 -0
config.py
CHANGED
|
@@ -10,7 +10,7 @@ ENCODE_KWARGS = {'normalize_embeddings': False}
|
|
| 10 |
VECTOR_STORE_DIRECTORY = "vectorStore"
|
| 11 |
|
| 12 |
# LLM Configuration
|
| 13 |
-
LLM_MODEL = "
|
| 14 |
LLM_TEMPERATURE = 0.8
|
| 15 |
|
| 16 |
# Retriever Configuration
|
|
|
|
| 10 |
VECTOR_STORE_DIRECTORY = "vectorStore"
|
| 11 |
|
| 12 |
# LLM Configuration
|
| 13 |
+
LLM_MODEL = "openai/gpt-oss-120b"
|
| 14 |
LLM_TEMPERATURE = 0.8
|
| 15 |
|
| 16 |
# Retriever Configuration
|
llm_chain.py
CHANGED
|
@@ -17,47 +17,71 @@ def get_llm():
|
|
| 17 |
def get_prompt_template():
|
| 18 |
"""Creates and returns the ChatPromptTemplate for the RAG chain."""
|
| 19 |
prompt_text = """
|
| 20 |
-
You are a chatbot AI assistant specialized exclusively in answering questions from
|
| 21 |
-
Your role is to provide
|
| 22 |
|
| 23 |
---
|
| 24 |
|
| 25 |
-
###
|
| 26 |
|
| 27 |
-
1.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
2.
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
3.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
4.
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
5.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
---
|
| 39 |
|
| 40 |
-
###
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 45 |
"The books by Ice Venkatesh do not provide enough information to answer this question."
|
| 46 |
|
| 47 |
---
|
| 48 |
|
| 49 |
-
###
|
| 50 |
|
| 51 |
-
Always
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
---
|
| 56 |
|
| 57 |
-
|
| 58 |
{context}
|
| 59 |
|
| 60 |
-
|
| 61 |
{query}
|
| 62 |
"""
|
| 63 |
return ChatPromptTemplate.from_template(prompt_text)
|
|
|
|
| 17 |
def get_prompt_template():
|
| 18 |
"""Creates and returns the ChatPromptTemplate for the RAG chain."""
|
| 19 |
prompt_text = """
|
| 20 |
+
You are a chatbot AI assistant specialized exclusively in answering questions from three mathematics books authored by Ice Venkatesh.
|
| 21 |
+
Your role is to provide clear, precise, and complete answers strictly based on the retrieved context from those books.
|
| 22 |
|
| 23 |
---
|
| 24 |
|
| 25 |
+
### Core Rules
|
| 26 |
|
| 27 |
+
1. Strict Reliance on Context
|
| 28 |
+
- You must only use the retrieved context (context) from Ice Venkatesh’s books.
|
| 29 |
+
- Do not invent, assume, or guess missing information.
|
| 30 |
+
- Do not rely on prior training knowledge.
|
| 31 |
+
- If the retrieved context does not contain enough information, explicitly state this.
|
| 32 |
|
| 33 |
+
2. No External Sources
|
| 34 |
+
- Never use the internet, external references, or training data.
|
| 35 |
+
- Never cite or refer to any source outside Ice Venkatesh’s three mathematics books.
|
| 36 |
+
- Never include filler knowledge or generic definitions unless they are explicitly provided in the context.
|
| 37 |
|
| 38 |
+
3. Mathematical Rigor and Clarity
|
| 39 |
+
- Always give step-by-step solutions for calculations, proofs, or problem-solving.
|
| 40 |
+
- Ensure all reasoning is mathematically correct and clearly explained.
|
| 41 |
+
- Avoid shortcuts that skip explanation unless the context itself provides them.
|
| 42 |
+
- Present answers in the simplest and most precise form.
|
| 43 |
|
| 44 |
+
4. Handling Off-Topic Queries
|
| 45 |
+
- If the user asks anything unrelated to Ice Venkatesh’s mathematics books or to mathematics itself, decline politely.
|
| 46 |
+
- Use exactly this phrasing when declining:
|
| 47 |
+
"I can only help with questions related to the three mathematics books by Ice Venkatesh. Unfortunately, I cannot assist with topics outside that scope."
|
| 48 |
|
| 49 |
+
5. Style and Professionalism
|
| 50 |
+
- Responses must be concise, clear, and professional.
|
| 51 |
+
- Do not include speculation, unnecessary commentary, or conversational filler.
|
| 52 |
+
- Never mention the words "context," "retrieved," or explain where the answer came from.
|
| 53 |
+
- Never break character as a mathematics assistant.
|
| 54 |
|
| 55 |
---
|
| 56 |
|
| 57 |
+
### Response Instructions
|
| 58 |
|
| 59 |
+
- Always read the retrieved context carefully and extract only what is needed to answer the query.
|
| 60 |
+
- Answer the query directly and fully, without mentioning retrieval or sources.
|
| 61 |
+
- If the retrieved context provides multiple methods, choose the clearest one and show all steps.
|
| 62 |
+
- If insufficient context is available, reply only with:
|
| 63 |
"The books by Ice Venkatesh do not provide enough information to answer this question."
|
| 64 |
|
| 65 |
---
|
| 66 |
|
| 67 |
+
### Output Format
|
| 68 |
|
| 69 |
+
- Always wrap the entire answer in double quotes.
|
| 70 |
+
- No additional text should appear outside the quotes.
|
| 71 |
+
- Do not include prefixes like “Answer:” or “Here is the solution:”.
|
| 72 |
+
- The entire response must be one continuous quoted block.
|
| 73 |
|
| 74 |
+
**Example:**
|
| 75 |
+
"Step 1: Divide the number by 3.
|
| 76 |
+
Step 2: Multiply the result by 111.
|
| 77 |
+
Final Answer: 37 × 24 = 888."
|
| 78 |
|
| 79 |
---
|
| 80 |
|
| 81 |
+
Retrieved context:
|
| 82 |
{context}
|
| 83 |
|
| 84 |
+
User question:
|
| 85 |
{query}
|
| 86 |
"""
|
| 87 |
return ChatPromptTemplate.from_template(prompt_text)
|
main.py
CHANGED
|
@@ -19,6 +19,53 @@ async def setup_model(app_instance, loop):
|
|
| 19 |
app_instance.ctx.rag_chain = rag_chain
|
| 20 |
print("Model pipeline is ready.")
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
@app.get("/getResponse")
|
| 23 |
async def get_response_endpoint(request):
|
| 24 |
"""
|
|
|
|
| 19 |
app_instance.ctx.rag_chain = rag_chain
|
| 20 |
print("Model pipeline is ready.")
|
| 21 |
|
| 22 |
+
@app.get("/")
|
| 23 |
+
async def home(request):
|
| 24 |
+
"""
|
| 25 |
+
Root endpoint showing app name and description.
|
| 26 |
+
"""
|
| 27 |
+
html_content = """
|
| 28 |
+
<html>
|
| 29 |
+
<head>
|
| 30 |
+
<title>VibbaBackend</title>
|
| 31 |
+
<style>
|
| 32 |
+
body {
|
| 33 |
+
font-family: Arial, sans-serif;
|
| 34 |
+
margin: 40px;
|
| 35 |
+
background-color: #f9f9f9;
|
| 36 |
+
color: #333;
|
| 37 |
+
}
|
| 38 |
+
h1 { color: #0073e6; }
|
| 39 |
+
.container {
|
| 40 |
+
max-width: 800px;
|
| 41 |
+
margin: auto;
|
| 42 |
+
padding: 20px;
|
| 43 |
+
background: #fff;
|
| 44 |
+
border-radius: 8px;
|
| 45 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
|
| 46 |
+
}
|
| 47 |
+
</style>
|
| 48 |
+
</head>
|
| 49 |
+
<body>
|
| 50 |
+
<div class="container">
|
| 51 |
+
<h1>VibbaBackend</h1>
|
| 52 |
+
<p>
|
| 53 |
+
Welcome to the <strong>VibbaBackend</strong> service! 🚀<br><br>
|
| 54 |
+
This backend powers a Retrieval-Augmented Generation (RAG) pipeline
|
| 55 |
+
using an ensemble retriever and a large language model.
|
| 56 |
+
</p>
|
| 57 |
+
<p>
|
| 58 |
+
<strong>Available endpoints:</strong>
|
| 59 |
+
<ul>
|
| 60 |
+
<li><code>/getResponse?question=Your+query</code> – Get an answer to your question.</li>
|
| 61 |
+
</ul>
|
| 62 |
+
</p>
|
| 63 |
+
</div>
|
| 64 |
+
</body>
|
| 65 |
+
</html>
|
| 66 |
+
"""
|
| 67 |
+
return response.html(html_content)
|
| 68 |
+
|
| 69 |
@app.get("/getResponse")
|
| 70 |
async def get_response_endpoint(request):
|
| 71 |
"""
|