Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/readme2demo/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def complete(system: str, user: str, model: str, max_tokens: int = 8192) -> LLMR

def extract_json(text: str) -> str:
"""Pull the first JSON object out of a response (handles ```json fences)."""
fence = re.search(r"```(?:json)?\s*\n(.*?)```", text, re.DOTALL)
fence = re.search(r"```(?:json)?\s*(.*?)\s*```", text, re.DOTALL)
if fence:
return fence.group(1).strip()
start = text.find("{")
Expand Down
6 changes: 6 additions & 0 deletions tests/test_llm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ def test_anthropic_default_model_matches_config():
assert llm.PROVIDERS["anthropic"].default_model == Config().model


def test_extract_json_accepts_single_line_fenced_json():
text = 'diagnostic {not json} ```json {"ok": true}```'

assert llm.extract_json(text) == '{"ok": true}'


# -- openai backend -----------------------------------------------------------------


Expand Down