Jarvis2345 commited on
Commit
618d304
·
verified ·
1 Parent(s): c6124c6

deploy(S4): Blender headless pipeline + WebAR client + backend fixes

Browse files
Files changed (1) hide show
  1. backend/services/token_manager.py +15 -6
backend/services/token_manager.py CHANGED
@@ -26,15 +26,24 @@ from backend.services.usb_vault import KeyDomain, resolve_vault_key
26
  def get_runtime_location() -> str:
27
  return "cloud" if os.environ.get("SPACE_ID") else "pc"
28
 
29
- def _persona_system_prompt(persona: str) -> str:
 
 
 
 
 
 
30
  """The identity prompt for the EXPLICITLY requested persona.
31
 
32
  The mobile app (and other callers) pass the persona they want per-turn, so
33
  we select on that string directly rather than the persisted global mode.
34
- Without this, LLM replies carry no JARVIS/FRIDAY character at all the
35
- identity file that is supposed to be the source of truth was being ignored
36
- on the primary /api/chat path.
 
37
  """
 
 
38
  try:
39
  from modules.assistant_identity import (
40
  JARVIS_PERSONALITY_PROMPT, FRIDAY_PERSONALITY_PROMPT,
@@ -245,7 +254,7 @@ def _nvidia_fallback_call_sync(prompt: str, task_id: str, task_type: str, partia
245
  if not partial_so_far:
246
  # NVIDIA models take no separate system channel here, so the persona
247
  # prompt is prepended (same place the hive-mind context goes).
248
- _sys = _persona_system_prompt(persona)
249
  actual_prompt = (_sys + "\n\n" if _sys else "") + omni_context + actual_prompt
250
 
251
  # Delegate to the NVIDIA Vault API directly
@@ -276,7 +285,7 @@ def _gemini_call_sync(prompt: str, task_id: str, task_type: str,
276
 
277
  # Shape the reply in the active assistant's voice (JARVIS/FRIDAY). Skip on a
278
  # resume continuation so we don't restate the persona mid-sentence.
279
- _sys = _persona_system_prompt(persona) if not partial_so_far else None
280
  model = genai.GenerativeModel(MODEL, system_instruction=_sys) if _sys else genai.GenerativeModel(MODEL)
281
  actual_prompt = _build_resume_prompt(prompt, partial_so_far, _extract_last_word(partial_so_far))
282
  if not partial_so_far:
 
26
  def get_runtime_location() -> str:
27
  return "cloud" if os.environ.get("SPACE_ID") else "pc"
28
 
29
+ # Only the conversational path should be shaped in the assistant's voice.
30
+ # Structured task types (blueprint JSON, code implementation, research digests,
31
+ # captcha/osint payloads) must stay clean — a "You are JARVIS…" preamble there
32
+ # corrupts JSON/code output.
33
+ _PERSONA_TASK_TYPES = {"general", "gaming"}
34
+
35
+ def _persona_system_prompt(persona: str, task_type: str = "general") -> str:
36
  """The identity prompt for the EXPLICITLY requested persona.
37
 
38
  The mobile app (and other callers) pass the persona they want per-turn, so
39
  we select on that string directly rather than the persisted global mode.
40
+ Without this, conversational LLM replies carry no JARVIS/FRIDAY character —
41
+ the identity file that is supposed to be the source of truth was being
42
+ ignored on the primary /api/chat path. Returns "" for non-conversational
43
+ task types so structured output is never polluted.
44
  """
45
+ if task_type not in _PERSONA_TASK_TYPES:
46
+ return ""
47
  try:
48
  from modules.assistant_identity import (
49
  JARVIS_PERSONALITY_PROMPT, FRIDAY_PERSONALITY_PROMPT,
 
254
  if not partial_so_far:
255
  # NVIDIA models take no separate system channel here, so the persona
256
  # prompt is prepended (same place the hive-mind context goes).
257
+ _sys = _persona_system_prompt(persona, task_type)
258
  actual_prompt = (_sys + "\n\n" if _sys else "") + omni_context + actual_prompt
259
 
260
  # Delegate to the NVIDIA Vault API directly
 
285
 
286
  # Shape the reply in the active assistant's voice (JARVIS/FRIDAY). Skip on a
287
  # resume continuation so we don't restate the persona mid-sentence.
288
+ _sys = _persona_system_prompt(persona, task_type) if not partial_so_far else None
289
  model = genai.GenerativeModel(MODEL, system_instruction=_sys) if _sys else genai.GenerativeModel(MODEL)
290
  actual_prompt = _build_resume_prompt(prompt, partial_so_far, _extract_last_word(partial_so_far))
291
  if not partial_so_far: