File size: 1,095 Bytes
d06797b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""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)