Spaces:
Sleeping
Sleeping
Upload 71 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .dockerignore +8 -0
- .gitignore +13 -0
- Dockerfile +21 -0
- __init__.py +0 -0
- agents/__init__.py +0 -0
- agents/__pycache__/__init__.cpython-311.pyc +0 -0
- agents/__pycache__/__init__.cpython-313.pyc +0 -0
- agents/__pycache__/feedback_agent.cpython-311.pyc +0 -0
- agents/__pycache__/feedback_agent.cpython-313.pyc +0 -0
- agents/__pycache__/math_solver.cpython-311.pyc +0 -0
- agents/__pycache__/math_solver.cpython-313.pyc +0 -0
- agents/__pycache__/parser_agent.cpython-311.pyc +0 -0
- agents/__pycache__/routing_agent.cpython-311.pyc +0 -0
- agents/__pycache__/routing_agent.cpython-313.pyc +0 -0
- agents/__pycache__/vector_db.cpython-311.pyc +0 -0
- agents/__pycache__/vector_db.cpython-313.pyc +0 -0
- agents/__pycache__/web_agent.cpython-311.pyc +0 -0
- agents/__pycache__/web_agent.cpython-313.pyc +0 -0
- agents/feedback_agent.py +163 -0
- agents/math_solver.py +74 -0
- agents/parser_agent.py +44 -0
- agents/routing_agent.py +38 -0
- agents/vector_db.py +43 -0
- agents/web_agent.py +3 -0
- create_init_files.py +0 -0
- data/__init__.py +1 -0
- data/data.txt +92 -0
- data/embeddings/index.faiss +0 -0
- data/embeddings/index.pkl +3 -0
- data/feedback_log.json +171 -0
- data/parsed/03b7e3b6-f742-4668-8238-f329df6ce0c7.json +22 -0
- data/uploads/0e118489-9862-4d85-96e9-27a8027258dc.webm +0 -0
- data/uploads/1a6c3053-9063-4c82-94d7-a0d394f8279a.webm +0 -0
- data/uploads/335e4b51-5ee5-4b55-95c5-f303f30c66c4.png +0 -0
- data/uploads/45be71fd-514d-4081-a611-861ba7a091a3.webm +0 -0
- data/uploads/50737f2b-de46-4f19-9284-29bdfd47456d.webm +0 -0
- data/uploads/6a76d880-7984-4bb9-a20f-ba0bf9299906.png +0 -0
- data/uploads/9bc29088-4aae-4406-a1c4-f1d47085296c.png +0 -0
- data/uploads/9d89b6e8-761f-40e7-9543-f07da13ada0d.webm +0 -0
- data/uploads/9f688908-d1fd-4730-b878-e8e2fc27f618.png +0 -0
- data/uploads/a123c319-5b6b-4db0-8109-08c118198a56.png +0 -0
- data/uploads/e277bc8a-5830-4795-82e1-f136f3e67046.png +0 -0
- data/uploads/ef53575a-9995-4fcb-9a68-1abb44cbf719.webm +0 -0
- data/uploads/f5c8e2cf-2c63-4acc-923d-f0c449e425f7.webm +0 -0
- data/uploads/hard-math-9.jpg +0 -0
- data/uploads/recording.webm +0 -0
- docker-compose.yml +27 -0
- main.py +36 -0
- requirements.txt +0 -0
- router/__init__.py +1 -0
.dockerignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
*.pyo
|
| 4 |
+
*.pyd
|
| 5 |
+
.env
|
| 6 |
+
node_modules/
|
| 7 |
+
.git
|
| 8 |
+
.idea
|
.gitignore
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ignore Python cache and environments
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
.env
|
| 5 |
+
|
| 6 |
+
# Ignore node_modules and build files
|
| 7 |
+
Frontend/react-app/node_modules/
|
| 8 |
+
Frontend/react-app/build/
|
| 9 |
+
|
| 10 |
+
# Ignore IDE and system files
|
| 11 |
+
.idea/
|
| 12 |
+
.vscode/
|
| 13 |
+
*.log
|
Dockerfile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.13-slim
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
# Create base working directory inside the container
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy requirements file from your Backend folder
|
| 8 |
+
COPY requirements.txt .
|
| 9 |
+
|
| 10 |
+
# Install dependencies
|
| 11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Copy entire Backend folder to /app/Backend inside container
|
| 14 |
+
COPY . /app
|
| 15 |
+
|
| 16 |
+
RUN apt-get update && apt-get install -y ffmpeg
|
| 17 |
+
|
| 18 |
+
# Expose the FastAPI port
|
| 19 |
+
EXPOSE 7860
|
| 20 |
+
|
| 21 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
__init__.py
ADDED
|
File without changes
|
agents/__init__.py
ADDED
|
File without changes
|
agents/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (141 Bytes). View file
|
|
|
agents/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (129 Bytes). View file
|
|
|
agents/__pycache__/feedback_agent.cpython-311.pyc
ADDED
|
Binary file (7.72 kB). View file
|
|
|
agents/__pycache__/feedback_agent.cpython-313.pyc
ADDED
|
Binary file (5.08 kB). View file
|
|
|
agents/__pycache__/math_solver.cpython-311.pyc
ADDED
|
Binary file (3.7 kB). View file
|
|
|
agents/__pycache__/math_solver.cpython-313.pyc
ADDED
|
Binary file (3.41 kB). View file
|
|
|
agents/__pycache__/parser_agent.cpython-311.pyc
ADDED
|
Binary file (1.29 kB). View file
|
|
|
agents/__pycache__/routing_agent.cpython-311.pyc
ADDED
|
Binary file (2.15 kB). View file
|
|
|
agents/__pycache__/routing_agent.cpython-313.pyc
ADDED
|
Binary file (1.88 kB). View file
|
|
|
agents/__pycache__/vector_db.cpython-311.pyc
ADDED
|
Binary file (2.05 kB). View file
|
|
|
agents/__pycache__/vector_db.cpython-313.pyc
ADDED
|
Binary file (1.79 kB). View file
|
|
|
agents/__pycache__/web_agent.cpython-311.pyc
ADDED
|
Binary file (379 Bytes). View file
|
|
|
agents/__pycache__/web_agent.cpython-313.pyc
ADDED
|
Binary file (331 Bytes). View file
|
|
|
agents/feedback_agent.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
import dspy
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
|
| 7 |
+
# path setup
|
| 8 |
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
| 9 |
+
|
| 10 |
+
from agents.routing_agent import route_query as math_agent
|
| 11 |
+
|
| 12 |
+
FEEDBACK = os.path.join("data", "feedback_log.json")
|
| 13 |
+
|
| 14 |
+
# DSPy setup
|
| 15 |
+
lm = dspy.LM(
|
| 16 |
+
model="groq/llama-3.1-8b-instant",
|
| 17 |
+
api_key=os.getenv("GROQ_API_KEY")
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
dspy.settings.configure(lm=lm)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class MathReasoner(dspy.Module):
|
| 24 |
+
|
| 25 |
+
def __init__(self):
|
| 26 |
+
super().__init__()
|
| 27 |
+
self.prog = dspy.ChainOfThought("question -> answer")
|
| 28 |
+
|
| 29 |
+
def forward(self, question):
|
| 30 |
+
return self.prog(question=question)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# -------- DSPY HITL AGENT --------
|
| 34 |
+
class ClarificationAgent(dspy.Module):
|
| 35 |
+
|
| 36 |
+
def __init__(self):
|
| 37 |
+
super().__init__()
|
| 38 |
+
self.generator = dspy.ChainOfThought("question -> clarification")
|
| 39 |
+
|
| 40 |
+
def forward(self, question):
|
| 41 |
+
return self.generator(question=question)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
clarifier = ClarificationAgent()
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def ask_for_clarification(question: str):
|
| 48 |
+
|
| 49 |
+
result = clarifier(question=question)
|
| 50 |
+
|
| 51 |
+
return result.clarification
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# -------- SAVE FEEDBACK (MEMORY) --------
|
| 55 |
+
def save_feedback(
|
| 56 |
+
query: str,
|
| 57 |
+
answer: str,
|
| 58 |
+
feedback: str,
|
| 59 |
+
rating: str = None,
|
| 60 |
+
parsed_question: dict = None,
|
| 61 |
+
retrieved_context: str = None,
|
| 62 |
+
verifier_outcome: str = None
|
| 63 |
+
):
|
| 64 |
+
|
| 65 |
+
entry = {
|
| 66 |
+
"timestamp": datetime.utcnow().isoformat(),
|
| 67 |
+
"original_input": query,
|
| 68 |
+
"parsed_question": parsed_question,
|
| 69 |
+
"retrieved_context": retrieved_context,
|
| 70 |
+
"final_answer": answer,
|
| 71 |
+
"verifier_outcome": verifier_outcome,
|
| 72 |
+
"user_feedback": feedback,
|
| 73 |
+
"rating": rating
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
if not os.path.exists(FEEDBACK):
|
| 77 |
+
with open(FEEDBACK, "w") as f:
|
| 78 |
+
json.dump([], f)
|
| 79 |
+
|
| 80 |
+
with open(FEEDBACK, "r+") as f:
|
| 81 |
+
|
| 82 |
+
data = json.load(f)
|
| 83 |
+
data.append(entry)
|
| 84 |
+
|
| 85 |
+
f.seek(0)
|
| 86 |
+
json.dump(data, f, indent=4)
|
| 87 |
+
|
| 88 |
+
print("🧠 Feedback stored in memory.")
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# -------- MEMORY RETRIEVAL --------
|
| 92 |
+
def retrieve_similar(query: str):
|
| 93 |
+
|
| 94 |
+
if not os.path.exists(FEEDBACK):
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
with open(FEEDBACK, "r") as f:
|
| 98 |
+
data = json.load(f)
|
| 99 |
+
|
| 100 |
+
for item in data:
|
| 101 |
+
|
| 102 |
+
if query.lower() in item["original_input"].lower():
|
| 103 |
+
return item
|
| 104 |
+
|
| 105 |
+
return None
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
# -------- MODEL TUNING --------
|
| 109 |
+
def tuning(query, incorrect_answer, rating: str = None):
|
| 110 |
+
|
| 111 |
+
example = [
|
| 112 |
+
dspy.Example(
|
| 113 |
+
question=query,
|
| 114 |
+
answer="its incorrect"
|
| 115 |
+
).with_inputs("question"),
|
| 116 |
+
]
|
| 117 |
+
|
| 118 |
+
def simple_metric(example, pred, trace=None):
|
| 119 |
+
|
| 120 |
+
try:
|
| 121 |
+
gold_answer = example.answer.lower().strip()
|
| 122 |
+
pred_answer = pred.answer.lower().strip()
|
| 123 |
+
|
| 124 |
+
return 1.0 if gold_answer == pred_answer else 0.0
|
| 125 |
+
|
| 126 |
+
except:
|
| 127 |
+
return 0.0
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
class MathAgentWrapper(dspy.Module):
|
| 131 |
+
|
| 132 |
+
def forward(self, question):
|
| 133 |
+
|
| 134 |
+
result = math_agent(question)
|
| 135 |
+
|
| 136 |
+
return dspy.Prediction(answer=result)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
wrapper_model = MathAgentWrapper()
|
| 140 |
+
|
| 141 |
+
trainer = dspy.BootstrapFewShot(
|
| 142 |
+
metric=simple_metric,
|
| 143 |
+
max_bootstrapped_demos=1,
|
| 144 |
+
max_labeled_demos=1
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
trainer.compile(wrapper_model, trainset=example)
|
| 148 |
+
|
| 149 |
+
print("🧠 Model updated based on feedback.")
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
# -------- ANSWER WITH MEMORY --------
|
| 153 |
+
def answer(query: str):
|
| 154 |
+
|
| 155 |
+
memory = retrieve_similar(query)
|
| 156 |
+
|
| 157 |
+
if memory:
|
| 158 |
+
print("⚡ Using stored solution from memory.")
|
| 159 |
+
return memory["final_answer"]
|
| 160 |
+
|
| 161 |
+
result = math_agent(query)
|
| 162 |
+
|
| 163 |
+
return result
|
agents/math_solver.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import sympy as sp
|
| 3 |
+
|
| 4 |
+
def try_math_solver(query: str) -> str:
|
| 5 |
+
q = query.lower().strip()
|
| 6 |
+
# Remove filler words that confuse sympy
|
| 7 |
+
q = re.sub(r'\b(what is|calculate|find|compute|equals?|result of|area of|value of|solve)\b', '', q)
|
| 8 |
+
q = q.strip()
|
| 9 |
+
|
| 10 |
+
# Handle "where x = 5" style variable substitution
|
| 11 |
+
variables = dict(re.findall(r'(\w+)\s*=\s*([\d\.]+)', q))
|
| 12 |
+
for var in variables:
|
| 13 |
+
q = re.sub(rf"\b{var}\s*=\s*{variables[var]}\b", '', q)
|
| 14 |
+
q = re.sub(r'\bwhere\b', '', q)
|
| 15 |
+
|
| 16 |
+
# Handle patterns like “add 2 and 5”
|
| 17 |
+
patterns = [
|
| 18 |
+
(r'addition of (\d+(?:\.\d+)?) and (\d+(?:\.\d+)?)', r'(\1 + \2)'),
|
| 19 |
+
(r'add (\d+(?:\.\d+)?) and (\d+(?:\.\d+)?)', r'(\1 + \2)'),
|
| 20 |
+
(r'subtract (\d+(?:\.\d+)?) from (\d+(?:\.\d+)?)', r'(\2 - \1)'),
|
| 21 |
+
(r'subtract (\d+(?:\.\d+)?) and (\d+(?:\.\d+)?)', r'(\1 - \2)'),
|
| 22 |
+
(r'multiply (\d+(?:\.\d+)?) by (\d+(?:\.\d+)?)', r'(\1 * \2)'),
|
| 23 |
+
(r'divide (\d+(?:\.\d+)?) by (\d+(?:\.\d+)?)', r'(\1 / \2)'),
|
| 24 |
+
(r'(\d+(?:\.\d+)?) power (\d+(?:\.\d+)?)', r'(\1 ** \2)'),
|
| 25 |
+
(r'square root of (\d+(?:\.\d+)?)', r'sqrt(\1)'),
|
| 26 |
+
]
|
| 27 |
+
for pat, repl in patterns:
|
| 28 |
+
q = re.sub(pat, repl, q)
|
| 29 |
+
|
| 30 |
+
# Replace simple words with symbols
|
| 31 |
+
replacements = {
|
| 32 |
+
"plus": "+", "minus": "-", "times": "*", "x": "*",
|
| 33 |
+
"mod": "%", "modulus": "%", "divided by": "/",
|
| 34 |
+
"power of": "**", "power": "**"
|
| 35 |
+
}
|
| 36 |
+
for word, sym in replacements.items():
|
| 37 |
+
q = re.sub(rf"\b{word}\b", sym, q)
|
| 38 |
+
|
| 39 |
+
# Remove assignments like “area =”
|
| 40 |
+
q = re.sub(r'\b\w+\s*=\s*', '', q).strip()
|
| 41 |
+
|
| 42 |
+
# Allow safe math functions
|
| 43 |
+
allowed_funcs = {
|
| 44 |
+
"sqrt": sp.sqrt, "sin": sp.sin, "cos": sp.cos, "tan": sp.tan,
|
| 45 |
+
"log": sp.log, "pi": sp.pi, "e": sp.E
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
expr = sp.sympify(q, locals=allowed_funcs)
|
| 50 |
+
if variables:
|
| 51 |
+
subs = {sp.Symbol(k): float(v) for k, v in variables.items()}
|
| 52 |
+
expr = expr.subs(subs)
|
| 53 |
+
result = expr.evalf()
|
| 54 |
+
return f"The answer is {result}"
|
| 55 |
+
except Exception as e:
|
| 56 |
+
return f"Sorry, couldn't solve that expression. ({e})"
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
tests = [
|
| 61 |
+
"addition of 2 and 5",
|
| 62 |
+
"add 10 and 20",
|
| 63 |
+
"what is 12 minus 5",
|
| 64 |
+
"multiply 6 by 3",
|
| 65 |
+
"divide 15 by 3",
|
| 66 |
+
"10 power 2",
|
| 67 |
+
"100 mod 3",
|
| 68 |
+
"square root of 81",
|
| 69 |
+
"2 + 5 * 3",
|
| 70 |
+
"area = pi * r^2 where r = 5"
|
| 71 |
+
]
|
| 72 |
+
for t in tests:
|
| 73 |
+
print(f"{t} → {try_math_solver(t)}")
|
| 74 |
+
|
agents/parser_agent.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def parse_problem(text: str):
|
| 5 |
+
|
| 6 |
+
cleaned_text = text.strip()
|
| 7 |
+
cleaned_text = re.sub(r"\s+", " ", cleaned_text)
|
| 8 |
+
|
| 9 |
+
# Extract variables
|
| 10 |
+
variables = list(set(re.findall(r"[a-zA-Z]", cleaned_text)))
|
| 11 |
+
|
| 12 |
+
# Extract constraints
|
| 13 |
+
constraints = re.findall(r"[a-zA-Z]\s*[><=]+\s*\d+", cleaned_text)
|
| 14 |
+
|
| 15 |
+
# Topic detection
|
| 16 |
+
topic = "general"
|
| 17 |
+
|
| 18 |
+
text_lower = cleaned_text.lower()
|
| 19 |
+
|
| 20 |
+
if "probability" in text_lower:
|
| 21 |
+
topic = "probability"
|
| 22 |
+
|
| 23 |
+
elif "matrix" in text_lower:
|
| 24 |
+
topic = "linear_algebra"
|
| 25 |
+
|
| 26 |
+
elif "derivative" in text_lower:
|
| 27 |
+
topic = "calculus"
|
| 28 |
+
|
| 29 |
+
elif "solve" in text_lower:
|
| 30 |
+
topic = "algebra"
|
| 31 |
+
|
| 32 |
+
# Check ambiguity
|
| 33 |
+
needs_clarification = False
|
| 34 |
+
|
| 35 |
+
if len(cleaned_text.split()) < 3:
|
| 36 |
+
needs_clarification = True
|
| 37 |
+
|
| 38 |
+
return {
|
| 39 |
+
"problem_text": cleaned_text,
|
| 40 |
+
"topic": topic,
|
| 41 |
+
"variables": variables,
|
| 42 |
+
"constraints": constraints,
|
| 43 |
+
"needs_clarification": needs_clarification
|
| 44 |
+
}
|
agents/routing_agent.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 2 |
+
from langchain_community.vectorstores import FAISS
|
| 3 |
+
from agents.math_solver import try_math_solver
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def route_query(query: str):
|
| 9 |
+
persist_dir = os.path.join("data", "embeddings")
|
| 10 |
+
|
| 11 |
+
# ✅ Load embeddings
|
| 12 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 13 |
+
vectordb = FAISS.load_local(persist_dir, embeddings, allow_dangerous_deserialization=True)
|
| 14 |
+
|
| 15 |
+
# ✅ Step 1: Search in FAISS
|
| 16 |
+
results = vectordb.similarity_search_with_score(query, k=1)
|
| 17 |
+
|
| 18 |
+
# ✅ If found in FAISS
|
| 19 |
+
if results and results[0][1] < 0.4:
|
| 20 |
+
print("📘 Answer is on data.txt")
|
| 21 |
+
return "KO"
|
| 22 |
+
|
| 23 |
+
else:
|
| 24 |
+
# ✅ Step 2: Try math solver
|
| 25 |
+
print("🧮 Not found in FAISS — trying math solver...")
|
| 26 |
+
solver_result = try_math_solver(query)
|
| 27 |
+
print(f"🧩 Solver result: {solver_result}")
|
| 28 |
+
|
| 29 |
+
# ✅ Check if math solver succeeded
|
| 30 |
+
if solver_result and not any(bad in solver_result.lower() for bad in [
|
| 31 |
+
"sorry", "couldn't", "could not", "error", "invalid", "failed"
|
| 32 |
+
]):
|
| 33 |
+
print("✅ Math solver succeeded!")
|
| 34 |
+
return solver_result
|
| 35 |
+
|
| 36 |
+
# ✅ If not solved by FAISS or math solver → LLM
|
| 37 |
+
print("🌐 Not found anywhere — going for LLM")
|
| 38 |
+
return "LLM"
|
agents/vector_db.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
warnings.filterwarnings("ignore", category=UserWarning)
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
from langchain_community.document_loaders import DirectoryLoader, TextLoader
|
| 6 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 7 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 8 |
+
from langchain_community.vectorstores import FAISS
|
| 9 |
+
|
| 10 |
+
def create_text():
|
| 11 |
+
# Define paths
|
| 12 |
+
kb_path = os.path.join("data") # your text files folder
|
| 13 |
+
persist_dir = os.path.join("data", "embeddings")
|
| 14 |
+
|
| 15 |
+
# if exist
|
| 16 |
+
os.makedirs(kb_path, exist_ok=True)
|
| 17 |
+
os.makedirs(persist_dir, exist_ok=True)
|
| 18 |
+
|
| 19 |
+
# Load all text files from folder
|
| 20 |
+
loader = DirectoryLoader(kb_path, glob="*.txt", loader_cls=TextLoader)
|
| 21 |
+
documents = loader.load()
|
| 22 |
+
|
| 23 |
+
if not documents:
|
| 24 |
+
print("⚠️ No text files found in data folder!")
|
| 25 |
+
return
|
| 26 |
+
|
| 27 |
+
# Split long text into chunks for embedding
|
| 28 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 29 |
+
chunks = text_splitter.split_documents(documents)
|
| 30 |
+
|
| 31 |
+
# Load embedding model
|
| 32 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 33 |
+
|
| 34 |
+
# Create FAISS vector DB from documents
|
| 35 |
+
vectordb = FAISS.from_documents(chunks, embeddings)
|
| 36 |
+
|
| 37 |
+
# Save it locally
|
| 38 |
+
vectordb.save_local(persist_dir)
|
| 39 |
+
|
| 40 |
+
print("vector database created", persist_dir)
|
| 41 |
+
return vectordb
|
| 42 |
+
|
| 43 |
+
|
agents/web_agent.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from utils.mcp_client import run_math_agent
|
| 2 |
+
def answer_from_web(query):
|
| 3 |
+
return run_math_agent(query)
|
create_init_files.py
ADDED
|
File without changes
|
data/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# This file makes Python treat this directory as a package
|
data/data.txt
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Q: What is the Pythagoras theorem?
|
| 2 |
+
A: In a right-angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides. Mathematically: a² + b² = c².
|
| 3 |
+
|
| 4 |
+
Q: What is the quadratic formula?
|
| 5 |
+
A: For a quadratic equation ax² + bx + c = 0, the roots are given by: x = (-b ± √(b² - 4ac)) / 2a.
|
| 6 |
+
|
| 7 |
+
Q: What is the derivative of x²?
|
| 8 |
+
A: The derivative of x² with respect to x is 2x.
|
| 9 |
+
|
| 10 |
+
Q: What is the integral of x²?
|
| 11 |
+
A: The integral of x² with respect to x is (x³ / 3) + C, where C is the constant of integration.
|
| 12 |
+
|
| 13 |
+
Q: What is the area of a circle?
|
| 14 |
+
A: The area of a circle is given by A = πr², where r is the radius.
|
| 15 |
+
|
| 16 |
+
Q: What is the circumference of a circle?
|
| 17 |
+
A: The circumference of a circle is given by C = 2πr, where r is the radius.
|
| 18 |
+
|
| 19 |
+
Q: What is the slope of a line passing through points (x1, y1) and (x2, y2)?
|
| 20 |
+
A: The slope is given by m = (y2 - y1) / (x2 - x1).
|
| 21 |
+
|
| 22 |
+
Q: What is the formula for simple interest?
|
| 23 |
+
A: Simple Interest = (Principal × Rate × Time) / 100.
|
| 24 |
+
|
| 25 |
+
Q: What is the formula for compound interest?
|
| 26 |
+
A: Compound Interest = Principal × (1 + Rate/100)^Time - Principal.
|
| 27 |
+
|
| 28 |
+
Q: What is the derivative of sin(x)?
|
| 29 |
+
A: The derivative of sin(x) is cos(x).
|
| 30 |
+
|
| 31 |
+
Q: What is the derivative of cos(x)?
|
| 32 |
+
A: The derivative of cos(x) is -sin(x).
|
| 33 |
+
|
| 34 |
+
Q: What is the integral of sin(x)?
|
| 35 |
+
A: The integral of sin(x) is -cos(x) + C.
|
| 36 |
+
|
| 37 |
+
Q: What is the integral of cos(x)?
|
| 38 |
+
A: The integral of cos(x) is sin(x) + C.
|
| 39 |
+
|
| 40 |
+
Q: What is the distance formula in coordinate geometry?
|
| 41 |
+
A: The distance between points (x1, y1) and (x2, y2) is √((x2 - x1)² + (y2 - y1)²).
|
| 42 |
+
|
| 43 |
+
Q: What is the midpoint formula?
|
| 44 |
+
A: The midpoint of a line joining (x1, y1) and (x2, y2) is ((x1 + x2)/2, (y1 + y2)/2).
|
| 45 |
+
|
| 46 |
+
Q: What is the sum of the first n natural numbers?
|
| 47 |
+
A: The sum is given by S = n(n + 1)/2.
|
| 48 |
+
|
| 49 |
+
Q: What is the sum of the first n even numbers?
|
| 50 |
+
A: The sum is n(n + 1).
|
| 51 |
+
|
| 52 |
+
Q: What is the sum of the first n odd numbers?
|
| 53 |
+
A: The sum is n².
|
| 54 |
+
|
| 55 |
+
Q: What is the formula for the area of a triangle?
|
| 56 |
+
A: Area = ½ × base × height.
|
| 57 |
+
|
| 58 |
+
Q: What is the trigonometric identity involving sin²(x) and cos²(x)?
|
| 59 |
+
A: sin²(x) + cos²(x) = 1.
|
| 60 |
+
|
| 61 |
+
Q: What is the binomial theorem?
|
| 62 |
+
A: The binomial theorem states that (a + b)^n = Σ [nCk * a^(n-k) * b^k], where the summation runs from k = 0 to n.
|
| 63 |
+
|
| 64 |
+
Q: What is the limit of sin(x)/x as x approaches 0?
|
| 65 |
+
A: The limit of sin(x)/x as x → 0 is 1.
|
| 66 |
+
|
| 67 |
+
Q: What is the derivative of e^x?
|
| 68 |
+
A: The derivative of e^x with respect to x is e^x.
|
| 69 |
+
|
| 70 |
+
Q: What is the derivative of ln(x)?
|
| 71 |
+
A: The derivative of ln(x) with respect to x is 1/x.
|
| 72 |
+
|
| 73 |
+
Q: What is the area under y = x between 0 and 2?
|
| 74 |
+
A: The area is ∫(0 to 2) x dx = [x² / 2]₀² = 2.
|
| 75 |
+
|
| 76 |
+
Q: What is the perimeter of a rectangle?
|
| 77 |
+
A: The perimeter of a rectangle is 2 × (length + width).
|
| 78 |
+
|
| 79 |
+
Q: What is the formula for volume of a sphere?
|
| 80 |
+
A: Volume = (4/3)πr³.
|
| 81 |
+
|
| 82 |
+
Q: What is the surface area of a sphere?
|
| 83 |
+
A: Surface Area = 4πr².
|
| 84 |
+
|
| 85 |
+
Q: What is the mean of numbers 4, 8, and 12?
|
| 86 |
+
A: Mean = (4 + 8 + 12) / 3 = 8.
|
| 87 |
+
|
| 88 |
+
Q: What is the median of the numbers 3, 5, 7, 9, 11?
|
| 89 |
+
A: The median is 7.
|
| 90 |
+
|
| 91 |
+
Q: What is the mode of the numbers 2, 3, 3, 5, 7?
|
| 92 |
+
A: The mode is 3.
|
data/embeddings/index.faiss
ADDED
|
Binary file (6.19 kB). View file
|
|
|
data/embeddings/index.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2cf3b3fcdfb8202be6e4a12816b8b4ce8f98abb6c763a74de741d4aa3151394c
|
| 3 |
+
size 4343
|
data/feedback_log.json
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"timestamp": "2025-10-28T23:44:33.438347",
|
| 4 |
+
"query": "What is the integral of sin(x)?",
|
| 5 |
+
"answer": "WEB",
|
| 6 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"timestamp": "2025-10-28T23:47:37.610680",
|
| 10 |
+
"query": "What is the integral of sin(x)?",
|
| 11 |
+
"answer": "WEB",
|
| 12 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"timestamp": "2025-10-28T23:50:34.812828",
|
| 16 |
+
"query": "What is the integral of sin(x)?",
|
| 17 |
+
"answer": "WEB",
|
| 18 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"timestamp": "2025-10-28T23:52:07.815951",
|
| 22 |
+
"query": "What is the integral of sin(x)?",
|
| 23 |
+
"answer": "WEB",
|
| 24 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"timestamp": "2025-10-28T23:55:11.166467",
|
| 28 |
+
"query": "What is the integral of sin(x)?",
|
| 29 |
+
"answer": "WEB",
|
| 30 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"timestamp": "2025-10-28T23:58:22.966961",
|
| 34 |
+
"query": "What is the integral of sin(x)?",
|
| 35 |
+
"answer": "WEB",
|
| 36 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"timestamp": "2025-10-28T23:59:57.870620",
|
| 40 |
+
"query": "What is the integral of sin(x)?",
|
| 41 |
+
"answer": "WEB",
|
| 42 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"timestamp": "2025-10-29T00:01:47.611761",
|
| 46 |
+
"query": "What is the integral of sin(x)?",
|
| 47 |
+
"answer": "WEB",
|
| 48 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"timestamp": "2025-10-29T00:03:41.277987",
|
| 52 |
+
"query": "What is the integral of sin(x)?",
|
| 53 |
+
"answer": "WEB",
|
| 54 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"timestamp": "2025-10-29T00:13:19.920208",
|
| 58 |
+
"query": "What is the integral of sin(x)?",
|
| 59 |
+
"answer": "WEB",
|
| 60 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"timestamp": "2025-10-29T00:15:51.787155",
|
| 64 |
+
"query": "What is the integral of sin(x)?",
|
| 65 |
+
"answer": "WEB",
|
| 66 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"timestamp": "2025-10-29T00:17:35.253793",
|
| 70 |
+
"query": "What is the integral of sin(x)?",
|
| 71 |
+
"answer": "WEB",
|
| 72 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"timestamp": "2025-10-29T00:20:26.191961",
|
| 76 |
+
"query": "What is the integral of sin(x)?",
|
| 77 |
+
"answer": "WEB",
|
| 78 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"timestamp": "2025-10-29T00:21:49.889546",
|
| 82 |
+
"query": "What is the integral of sin(x)?",
|
| 83 |
+
"answer": "WEB",
|
| 84 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"timestamp": "2025-10-29T00:29:02.417399",
|
| 88 |
+
"query": "What is the integral of sin(x)?",
|
| 89 |
+
"answer": "WEB",
|
| 90 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"timestamp": "2025-10-29T00:30:43.568817",
|
| 94 |
+
"query": "What is the integral of sin(x)?",
|
| 95 |
+
"answer": "WEB",
|
| 96 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 97 |
+
},
|
| 98 |
+
{
|
| 99 |
+
"timestamp": "2025-10-29T10:11:22.019712",
|
| 100 |
+
"query": "What is the integral of sin(x)?",
|
| 101 |
+
"answer": "WEB",
|
| 102 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"timestamp": "2025-10-29T11:35:41.805717",
|
| 106 |
+
"query": "integration of sin(x)",
|
| 107 |
+
"answer": "The integral of sin(x) sin ( x ) with respect to x x is \u2212cos(x) - cos ( x ) . \u2212cos(x)+C - cos ( x ) + C. sin(x) s i n \u2061 ( x ) Mathematically, this is written as **\u222b sin x dx = -cos x + C**, were, C is the integration constant. * \u222b sin x dx = -cos x + C, where C is the constant of integration. \u222b sin x dx = -cos x + C -cos x + C = \u222b sin x dx **Answer:** \u222b sin x cos x dx = (-cos 2x)/4 + C \u222b sin u (1/2) du = (1/2) (-cos u) + C (as the integration of sin x is -cos x) **Answer:** \u222b x sin (x2) dx = (-cos x2)/2+C The integral of sin x is -cos x + C. Substituting u = 3x back, we get \u222b sin 3x dx = (1/3) (-cos (3x)) + C. Integral of sin(x)\nblackpenredpen\n1380000 subscribers\n1082 likes\n200320 views\n22 Feb 2015\nThe integral of sin(x) is just -cos(x)+C because the derivative of -cos(x) is sin(x).\n\nCheck out my 100 integrals for more calculus integral practice problems. https://youtu.be/dgm4-3-Iv3s?si=lTybJlpTMFdQINXr\n----------------------------------------\n\ud83d\udecd Shop my math t-shirt & hoodies: amzn.to/3qBeuw6\n\ud83d\udcaa Get my math notes by becoming a patron: https://www.patreon.com/blackpenredpen\n#blackpenredpen #math #calculus #apcalculus\n57 comments\n Our rough (rough!) conversion to Plain English is: The integral of sin(x) multiplies our intended path length (from 0 to x) by a percentage. # Integral of Sin x * What is Integral of Sin x? * Integral of Sin x From 0 to \u03c0 * Integral of Sin x From 0 to \u03c0/2 ## ****What is Integral of Sin x?**** The integral of the sine function, \u222b sin(x) dx, is equal to -cos(x) + C, where C is the constant of integration. Integral of sin(x) dx = -\u222b du Integral of sin(x) dx = -u + C Integral of sin(x) dx = -cos(x) + C ## ****Integral of Sin x From 0 to**** \u03c0 ## ****Integral of Sin x From 0 to**** \u03c0****/2**** ****Example 7: Find integral of x sin 2x dx**** ****Example 8: Find integral of sin x cos 2x****",
|
| 108 |
+
"feedback": "please give in 50 words"
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"timestamp": "2025-10-29T19:15:40.383977",
|
| 112 |
+
"query": "What is the integral of sin(x)?",
|
| 113 |
+
"answer": "WEB",
|
| 114 |
+
"feedback": "Incorrect \u2014 the correct answer is -cos(x) + C"
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"query": "derivative of sin(x)",
|
| 118 |
+
"answer": "The derivative of the sine function, sin\u2061(x), is the cosine function, cos\u2061(x). Mathematically, if f(x)=sin(x), then f\u2032(x)=cos\u2061(x). This result Here also we are going to prove the derivative of sin x to be -cos x using the first principle. The derivative of sin x is cos x. Thus, we have proved that the derivative of sin x is cos x. Therefore, the derivative of sin is cos x and is proved by using the quotient rule. Derivative of Sin x Worksheet Therefore, the derivative of sin x is cos x. * The derivative of sin x is cos x. Thus, the derivative of sin 3x is 3 cos 3x. Therefore, the derivative of sin x by first principle is cos x. We know that the derivative of sin x is cos x. So the derivative of sin x2 using this and using the chain rule is cos x2\u00b7 d/dx(x2). ## Derivative of sin x using the First Principle Method f\u2019(x) = limh\u21920 [sin x cos h + cos x sin h \u2013 sin x]/h f\u2019(x) = limh\u21920 [-sin x(1-cosh) + cos x sin h]/h sin (0/2)) + cos x (1) f\u2019(x) = \u2013 sin x(0) + cos x Thus, the derivative of sin x is cos x, is derived. ### Derivative of Sin x Examples Now, we have to find the derivative of sin (x+1), using the 1st principle. Hence, the derivative of sin (x+1), with respect to x is cos (x+1). Find the derivative of sin 2x. **To find:** derivative of sin 2x. Hence, the derivative of sin 2x is 2 cos 2x. ddx[sinx]=cosx Certainly, by the limit definition of the derivative, we know that ddx[sinx]=limh\u21920sin(x+h)\u2212sin(x)h ddx[sinx]=limh\u21920sinxcosh+cosxsinh\u2212sinxh Seeing all of the components of a similar limit in our expression for the derivative, (i.e., there is a sinh in the numerator, an h in the denominator, and both of these are inside a limit as h\u21920), we use algebra and the limit laws to reveal this known limit in our expression: ddx[sinx]=limh\u21920[cosxsinhh+sinxcosh\u2212sinxh]=limh\u21920[cosx\u22c5sinhh+sinxcosh\u2212sinxh]=limh\u21920cosx\u22c5limh\u21920sinhh+limh\u21920sinxcosh\u2212sinxh Note, the first limit in the last line above is of an expression that does not depend on h, and hence effectively the limit of a constant. ddx[sinx]=cosx+limh\u21920sinxcosh\u2212sinxh Pulling out the common factor of sinx in the remaining limit and splitting the resulting product with the limit laws again, we see another familiar limit -- one we which we know equals zero... ddx[sinx]=cosx+limh\u21920sinx(cosh\u22121)h=cosx+[limh\u21920sinx]\u22c5[limh\u21920cosh\u22121h]=cosx+sinx\u22c50=cosx d/dx(sin x) = \u03c0/180 cos x \"\"\" Which seems to suggest that the d/dx sin(x) is not equal to the cos(x) when degrees are used. That a constant must",
|
| 119 |
+
"feedback": "its cos(x)+c"
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"query": "derivative of sin(x)",
|
| 123 |
+
"answer": "The derivative of the sine function, sin\u2061(x), is the cosine function, cos\u2061(x). Mathematically, if f(x)=sin(x), then f\u2032(x)=cos\u2061(x). This result Here also we are going to prove the derivative of sin x to be -cos x using the first principle. The derivative of sin x is cos x. Thus, we have proved that the derivative of sin x is cos x. Therefore, the derivative of sin is cos x and is proved by using the quotient rule. Derivative of Sin x Worksheet Therefore, the derivative of sin x is cos x. * The derivative of sin x is cos x. Thus, the derivative of sin 3x is 3 cos 3x. Therefore, the derivative of sin x by first principle is cos x. We know that the derivative of sin x is cos x. So the derivative of sin x2 using this and using the chain rule is cos x2\u00b7 d/dx(x2). ## Derivative of sin x using the First Principle Method f\u2019(x) = limh\u21920 [sin x cos h + cos x sin h \u2013 sin x]/h f\u2019(x) = limh\u21920 [-sin x(1-cosh) + cos x sin h]/h sin (0/2)) + cos x (1) f\u2019(x) = \u2013 sin x(0) + cos x Thus, the derivative of sin x is cos x, is derived. ### Derivative of Sin x Examples Now, we have to find the derivative of sin (x+1), using the 1st principle. Hence, the derivative of sin (x+1), with respect to x is cos (x+1). Find the derivative of sin 2x. **To find:** derivative of sin 2x. Hence, the derivative of sin 2x is 2 cos 2x. ddx[sinx]=cosx Certainly, by the limit definition of the derivative, we know that ddx[sinx]=limh\u21920sin(x+h)\u2212sin(x)h ddx[sinx]=limh\u21920sinxcosh+cosxsinh\u2212sinxh Seeing all of the components of a similar limit in our expression for the derivative, (i.e., there is a sinh in the numerator, an h in the denominator, and both of these are inside a limit as h\u21920), we use algebra and the limit laws to reveal this known limit in our expression: ddx[sinx]=limh\u21920[cosxsinhh+sinxcosh\u2212sinxh]=limh\u21920[cosx\u22c5sinhh+sinxcosh\u2212sinxh]=limh\u21920cosx\u22c5limh\u21920sinhh+limh\u21920sinxcosh\u2212sinxh Note, the first limit in the last line above is of an expression that does not depend on h, and hence effectively the limit of a constant. ddx[sinx]=cosx+limh\u21920sinxcosh\u2212sinxh Pulling out the common factor of sinx in the remaining limit and splitting the resulting product with the limit laws again, we see another familiar limit -- one we which we know equals zero... ddx[sinx]=cosx+limh\u21920sinx(cosh\u22121)h=cosx+[limh\u21920sinx]\u22c5[limh\u21920cosh\u22121h]=cosx+sinx\u22c50=cosx d/dx(sin x) = \u03c0/180 cos x \"\"\" Which seems to suggest that the d/dx sin(x) is not equal to the cos(x) when degrees are used. That a constant must",
|
| 124 |
+
"feedback": "its cos(x)+c",
|
| 125 |
+
"rating": null
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"query": "derivative of sinx",
|
| 129 |
+
"answer": "The derivative of sin x is cos x, which is the rate of change of the sine function at any given point. Here also we are going to prove the derivative of sin x to be -cos x using the first principle. The derivative of sin x is cos x. Thus, we have proved that the derivative of sin x is cos x. Therefore, the derivative of sin is cos x and is proved by using the quotient rule. Derivative of Sin x Worksheet Therefore, the derivative of sin x is cos x. * The derivative of sin x is cos x. Thus, the derivative of sin 3x is 3 cos 3x. Therefore, the derivative of sin x by first principle is cos x. We know that the derivative of sin x is cos x. So the derivative of sin x2 using this and using the chain rule is cos x2\u00b7 d/dx(x2). ## Derivative of sin x using the First Principle Method f\u2019(x) = limh\u21920 [sin x cos h + cos x sin h \u2013 sin x]/h f\u2019(x) = limh\u21920 [-sin x(1-cosh) + cos x sin h]/h sin (0/2)) + cos x (1) f\u2019(x) = \u2013 sin x(0) + cos x Thus, the derivative of sin x is cos x, is derived. ### Derivative of Sin x Examples Now, we have to find the derivative of sin (x+1), using the 1st principle. Hence, the derivative of sin (x+1), with respect to x is cos (x+1). Find the derivative of sin 2x. **To find:** derivative of sin 2x. Hence, the derivative of sin 2x is 2 cos 2x. : r/calculus : r/calculus Image 1: r/calculus icon Go to calculus r/calculus Image 3: r/calculus iconr/calculus Welcome to r/calculus - a space for learning calculus and related disciplines. We learned in class that the derivative of sin(x) is cos(x). New to Reddit? * Reddit reReddit: Top posts of October 6, 2016 * * * * Reddit reReddit: Top posts of October 2016 * * * * Reddit reReddit: Top posts of 2016 * * * * Reddit Meta * Games * Gaming News & Discussion * Other Games * Action Movies & Series * Animated Movies & Series * Comedy Movies & Series * Romance Movies & Series * Superhero Movies & Series * About Reddit * Best of Reddit ddx[sinx]=cosx Certainly, by the limit definition of the derivative, we know that ddx[sinx]=limh\u21920sin(x+h)\u2212sin(x)h ddx[sinx]=limh\u21920sinxcosh+cosxsinh\u2212sinxh Seeing all of the components of a similar limit in our expression for the derivative, (i.e., there is a sinh in the numerator, an h in the denominator, and both of these are inside a limit as h\u21920), we use algebra and the limit laws to reveal this known limit in our expression: ddx[sinx]=limh\u21920[cosxsinhh+sinxcosh\u2212sinxh]=limh\u21920[cosx\u22c5sinhh+sinxcosh\u2212sinxh]=limh\u21920cosx\u22c5limh\u21920sinhh+limh\u21920sinxcosh\u2212sinxh Note, the first limit in the last line above is of an expression that does not depend on h, and hence effectively the limit of a constant. ddx[sinx]=cosx+limh\u21920sinxcosh\u2212sinxh Pulling out the common factor of sinx in the remaining limit and splitting the resulting product with the limit laws again, we see another familiar limit -- one we which we know equals zero... ddx[sinx]=cosx+limh\u21920sinx(cosh\u22121)h=cosx+[limh\u21920sinx]\u22c5[limh\u21920cosh\u22121h]=cosx+sinx\u22c50=cosx",
|
| 130 |
+
"feedback": "good",
|
| 131 |
+
"rating": null
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"query": "derivative of sinx",
|
| 135 |
+
"answer": "The derivative of sin x is cos x, which is the rate of change of the sine function at any given point. Here also we are going to prove the derivative of sin x to be -cos x using the first principle. The derivative of sin x is cos x. Thus, we have proved that the derivative of sin x is cos x. Therefore, the derivative of sin is cos x and is proved by using the quotient rule. Derivative of Sin x Worksheet Therefore, the derivative of sin x is cos x. * The derivative of sin x is cos x. Thus, the derivative of sin 3x is 3 cos 3x. Therefore, the derivative of sin x by first principle is cos x. We know that the derivative of sin x is cos x. So the derivative of sin x2 using this and using the chain rule is cos x2\u00b7 d/dx(x2). ## Derivative of sin x using the First Principle Method f\u2019(x) = limh\u21920 [sin x cos h + cos x sin h \u2013 sin x]/h f\u2019(x) = limh\u21920 [-sin x(1-cosh) + cos x sin h]/h sin (0/2)) + cos x (1) f\u2019(x) = \u2013 sin x(0) + cos x Thus, the derivative of sin x is cos x, is derived. ### Derivative of Sin x Examples Now, we have to find the derivative of sin (x+1), using the 1st principle. Hence, the derivative of sin (x+1), with respect to x is cos (x+1). Find the derivative of sin 2x. **To find:** derivative of sin 2x. Hence, the derivative of sin 2x is 2 cos 2x. : r/calculus : r/calculus Image 1: r/calculus icon Go to calculus r/calculus Image 3: r/calculus iconr/calculus Welcome to r/calculus - a space for learning calculus and related disciplines. We learned in class that the derivative of sin(x) is cos(x). New to Reddit? * Reddit reReddit: Top posts of October 6, 2016 * * * * Reddit reReddit: Top posts of October 2016 * * * * Reddit reReddit: Top posts of 2016 * * * * Reddit Meta * Games * Gaming News & Discussion * Other Games * Action Movies & Series * Animated Movies & Series * Comedy Movies & Series * Romance Movies & Series * Superhero Movies & Series * About Reddit * Best of Reddit ddx[sinx]=cosx Certainly, by the limit definition of the derivative, we know that ddx[sinx]=limh\u21920sin(x+h)\u2212sin(x)h ddx[sinx]=limh\u21920sinxcosh+cosxsinh\u2212sinxh Seeing all of the components of a similar limit in our expression for the derivative, (i.e., there is a sinh in the numerator, an h in the denominator, and both of these are inside a limit as h\u21920), we use algebra and the limit laws to reveal this known limit in our expression: ddx[sinx]=limh\u21920[cosxsinhh+sinxcosh\u2212sinxh]=limh\u21920[cosx\u22c5sinhh+sinxcosh\u2212sinxh]=limh\u21920cosx\u22c5limh\u21920sinhh+limh\u21920sinxcosh\u2212sinxh Note, the first limit in the last line above is of an expression that does not depend on h, and hence effectively the limit of a constant. ddx[sinx]=cosx+limh\u21920sinxcosh\u2212sinxh Pulling out the common factor of sinx in the remaining limit and splitting the resulting product with the limit laws again, we see another familiar limit -- one we which we know equals zero... ddx[sinx]=cosx+limh\u21920sinx(cosh\u22121)h=cosx+[limh\u21920sinx]\u22c5[limh\u21920cosh\u22121h]=cosx+sinx\u22c50=cosx",
|
| 136 |
+
"feedback": "good",
|
| 137 |
+
"rating": null
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"query": "derivative of sinx",
|
| 141 |
+
"answer": "The derivative of sin x is cos x, which is the rate of change of the sine function at any given point. Here also we are going to prove the derivative of sin x to be -cos x using the first principle. The derivative of sin x is cos x. Thus, we have proved that the derivative of sin x is cos x. Therefore, the derivative of sin is cos x and is proved by using the quotient rule. Derivative of Sin x Worksheet Therefore, the derivative of sin x is cos x. * The derivative of sin x is cos x. Thus, the derivative of sin 3x is 3 cos 3x. Therefore, the derivative of sin x by first principle is cos x. We know that the derivative of sin x is cos x. So the derivative of sin x2 using this and using the chain rule is cos x2\u00b7 d/dx(x2). ## Derivative of sin x using the First Principle Method f\u2019(x) = limh\u21920 [sin x cos h + cos x sin h \u2013 sin x]/h f\u2019(x) = limh\u21920 [-sin x(1-cosh) + cos x sin h]/h sin (0/2)) + cos x (1) f\u2019(x) = \u2013 sin x(0) + cos x Thus, the derivative of sin x is cos x, is derived. ### Derivative of Sin x Examples Now, we have to find the derivative of sin (x+1), using the 1st principle. Hence, the derivative of sin (x+1), with respect to x is cos (x+1). Find the derivative of sin 2x. **To find:** derivative of sin 2x. Hence, the derivative of sin 2x is 2 cos 2x. : r/calculus : r/calculus Image 1: r/calculus icon Go to calculus r/calculus Image 3: r/calculus iconr/calculus Welcome to r/calculus - a space for learning calculus and related disciplines. We learned in class that the derivative of sin(x) is cos(x). New to Reddit? * Reddit reReddit: Top posts of October 6, 2016 * * * * Reddit reReddit: Top posts of October 2016 * * * * Reddit reReddit: Top posts of 2016 * * * * Reddit Meta * Games * Gaming News & Discussion * Other Games * Action Movies & Series * Animated Movies & Series * Comedy Movies & Series * Romance Movies & Series * Superhero Movies & Series * About Reddit * Best of Reddit ddx[sinx]=cosx Certainly, by the limit definition of the derivative, we know that ddx[sinx]=limh\u21920sin(x+h)\u2212sin(x)h ddx[sinx]=limh\u21920sinxcosh+cosxsinh\u2212sinxh Seeing all of the components of a similar limit in our expression for the derivative, (i.e., there is a sinh in the numerator, an h in the denominator, and both of these are inside a limit as h\u21920), we use algebra and the limit laws to reveal this known limit in our expression: ddx[sinx]=limh\u21920[cosxsinhh+sinxcosh\u2212sinxh]=limh\u21920[cosx\u22c5sinhh+sinxcosh\u2212sinxh]=limh\u21920cosx\u22c5limh\u21920sinhh+limh\u21920sinxcosh\u2212sinxh Note, the first limit in the last line above is of an expression that does not depend on h, and hence effectively the limit of a constant. ddx[sinx]=cosx+limh\u21920sinxcosh\u2212sinxh Pulling out the common factor of sinx in the remaining limit and splitting the resulting product with the limit laws again, we see another familiar limit -- one we which we know equals zero... ddx[sinx]=cosx+limh\u21920sinx(cosh\u22121)h=cosx+[limh\u21920sinx]\u22c5[limh\u21920cosh\u22121h]=cosx+sinx\u22c50=cosx",
|
| 142 |
+
"feedback": "its too long!",
|
| 143 |
+
"rating": null
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"query": "derivative of sinx",
|
| 147 |
+
"answer": "The derivative of sin x is the rate of change with respect to angle ie, x. The resultant of the derivative of sin x is cos x. Here also we are going to prove the derivative of sin x to be -cos x using the first principle. The derivative of sin x is cos x. Thus, we have proved that the derivative of sin x is cos x. Therefore, the derivative of sin is cos x and is proved by using the quotient rule. Derivative of Sin x Worksheet Therefore, the derivative of sin x is cos x. * The derivative of sin x is cos x. Thus, the derivative of sin 3x is 3 cos 3x. Therefore, the derivative of sin x by first principle is cos x. We know that the derivative of sin x is cos x. So the derivative of sin x2 using this and using the chain rule is cos x2\u00b7 d/dx(x2). The derivative of sin(x) is cos(x). Why? The derivative of any given function is simply the slope of the tangent line to original function ## Derivative of sin x using the First Principle Method f\u2019(x) = limh\u21920 [sin x cos h + cos x sin h \u2013 sin x]/h f\u2019(x) = limh\u21920 [-sin x(1-cosh) + cos x sin h]/h sin (0/2)) + cos x (1) f\u2019(x) = \u2013 sin x(0) + cos x Thus, the derivative of sin x is cos x, is derived. ### Derivative of Sin x Examples Now, we have to find the derivative of sin (x+1), using the 1st principle. Hence, the derivative of sin (x+1), with respect to x is cos (x+1). Find the derivative of sin 2x. **To find:** derivative of sin 2x. Hence, the derivative of sin 2x is 2 cos 2x. : r/calculus : r/calculus Image 1: r/calculus icon Go to calculus r/calculus Image 3: r/calculus iconr/calculus Welcome to r/calculus - a space for learning calculus and related disciplines. We learned in class that the derivative of sin(x) is cos(x). New to Reddit? * Reddit reReddit: Top posts of October 6, 2016 * * * * Reddit reReddit: Top posts of October 2016 * * * * Reddit reReddit: Top posts of 2016 * * * * Reddit Meta * Games * Gaming News & Discussion * Other Games * Action Movies & Series * Animated Movies & Series * Comedy Movies & Series * Romance Movies & Series * Superhero Movies & Series * About Reddit * Best of Reddit",
|
| 148 |
+
"feedback": "liitle bit small",
|
| 149 |
+
"rating": null
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"timestamp": "2026-03-07T18:08:36.330731",
|
| 153 |
+
"original_input": "WHAT IS DERIVATIVE OF SINX",
|
| 154 |
+
"parsed_question": null,
|
| 155 |
+
"retrieved_context": null,
|
| 156 |
+
"final_answer": "Derivative of Sine Function\n\nAssumptions\n- The function is f(x) = sin(x)\n- The variable x is a real number\n\nStep 1\nTo find the derivative of sin(x), we will use the definition of a derivative as a limit.\nf'(x) = lim(h -> 0) [f(x + h) - f(x)]/h\n\nStep 2\nWe will apply the definition to the sine function, using the angle addition formula for sine.\nf'(x) = lim(h -> 0) [sin(x + h) - sin(x)]/h\n\nStep 3\nUsing the angle addition formula for sine, we can rewrite sin(x + h) as sin(x)cos(h) + cos(x)sin(h).\nf'(x) = lim(h -> 0) [sin(x)cos(h) + cos(x)sin(h) - sin(x)]/h\n\nStep 4\nWe can simplify the expression by canceling out sin(x) and dividing the numerator and denominator by h.\nf'(x) = lim(h -> 0) [cos(h) + cos(x)sin(h)/h - 1]/1\n\nStep 5\nAs h approaches 0, cos(h) approaches 1 and sin(h)/h approaches 1.\nf'(x) = 1",
|
| 157 |
+
"verifier_outcome": null,
|
| 158 |
+
"user_feedback": "THE ANSWER SHOULD BE COSX",
|
| 159 |
+
"rating": "negative"
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
"timestamp": "2026-03-07T18:09:56.957106",
|
| 163 |
+
"original_input": "integration of sinx",
|
| 164 |
+
"parsed_question": null,
|
| 165 |
+
"retrieved_context": null,
|
| 166 |
+
"final_answer": "Integration of Sine Function\n\nAssumptions\nThe function to be integrated is sin(x).\nThe variable of integration is x.\n\nStep 1\nTo integrate sin(x), we can use the basic integration rule.\n\u222bsin(x) dx = -cos(x)\n\nStep 2\nWe can verify this result by differentiating the result from step 1.\nd(-cos(x))/dx = sin(x)\n\nFinal Answer\n\u222bsin(x) dx = -cos(x)",
|
| 167 |
+
"verifier_outcome": null,
|
| 168 |
+
"user_feedback": "Good",
|
| 169 |
+
"rating": "positive"
|
| 170 |
+
}
|
| 171 |
+
]
|
data/parsed/03b7e3b6-f742-4668-8238-f329df6ce0c7.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"problem_text": "what is derivative of sinx",
|
| 3 |
+
"topic": "calculus",
|
| 4 |
+
"variables": [
|
| 5 |
+
"v",
|
| 6 |
+
"s",
|
| 7 |
+
"t",
|
| 8 |
+
"f",
|
| 9 |
+
"x",
|
| 10 |
+
"w",
|
| 11 |
+
"a",
|
| 12 |
+
"o",
|
| 13 |
+
"d",
|
| 14 |
+
"n",
|
| 15 |
+
"e",
|
| 16 |
+
"i",
|
| 17 |
+
"h",
|
| 18 |
+
"r"
|
| 19 |
+
],
|
| 20 |
+
"constraints": [],
|
| 21 |
+
"needs_clarification": false
|
| 22 |
+
}
|
data/uploads/0e118489-9862-4d85-96e9-27a8027258dc.webm
ADDED
|
Binary file (61.2 kB). View file
|
|
|
data/uploads/1a6c3053-9063-4c82-94d7-a0d394f8279a.webm
ADDED
|
Binary file (84.3 kB). View file
|
|
|
data/uploads/335e4b51-5ee5-4b55-95c5-f303f30c66c4.png
ADDED
|
data/uploads/45be71fd-514d-4081-a611-861ba7a091a3.webm
ADDED
|
Binary file (58.3 kB). View file
|
|
|
data/uploads/50737f2b-de46-4f19-9284-29bdfd47456d.webm
ADDED
|
Binary file (54.4 kB). View file
|
|
|
data/uploads/6a76d880-7984-4bb9-a20f-ba0bf9299906.png
ADDED
|
data/uploads/9bc29088-4aae-4406-a1c4-f1d47085296c.png
ADDED
|
data/uploads/9d89b6e8-761f-40e7-9543-f07da13ada0d.webm
ADDED
|
Binary file (86.3 kB). View file
|
|
|
data/uploads/9f688908-d1fd-4730-b878-e8e2fc27f618.png
ADDED
|
data/uploads/a123c319-5b6b-4db0-8109-08c118198a56.png
ADDED
|
data/uploads/e277bc8a-5830-4795-82e1-f136f3e67046.png
ADDED
|
data/uploads/ef53575a-9995-4fcb-9a68-1abb44cbf719.webm
ADDED
|
Binary file (92.1 kB). View file
|
|
|
data/uploads/f5c8e2cf-2c63-4acc-923d-f0c449e425f7.webm
ADDED
|
Binary file (55.4 kB). View file
|
|
|
data/uploads/hard-math-9.jpg
ADDED
|
data/uploads/recording.webm
ADDED
|
Binary file (83.4 kB). View file
|
|
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
services:
|
| 2 |
+
backend:
|
| 3 |
+
build: .
|
| 4 |
+
ports:
|
| 5 |
+
- "8000:8000"
|
| 6 |
+
environment:
|
| 7 |
+
- PORT=8000
|
| 8 |
+
command: uvicorn main:app --host 0.0.0.0 --port 8000
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
frontend:
|
| 12 |
+
build:
|
| 13 |
+
context: ./Frontend/react-app
|
| 14 |
+
dockerfile: Dockerfile
|
| 15 |
+
ports:
|
| 16 |
+
- "3000:80"
|
| 17 |
+
|
| 18 |
+
backend_v2:
|
| 19 |
+
build:
|
| 20 |
+
context: .
|
| 21 |
+
dockerfile: Dockerfile.v2
|
| 22 |
+
container_name: math_agent_v2
|
| 23 |
+
ports:
|
| 24 |
+
- "8080:8000"
|
| 25 |
+
environment:
|
| 26 |
+
- PORT=8000
|
| 27 |
+
command: uvicorn main:app --host 0.0.0.0 --port 7860
|
main.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.environ["USE_TF"] = "0"
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
# Add the current directory to Python path so Backend imports work
|
| 6 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 7 |
+
sys.path.insert(0, current_dir)
|
| 8 |
+
|
| 9 |
+
from fastapi import FastAPI
|
| 10 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
+
from router.rag_router import router as rag_router
|
| 12 |
+
from router.feedback_router import router as feedback_router
|
| 13 |
+
app = FastAPI(
|
| 14 |
+
title="Math Routing Agent ",
|
| 15 |
+
description="Hello",
|
| 16 |
+
version="1.0.0"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
app.add_middleware(
|
| 20 |
+
CORSMiddleware,
|
| 21 |
+
allow_origins=["*"], # you can restrict this later to your React app
|
| 22 |
+
allow_credentials=True,
|
| 23 |
+
allow_methods=["*"],
|
| 24 |
+
allow_headers=["*"],
|
| 25 |
+
)
|
| 26 |
+
#Routers
|
| 27 |
+
app.include_router(rag_router, prefix="/api/query", tags=["RAG Router"])
|
| 28 |
+
app.include_router(feedback_router, prefix="/api/feedback", tags=["Feedback Router"])
|
| 29 |
+
# Endpoint
|
| 30 |
+
@app.get("/")
|
| 31 |
+
async def root():
|
| 32 |
+
return {"message": "Math Routing Agent API is on"}
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
import uvicorn
|
| 36 |
+
uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True)
|
requirements.txt
ADDED
|
Binary file (518 Bytes). View file
|
|
|
router/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# This file makes Python treat this directory as a package
|