server/rtc: fix topic output

This commit is contained in:
Mathieu Virbel
2023-08-01 19:12:51 +02:00
parent 99c9ba3e6b
commit d320558cc9
4 changed files with 57 additions and 13 deletions

View File

@@ -55,9 +55,13 @@ class LLM:
regex = r"```(json|javascript|)?(.*)```"
matches = re.findall(regex, result.strip(), re.MULTILINE | re.DOTALL)
if not matches:
return result
if matches:
result = matches[0][1]
else:
# maybe the prompt has been started with ```json
# so if text ends with ```, just remove it and use it as json
if result.endswith("```"):
result = result[:-3]
# we have a match, try to parse it
result = matches[0][1]
return json.loads(result.strip())