fix(discord_bot): unified prompt JSON '{' parsing fallback
This commit is contained in:
@@ -8,25 +8,11 @@ sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="repla
|
||||
sys.path.insert(0, ".")
|
||||
|
||||
from core.gemini_caller import GeminiCaller
|
||||
|
||||
from api.discord_bot import _parse_unified_response
|
||||
|
||||
def extract_mode(raw):
|
||||
start = raw.find("{")
|
||||
if start == -1:
|
||||
return "NO_JSON"
|
||||
depth = 0
|
||||
for i in range(start, len(raw)):
|
||||
if raw[i] == "{":
|
||||
depth += 1
|
||||
elif raw[i] == "}":
|
||||
depth -= 1
|
||||
if depth == 0:
|
||||
try:
|
||||
p = json.loads(raw[start : i + 1])
|
||||
return p.get("mode", "?")
|
||||
except json.JSONDecodeError:
|
||||
return "PARSE_ERR"
|
||||
return "NO_CLOSE"
|
||||
parsed = _parse_unified_response(raw)
|
||||
return parsed.get("mode", "?")
|
||||
|
||||
|
||||
async def main():
|
||||
|
||||
Reference in New Issue
Block a user