Add files via upload

This commit is contained in:
FatihMakes authored and GitHub committed 2026-06-21 13:23:06 +03:00
1 parent fb46b5e6a1
commit 067f5289b2
26 files changed
+4189 -3033

No files matched your search

+28 -13
View File
@@ -29,6 +29,11 @@ def _get_base_dir() -> Path:
return Path(sys.executable).parent
return Path(__file__).resolve().parent.parent
def _get_api_key() -> str:
path = _get_base_dir() / "config" / "api_keys.json"
with open(path, "r", encoding="utf-8") as f:
return json.load(f)["gemini_api_key"]
def _get_macos_wifi_interface() -> str:
try:
result = subprocess.run(
@@ -564,24 +569,34 @@ _DANGEROUS_ACTIONS = {"restart", "shutdown"}
def _detect_action(description: str) -> dict:
from core.llm_client import call_llm_text
from google import genai as _genai
_client = _genai.Client(api_key=_get_api_key())
available = ", ".join(sorted(ACTION_MAP.keys())) + \
", volume_set, type_text, press_key, reload_n"
system = (
"You are an intent detector. Return ONLY a valid JSON object — "
"no explanation, no markdown."
)
prompt = (
f'User command (any language): "{description}"\n\n'
f"Available actions: {available}\n\n"
f'Return: {{"action": "action_name", "value": null_or_value}}\n'
f"Rules: volume_set→int 0-100; type_text→exact text; press_key→key name; reload_n→int."
)
prompt = f"""You are an intent detector for a computer control assistant.
The user issued a command (possibly in any language): "{description}"
Available actions: {available}
Return ONLY a valid JSON object:
{{"action": "action_name", "value": null_or_value}}
Rules:
- Pick the single best matching action from the available list.
- For volume_set: value is an integer 0-100.
- For type_text: value is the exact text to type.
- For press_key: value is the key name (e.g. "f5", "tab", "enter").
- For reload_n: value is an integer (number of times to reload).
- If no clear match, pick the closest action.
- Return ONLY the JSON, no explanation, no markdown."""
try:
text = call_llm_text(prompt, system=system)
text = re.sub(r"```(?:json)?", "", text).strip().rstrip("`").strip()
resp = _client.models.generate_content(model="gemini-2.5-flash-lite", contents=prompt)
text = re.sub(r"```(?:json)?", "", resp.text).strip().rstrip("`").strip()
return json.loads(text)
except Exception as e:
print(f"[Settings] Intent detection failed: {e}")