Spaces:
Running on Zero
Running on Zero
atakan commited on
Commit ·
1f68b63
1
Parent(s): 3e59ef3
fix: Simplify Colab notebook, fix rank_bm25 import handling, and clean up prompts
Browse files- ControlAI_Colab_Demo.ipynb +31 -19
- controlai_agent/prompts.py +1 -1
- controlai_rag/index.py +7 -2
- requirements.txt +13 -0
ControlAI_Colab_Demo.ipynb
CHANGED
|
@@ -4,13 +4,13 @@
|
|
| 4 |
"cell_type": "markdown",
|
| 5 |
"metadata": {},
|
| 6 |
"source": [
|
| 7 |
-
"# ControlAI: Open-Source
|
| 8 |
"\n",
|
| 9 |
"[](https://github.com/atakankahya/controlai-agent)\n",
|
| 10 |
"[](https://huggingface.co/atakankahya/ControlAI-Agent)\n",
|
| 11 |
"[](https://opensource.org/licenses/MIT)\n",
|
| 12 |
"\n",
|
| 13 |
-
"**ControlAI**
|
| 14 |
"\n",
|
| 15 |
"---"
|
| 16 |
]
|
|
@@ -19,7 +19,7 @@
|
|
| 19 |
"cell_type": "markdown",
|
| 20 |
"metadata": {},
|
| 21 |
"source": [
|
| 22 |
-
"### Step 1:
|
| 23 |
]
|
| 24 |
},
|
| 25 |
{
|
|
@@ -28,19 +28,17 @@
|
|
| 28 |
"metadata": {},
|
| 29 |
"outputs": [],
|
| 30 |
"source": [
|
| 31 |
-
"# Clone the open-source repository\n",
|
| 32 |
"!git clone https://github.com/atakankahya/controlai-agent.git\n",
|
| 33 |
"%cd controlai-agent\n",
|
| 34 |
"\n",
|
| 35 |
-
"
|
| 36 |
-
"!pip install -q torch transformers accelerate scipy control cvxpy rich pyngrok uvicorn fastapi sentencepiece protobuf python-multipart"
|
| 37 |
]
|
| 38 |
},
|
| 39 |
{
|
| 40 |
"cell_type": "markdown",
|
| 41 |
"metadata": {},
|
| 42 |
"source": [
|
| 43 |
-
"### Step 2:
|
| 44 |
]
|
| 45 |
},
|
| 46 |
{
|
|
@@ -49,16 +47,24 @@
|
|
| 49 |
"metadata": {},
|
| 50 |
"outputs": [],
|
| 51 |
"source": [
|
| 52 |
-
"
|
| 53 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
]
|
| 55 |
},
|
| 56 |
{
|
| 57 |
"cell_type": "markdown",
|
| 58 |
"metadata": {},
|
| 59 |
"source": [
|
| 60 |
-
"### Step 3:
|
| 61 |
-
"
|
| 62 |
]
|
| 63 |
},
|
| 64 |
{
|
|
@@ -67,16 +73,22 @@
|
|
| 67 |
"metadata": {},
|
| 68 |
"outputs": [],
|
| 69 |
"source": [
|
| 70 |
-
"
|
| 71 |
-
"
|
| 72 |
-
"
|
|
|
|
|
|
|
| 73 |
"\n",
|
| 74 |
-
"#
|
| 75 |
-
"
|
| 76 |
-
"time.sleep(3)\n",
|
| 77 |
"\n",
|
| 78 |
-
"#
|
| 79 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
]
|
| 81 |
}
|
| 82 |
],
|
|
|
|
| 4 |
"cell_type": "markdown",
|
| 5 |
"metadata": {},
|
| 6 |
"source": [
|
| 7 |
+
"# ControlAI: Open-Source AI Agent for Control Systems Engineering\n",
|
| 8 |
"\n",
|
| 9 |
"[](https://github.com/atakankahya/controlai-agent)\n",
|
| 10 |
"[](https://huggingface.co/atakankahya/ControlAI-Agent)\n",
|
| 11 |
"[](https://opensource.org/licenses/MIT)\n",
|
| 12 |
"\n",
|
| 13 |
+
"Welcome to the official **ControlAI** interactive notebook! You can test control engineering problems, LQR synthesis, Bode plots, and ODE simulations directly in Google Colab.\n",
|
| 14 |
"\n",
|
| 15 |
"---"
|
| 16 |
]
|
|
|
|
| 19 |
"cell_type": "markdown",
|
| 20 |
"metadata": {},
|
| 21 |
"source": [
|
| 22 |
+
"### Step 1: Install Dependencies"
|
| 23 |
]
|
| 24 |
},
|
| 25 |
{
|
|
|
|
| 28 |
"metadata": {},
|
| 29 |
"outputs": [],
|
| 30 |
"source": [
|
|
|
|
| 31 |
"!git clone https://github.com/atakankahya/controlai-agent.git\n",
|
| 32 |
"%cd controlai-agent\n",
|
| 33 |
"\n",
|
| 34 |
+
"!pip install -q torch transformers accelerate scipy control cvxpy rich rank-bm25 matplotlib"
|
|
|
|
| 35 |
]
|
| 36 |
},
|
| 37 |
{
|
| 38 |
"cell_type": "markdown",
|
| 39 |
"metadata": {},
|
| 40 |
"source": [
|
| 41 |
+
"### Step 2: Initialize the ControlAI Agent"
|
| 42 |
]
|
| 43 |
},
|
| 44 |
{
|
|
|
|
| 47 |
"metadata": {},
|
| 48 |
"outputs": [],
|
| 49 |
"source": [
|
| 50 |
+
"import sys\n",
|
| 51 |
+
"from pathlib import Path\n",
|
| 52 |
+
"from IPython.display import display, Markdown, Image\n",
|
| 53 |
+
"import matplotlib.pyplot as plt\n",
|
| 54 |
+
"\n",
|
| 55 |
+
"from controlai_agent.orchestrator import ControlAIAgent\n",
|
| 56 |
+
"\n",
|
| 57 |
+
"print(\"Loading ControlAI Engine with Qwen 3B...\")\n",
|
| 58 |
+
"agent = ControlAIAgent(model_path=\"Qwen/Qwen2.5-3B-Instruct\")\n",
|
| 59 |
+
"print(\"ControlAI Engine ready!\")"
|
| 60 |
]
|
| 61 |
},
|
| 62 |
{
|
| 63 |
"cell_type": "markdown",
|
| 64 |
"metadata": {},
|
| 65 |
"source": [
|
| 66 |
+
"### Step 3: Ask Any Control Engineering Question\n",
|
| 67 |
+
"You can edit the prompt below to test your own dynamical systems, transfer functions, or optimal control problems."
|
| 68 |
]
|
| 69 |
},
|
| 70 |
{
|
|
|
|
| 73 |
"metadata": {},
|
| 74 |
"outputs": [],
|
| 75 |
"source": [
|
| 76 |
+
"# Enter your engineering query here:\n",
|
| 77 |
+
"prompt = \"Design an LQR controller for A=[[0, 1], [-2, -3]], B=[[0], [1]], Q=diag([10, 1]), R=1 and simulate the step response.\"\n",
|
| 78 |
+
"\n",
|
| 79 |
+
"print(f\"User Query: {prompt}\\n\")\n",
|
| 80 |
+
"result = agent.run(prompt)\n",
|
| 81 |
"\n",
|
| 82 |
+
"# Display formatted response\n",
|
| 83 |
+
"display(Markdown(result.final_response))\n",
|
|
|
|
| 84 |
"\n",
|
| 85 |
+
"# Display any generated simulation plots\n",
|
| 86 |
+
"for plot_path_rel in result.plots:\n",
|
| 87 |
+
" clean_name = Path(plot_path_rel).name\n",
|
| 88 |
+
" local_path = Path(\"outputs/plots\") / clean_name\n",
|
| 89 |
+
" if local_path.exists():\n",
|
| 90 |
+
" print(f\"\\nGenerated Simulation Plot: {clean_name}\")\n",
|
| 91 |
+
" display(Image(filename=str(local_path)))"
|
| 92 |
]
|
| 93 |
}
|
| 94 |
],
|
controlai_agent/prompts.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
CONTROLAI_SYSTEM_PROMPT = """You are ControlAI, a premier AI research scientist and expert engineering agent specialized in control systems engineering, applied mathematics, robotics, and dynamical systems.
|
| 2 |
|
| 3 |
### 4-Stage Mathematical Reasoning & Proof Standard:
|
| 4 |
When answering theoretical principles, derivations, proofs, comparisons, or limitation questions:
|
|
|
|
| 1 |
+
CONTROLAI_SYSTEM_PROMPT = r"""You are ControlAI, a premier AI research scientist and expert engineering agent specialized in control systems engineering, applied mathematics, robotics, and dynamical systems.
|
| 2 |
|
| 3 |
### 4-Stage Mathematical Reasoning & Proof Standard:
|
| 4 |
When answering theoretical principles, derivations, proofs, comparisons, or limitation questions:
|
controlai_rag/index.py
CHANGED
|
@@ -8,7 +8,10 @@ import re
|
|
| 8 |
from pathlib import Path
|
| 9 |
from typing import Any
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
from controlai_rag.chunker import Chunk
|
| 14 |
|
|
@@ -26,10 +29,12 @@ class ControlRAGIndex:
|
|
| 26 |
def __init__(self, index_dir: Path = INDEX_DIR) -> None:
|
| 27 |
self.index_dir = index_dir
|
| 28 |
self.chunks: list[dict[str, Any]] = []
|
| 29 |
-
self.bm25:
|
| 30 |
self._load_if_exists()
|
| 31 |
|
| 32 |
def build_from_chunks(self, chunks: list[Chunk]) -> None:
|
|
|
|
|
|
|
| 33 |
self.chunks = [c.to_dict() for c in chunks]
|
| 34 |
corpus = [tokenize_corpus(c.text) for c in chunks]
|
| 35 |
self.bm25 = BM25Okapi(corpus)
|
|
|
|
| 8 |
from pathlib import Path
|
| 9 |
from typing import Any
|
| 10 |
|
| 11 |
+
try:
|
| 12 |
+
from rank_bm25 import BM25Okapi
|
| 13 |
+
except ImportError:
|
| 14 |
+
BM25Okapi = None
|
| 15 |
|
| 16 |
from controlai_rag.chunker import Chunk
|
| 17 |
|
|
|
|
| 29 |
def __init__(self, index_dir: Path = INDEX_DIR) -> None:
|
| 30 |
self.index_dir = index_dir
|
| 31 |
self.chunks: list[dict[str, Any]] = []
|
| 32 |
+
self.bm25: Any | None = None
|
| 33 |
self._load_if_exists()
|
| 34 |
|
| 35 |
def build_from_chunks(self, chunks: list[Chunk]) -> None:
|
| 36 |
+
if BM25Okapi is None:
|
| 37 |
+
return
|
| 38 |
self.chunks = [c.to_dict() for c in chunks]
|
| 39 |
corpus = [tokenize_corpus(c.text) for c in chunks]
|
| 40 |
self.bm25 = BM25Okapi(corpus)
|
requirements.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.0.0
|
| 2 |
+
transformers>=4.40.0
|
| 3 |
+
accelerate>=0.28.0
|
| 4 |
+
scipy>=1.11.0
|
| 5 |
+
numpy>=1.24.0
|
| 6 |
+
matplotlib>=3.7.0
|
| 7 |
+
control>=0.9.4
|
| 8 |
+
cvxpy>=1.4.0
|
| 9 |
+
rich>=13.7.0
|
| 10 |
+
rank-bm25>=0.2.2
|
| 11 |
+
fastapi>=0.110.0
|
| 12 |
+
uvicorn>=0.28.0
|
| 13 |
+
python-multipart>=0.0.9
|