Break *prompt* into a numbered plan. Uses the local 0.5B on port 8081 by default. When CODEY_BACKEND_P (or CODEY_BACKEND) is a remote backend, routes there instead so the 0.5B server does not need to be running.
(prompt: str)
| 221 | |
| 222 | |
| 223 | def get_plan(prompt: str) -> Optional[List[str]]: |
| 224 | """ |
| 225 | Break *prompt* into a numbered plan. |
| 226 | |
| 227 | Uses the local 0.5B on port 8081 by default. |
| 228 | When CODEY_BACKEND_P (or CODEY_BACKEND) is a remote backend, routes |
| 229 | there instead so the 0.5B server does not need to be running. |
| 230 | """ |
| 231 | try: |
| 232 | from utils.config import is_remote_planner_backend |
| 233 | if is_remote_planner_backend(): |
| 234 | return _get_plan_remote(prompt) |
| 235 | except ImportError: |
| 236 | pass |
| 237 | |
| 238 | try: |
| 239 | from utils.config import PLANNER_TEMPERATURE, PLANNER_MAX_TOKENS |
| 240 | temperature = PLANNER_TEMPERATURE |
| 241 | max_tokens = PLANNER_MAX_TOKENS |
| 242 | except ImportError: |
| 243 | temperature = 0.2 |
| 244 | max_tokens = 512 |
| 245 | |
| 246 | try: |
| 247 | from utils.config import PLANND_SERVER_PORT |
| 248 | port = PLANND_SERVER_PORT |
| 249 | except ImportError: |
| 250 | port = 8081 |
| 251 | |
| 252 | payload = { |
| 253 | "model": "plannd", |
| 254 | "messages": [ |
| 255 | {"role": "system", "content": PLANNER_PROMPT}, |
| 256 | {"role": "user", "content": prompt}, |
| 257 | ], |
| 258 | "max_tokens": max_tokens, |
| 259 | "temperature": temperature, |
| 260 | "stream": False, |
| 261 | } |
| 262 | |
| 263 | url = f"http://127.0.0.1:{port}/v1/chat/completions" |
| 264 | req = urllib.request.Request( |
| 265 | url, |
| 266 | data=json.dumps(payload).encode("utf-8"), |
| 267 | headers={"Content-Type": "application/json"}, |
| 268 | method="POST", |
| 269 | ) |
| 270 | |
| 271 | try: |
| 272 | with urllib.request.urlopen(req, timeout=60) as response: |
| 273 | result = json.loads(response.read().decode("utf-8")) |
| 274 | choices = result.get("choices", []) |
| 275 | if not choices: |
| 276 | return None |
| 277 | raw = choices[0].get("message", {}).get("content", "").strip() |
| 278 | if not raw: |
| 279 | return None |
| 280 | steps = parse_steps(raw) |
nothing calls this directly
no test coverage detected