Download nova_code_request.py from noah33565/Poloniu: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/noah33565/Poloniu/resolve/main/nova_code_request.py
- Command line
-
hf download hf://spaces/noah33565/Poloniu/nova_code_request.py
-
curl -L -o nova_code_request.py https://huggingface.co/spaces/noah33565/Poloniu/resolve/main/nova_code_request.py
1.1 kB
| """Helpers for detecting whether a prompt is a clear programming request.""" | |
| from __future__ import annotations | |
| import re | |
| _CODE_REQUEST = re.compile( | |
| r"(?:^|\s)(?:" | |
| r"(?:programm|skript|code|funktion|klasse|algorithmus|anwendung|tool|beispiel|debug|fehler|" | |
| r"schreib|erstell|implement|bau|verbess|optimier|analysier|test|konvertier|parse|" | |
| r"make|build|create|write|implement|fix|debug|refactor|test|convert)\w*" | |
| r"(?:\s+(?:ein|eine|einen|einem|einer|den|die|das|mit|für|von|und|oder)|$)" | |
| r"|(?:^|\s)(?:python|py|javascript|typescript|java|c\+\+|c#|csharp|rust|go|php|kotlin|ruby|dart|swift|sql|lua|luau)\b" | |
| r"(?:\s+(?:code|programm|skript|funktion|klasse|anwendung|beispiel))?" | |
| r")|```", | |
| re.IGNORECASE, | |
| ) | |
| def is_code_request(prompt: str) -> bool: | |
| """Return whether the prompt clearly asks for programming work.""" | |
| return bool(_CODE_REQUEST.search(prompt)) | |
| def should_execute_code(prompt: str) -> bool: | |
| """Return whether the prompt must use the programming-execution path.""" | |
| return is_code_request(prompt) | |