fix: update README for deployment instructions and improve code formatting
Some checks failed
Deploy BetterBot / deploy (push) Failing after 2s
Deploy BetterBot / notify (push) Successful in 3s

This commit is contained in:
Andre Kamarudin 2026-04-19 08:57:58 +08:00
parent 1d49a39c6a
commit eb8f283e44
3 changed files with 28 additions and 14 deletions

View file

@ -37,7 +37,12 @@ betterbot-specific files are:
| `compose/` | Docker compose for RackNerd with site-dir mounts | | `compose/` | Docker compose for RackNerd with site-dir mounts |
| `scripts/deploy-betterbot.sh` | Deploy script targeting RackNerd + Infisical | | `scripts/deploy-betterbot.sh` | Deploy script targeting RackNerd + Infisical |
To sync upstream changes, copy updated framework files from `code_anywhere/`. Deploys on RackNerd pull from the BetterBot Forgejo repo only. They do not
pull directly from CodeAnywhere during deploy.
If CodeAnywhere framework files change, sync those changes into this repo
first, commit them here, and then deploy BetterBot from its own `master`
branch.
## Deployment ## Deployment

15
main.py
View file

@ -35,9 +35,12 @@ def _get_advisor_usage(thread_id: str | None) -> dict | None:
return None return None
try: try:
from tools.advisor import get_advisor_usage from tools.advisor import get_advisor_usage
return get_advisor_usage(thread_id) return get_advisor_usage(thread_id)
except ImportError: except ImportError:
return None return None
from local_media_store import LocalMediaStore from local_media_store import LocalMediaStore
from model_selection import ( from model_selection import (
ModelSelection, ModelSelection,
@ -912,7 +915,9 @@ async def send_thread_message(thread_id: str, request: Request):
getattr(getattr(result, "data", None), "content", None) or getattr(result, "content", None) or "" getattr(getattr(result, "data", None), "content", None) or getattr(result, "content", None) or ""
) )
usage = extract_usage_and_cost( usage = extract_usage_and_cost(
selection.model, selection.provider, result, selection.model,
selection.provider,
result,
advisor_usage=_get_advisor_usage(thread_id), advisor_usage=_get_advisor_usage(thread_id),
) )
web_store.add_usage(thread_id, usage) web_store.add_usage(thread_id, usage)
@ -1071,15 +1076,19 @@ async def stream_thread_message(thread_id: str, request: Request):
# Emit advisor trace events if any # Emit advisor trace events if any
try: try:
from tools.advisor import get_advisor_traces from tools.advisor import get_advisor_traces
for trace in get_advisor_traces(thread_id): for trace in get_advisor_traces(thread_id):
yield _sse_event("progress", { yield _sse_event(
"progress",
{
"kind": "advisor_trace", "kind": "advisor_trace",
"question": trace.get("question", ""), "question": trace.get("question", ""),
"answer": trace.get("answer", ""), "answer": trace.get("answer", ""),
"stakes": trace.get("stakes", "medium"), "stakes": trace.get("stakes", "medium"),
"model": trace.get("model", ""), "model": trace.get("model", ""),
"duration_ms": trace.get("duration_ms", 0), "duration_ms": trace.get("duration_ms", 0),
}) },
)
except ImportError: except ImportError:
pass pass

View file

@ -23,7 +23,9 @@ logger = logging.getLogger(__name__)
def _build_projects() -> dict[str, dict[str, Any]]: def _build_projects() -> dict[str, dict[str, Any]]:
"""Build the project map from environment-configured directories.""" """Build the project map from environment-configured directories."""
site_dir = pathlib.Path(settings.SITE_DIR) if hasattr(settings, "SITE_DIR") else pathlib.Path("/site") site_dir = pathlib.Path(settings.SITE_DIR) if hasattr(settings, "SITE_DIR") else pathlib.Path("/site")
memoraiz_dir = pathlib.Path(settings.MEMORAIZ_DIR) if hasattr(settings, "MEMORAIZ_DIR") else pathlib.Path("/memoraiz") memoraiz_dir = (
pathlib.Path(settings.MEMORAIZ_DIR) if hasattr(settings, "MEMORAIZ_DIR") else pathlib.Path("/memoraiz")
)
projects: dict[str, dict[str, Any]] = {} projects: dict[str, dict[str, Any]] = {}
if site_dir.exists(): if site_dir.exists():
@ -102,9 +104,7 @@ def handle_tool_call(name: str, args: dict) -> str:
target = _resolve(base, subdir) if subdir else base target = _resolve(base, subdir) if subdir else base
files = [] files = []
for p in sorted(target.rglob("*")): for p in sorted(target.rglob("*")):
if p.is_file() and not any( if p.is_file() and not any(part in (".git", "node_modules", "__pycache__") for part in p.parts):
part in (".git", "node_modules", "__pycache__") for part in p.parts
):
files.append(str(p.relative_to(base))) files.append(str(p.relative_to(base)))
return "\n".join(files[:200]) if files else "(no files found)" return "\n".join(files[:200]) if files else "(no files found)"