Spaces:
Running
Running
noahlee1234 commited on
Commit ·
0f4cba0
1
Parent(s): f371495
sec: hide generated CAD code in worker logs and API response by default
Browse files- apps/cad-worker/README.md +2 -0
- apps/cad-worker/main.py +5 -2
apps/cad-worker/README.md
CHANGED
|
@@ -35,6 +35,8 @@ OPENROUTER_MODEL=openai/gpt-4o-mini # or any OpenRouter model id you want
|
|
| 35 |
OPENROUTER_API_URL=https://openrouter.ai/api/v1/chat/completions # optional override
|
| 36 |
OPENROUTER_REFERER=https://huggingface.co/spaces/noahtheboa/naturalcad # optional
|
| 37 |
OPENROUTER_TITLE=NaturalCAD # optional
|
|
|
|
|
|
|
| 38 |
```
|
| 39 |
|
| 40 |
Also required for uploads/logging:
|
|
|
|
| 35 |
OPENROUTER_API_URL=https://openrouter.ai/api/v1/chat/completions # optional override
|
| 36 |
OPENROUTER_REFERER=https://huggingface.co/spaces/noahtheboa/naturalcad # optional
|
| 37 |
OPENROUTER_TITLE=NaturalCAD # optional
|
| 38 |
+
NATURALCAD_LOG_CODE=false # optional, default false
|
| 39 |
+
NATURALCAD_INCLUDE_CODE_IN_RESPONSE=false # optional, default false
|
| 40 |
```
|
| 41 |
|
| 42 |
Also required for uploads/logging:
|
apps/cad-worker/main.py
CHANGED
|
@@ -553,6 +553,8 @@ def generate_cad(prompt: str, mode: str = "part", output_type: str = "3d_solid")
|
|
| 553 |
|
| 554 |
openrouter_api_url = os.environ.get("OPENROUTER_API_URL", "https://openrouter.ai/api/v1/chat/completions")
|
| 555 |
openrouter_model = os.environ.get("OPENROUTER_MODEL", "anthropic/claude-opus-4.7")
|
|
|
|
|
|
|
| 556 |
|
| 557 |
mode_hint = _MODE_HINTS.get(mode, _MODE_HINTS["part"])
|
| 558 |
output_rule = _OUTPUT_RULES.get(output_type, _OUTPUT_RULES["3d_solid"])
|
|
@@ -621,7 +623,8 @@ def generate_cad(prompt: str, mode: str = "part", output_type: str = "3d_solid")
|
|
| 621 |
print(f"LLM call failed: {e}")
|
| 622 |
return {"error": "LLM call failed. Please retry."}
|
| 623 |
|
| 624 |
-
|
|
|
|
| 625 |
|
| 626 |
from build123d import export_stl, export_step
|
| 627 |
|
|
@@ -768,7 +771,7 @@ def generate_cad(prompt: str, mode: str = "part", output_type: str = "3d_solid")
|
|
| 768 |
"model": openrouter_model,
|
| 769 |
"urls": urls,
|
| 770 |
"prompt": prompt,
|
| 771 |
-
"generated_code": generated_code,
|
| 772 |
}
|
| 773 |
|
| 774 |
|
|
|
|
| 553 |
|
| 554 |
openrouter_api_url = os.environ.get("OPENROUTER_API_URL", "https://openrouter.ai/api/v1/chat/completions")
|
| 555 |
openrouter_model = os.environ.get("OPENROUTER_MODEL", "anthropic/claude-opus-4.7")
|
| 556 |
+
log_generated_code = os.environ.get("NATURALCAD_LOG_CODE", "false").strip().lower() in {"1", "true", "yes", "on"}
|
| 557 |
+
include_code_in_response = os.environ.get("NATURALCAD_INCLUDE_CODE_IN_RESPONSE", "false").strip().lower() in {"1", "true", "yes", "on"}
|
| 558 |
|
| 559 |
mode_hint = _MODE_HINTS.get(mode, _MODE_HINTS["part"])
|
| 560 |
output_rule = _OUTPUT_RULES.get(output_type, _OUTPUT_RULES["3d_solid"])
|
|
|
|
| 623 |
print(f"LLM call failed: {e}")
|
| 624 |
return {"error": "LLM call failed. Please retry."}
|
| 625 |
|
| 626 |
+
if log_generated_code:
|
| 627 |
+
print(f"Generated code:\n{generated_code}")
|
| 628 |
|
| 629 |
from build123d import export_stl, export_step
|
| 630 |
|
|
|
|
| 771 |
"model": openrouter_model,
|
| 772 |
"urls": urls,
|
| 773 |
"prompt": prompt,
|
| 774 |
+
"generated_code": generated_code if include_code_in_response else "",
|
| 775 |
}
|
| 776 |
|
| 777 |
|