Skip to content

Commit

Permalink
Remove markdown formatting if present
Browse files Browse the repository at this point in the history
  • Loading branch information
caufieldjh committed Aug 14, 2024
1 parent adafb1d commit 271b78b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/curate_gpt/agents/mapping_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def match(
raise ValueError(f"Prompt too long: {prompt}.")
kb_results.pop()
response = model.prompt(prompt)
# Need to remove Markdown formatting here or it won't parse as JSON
response_text = response.text()
if response_text.startswith("```json"):
response_text = response_text[7:-3]
mappings = []
try:
for m in json.loads(response_text):
Expand All @@ -154,6 +157,7 @@ def match(
)
)
except json.decoder.JSONDecodeError:
# This returns an empty set of mappings, but the prompt and response text are retained
return MappingSet(mappings=mappings, prompt=prompt, response_text=response_text)

return MappingSet(mappings=mappings, prompt=prompt, response_text=response_text)
Expand Down

0 comments on commit 271b78b

Please sign in to comment.