FIX: return all attributes in wikidata (#4786)

This commit is contained in:
Eric Hare 2024-11-22 09:35:26 -08:00 • committed by GitHub
commit 4ee53f2ea1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,21 +39,12 @@ class WikidataAPIWrapper(BaseModel):
def run(self, query: str) -> list[dict[str, Any]]: def run(self, query: str) -> list[dict[str, Any]]:
try: try:
results = self.results(query) results = self.results(query)
if not results: if results:
msg = "No search results found for the given query." return results
raise ToolException(msg) error_message = "No search results found for the given query."
# Process and structure the results raise ToolException(error_message)
return [
{
"label": result.get("label", ""),
"description": result.get("description", ""),
"concepturi": result.get("concepturi", ""),
"id": result.get("id", ""),
}
for result in results
]
except Exception as e: except Exception as e:
error_message = f"Error in Wikidata Search API: {e!s}" error_message = f"Error in Wikidata Search API: {e!s}"
@ -99,11 +90,7 @@ class WikidataAPIComponent(LCToolComponent):
data = [ data = [
Data( Data(
text=result["label"], text=result["label"],
metadata={ metadata=result,
"id": result["id"],
"concepturi": result["concepturi"],
"description": result["description"],
},
) )
for result in results for result in results
] ]