Artsem Radzevich
commited on
Commit
·
8595b15
1
Parent(s):
58477b5
Fixed wiki
Browse files- tools/wiki_tool.py +33 -14
tools/wiki_tool.py
CHANGED
|
@@ -3,15 +3,36 @@ import wikipedia
|
|
| 3 |
|
| 4 |
class WikiTool(Tool):
|
| 5 |
def __init__(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
super().__init__(
|
| 7 |
-
name=
|
| 8 |
-
description=
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
"- {'action': 'summary', 'topic': 'France'}\n"
|
| 12 |
-
"- {'action': 'is_historical_country', 'country_name': 'Yugoslavia'}"
|
| 13 |
-
),
|
| 14 |
-
inputs=["action", "topic", "country_name"]
|
| 15 |
)
|
| 16 |
|
| 17 |
def fetch_summary(self, topic: str) -> str:
|
|
@@ -38,12 +59,10 @@ class WikiTool(Tool):
|
|
| 38 |
except Exception:
|
| 39 |
return "Unknown (error during lookup)"
|
| 40 |
|
| 41 |
-
def
|
| 42 |
-
action = args.get("action")
|
| 43 |
-
|
| 44 |
if action == "summary":
|
| 45 |
-
return self.fetch_summary(
|
| 46 |
elif action == "is_historical_country":
|
| 47 |
-
return self.is_historical_country(
|
| 48 |
else:
|
| 49 |
-
return "Error: Unknown action. Use 'summary' or 'is_historical_country'."
|
|
|
|
| 3 |
|
| 4 |
class WikiTool(Tool):
|
| 5 |
def __init__(self):
|
| 6 |
+
self.name = "WikiTool" # Явно задаем имя
|
| 7 |
+
self.description = (
|
| 8 |
+
"Performs Wikipedia lookups. Supports actions: 'summary' and 'is_historical_country'.\n"
|
| 9 |
+
"Usage:\n"
|
| 10 |
+
"- {'action': 'summary', 'topic': 'France'}\n"
|
| 11 |
+
"- {'action': 'is_historical_country', 'country_name': 'Yugoslavia'}"
|
| 12 |
+
)
|
| 13 |
+
self.inputs = {
|
| 14 |
+
"action": {
|
| 15 |
+
"type": "string",
|
| 16 |
+
"description": "The action to perform: 'summary' or 'is_historical_country'.",
|
| 17 |
+
"nullable": True # Сделать action необязательным
|
| 18 |
+
},
|
| 19 |
+
"topic": {
|
| 20 |
+
"type": "string",
|
| 21 |
+
"description": "The topic to summarize (required for 'summary' action).",
|
| 22 |
+
"nullable": True
|
| 23 |
+
},
|
| 24 |
+
"country_name": {
|
| 25 |
+
"type": "string",
|
| 26 |
+
"description": "The country name to check (required for 'is_historical_country' action).",
|
| 27 |
+
"nullable": True
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
self.output_type = "string"
|
| 31 |
super().__init__(
|
| 32 |
+
name=self.name,
|
| 33 |
+
description=self.description,
|
| 34 |
+
inputs=self.inputs,
|
| 35 |
+
output_type=self.output_type
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
def fetch_summary(self, topic: str) -> str:
|
|
|
|
| 59 |
except Exception:
|
| 60 |
return "Unknown (error during lookup)"
|
| 61 |
|
| 62 |
+
def forward(self, action: str = "", topic: str = "", country_name: str = "") -> str:
|
|
|
|
|
|
|
| 63 |
if action == "summary":
|
| 64 |
+
return self.fetch_summary(topic)
|
| 65 |
elif action == "is_historical_country":
|
| 66 |
+
return self.is_historical_country(country_name)
|
| 67 |
else:
|
| 68 |
+
return "Error: Unknown action. Use 'summary' or 'is_historical_country'."
|