Skip to content

Commit

Permalink
Avoid errors due to empty tables
Browse files Browse the repository at this point in the history
  • Loading branch information
caufieldjh committed Aug 14, 2024
1 parent b700904 commit adafb1d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/curate_gpt/agents/mapping_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,24 @@ def match(
response = model.prompt(prompt)
response_text = response.text()
mappings = []
for m in json.loads(response_text):
m = str(m)
if m in objects:
object_id = objects.get(m)["id"]
else:
object_id = m
mappings.append(
Mapping(
subject_id=query,
object_id=object_id,
predicate=MappingPredicate.SAME_AS,
prompt=prompt,
try:
for m in json.loads(response_text):
m = str(m)
if m in objects:
object_id = objects.get(m)["id"]
else:
object_id = m
mappings.append(
Mapping(
subject_id=query,
object_id=object_id,
predicate=MappingPredicate.SAME_AS,
prompt=prompt,
)
)
)
except json.decoder.JSONDecodeError:
return MappingSet(mappings=mappings, prompt=prompt, response_text=response_text)

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

def categorize_mappings(
Expand Down
2 changes: 2 additions & 0 deletions src/curate_gpt/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def ask_chatbot(query, expand=False) -> ChatResponse:


def html_table(rows: List[dict]) -> str:
if len(rows) == 0:
rows = [{"No data": "No data"}]
hdr = rows[0].keys()
html_content = '<table border="1">'
cols = [f"<th>{h}</th>" for h in hdr]
Expand Down

0 comments on commit adafb1d

Please sign in to comment.