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