mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-14 20:17:42 +00:00
More token efficient jetbrains overview tool
The grouping by type and the removing of the per-symbol-repeated name_path leads to a huge reduction in output size while the same information is retained!
From
{"symbols": [{"name_path": "collections", "type": "Py:IMPORT_ELEMENT"}, ...
To
{"symbols": {"Py:IMPORT_ELEMENT": ["collections", ...
This commit is contained in:
1 parent
5b730baf07
commit
73f24011f2
1 file changed
+13
-1
@@ -1,3 +1,5 @@
|
||||
from collections import defaultdict
|
||||
|
||||
from serena.tools import Tool, ToolMarkerOptional, ToolMarkerSymbolicRead
|
||||
from serena.tools.jetbrains_plugin_client import JetBrainsPluginClient
|
||||
|
||||
@@ -117,5 +119,15 @@ class JetBrainsGetSymbolsOverviewTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOp
|
||||
response_dict = client.get_symbols_overview(
|
||||
relative_path=relative_path,
|
||||
)
|
||||
result = self._to_json(response_dict)
|
||||
symbols = response_dict["symbols"]
|
||||
# symbols come with name_path and type, we group them by type for token efficiency
|
||||
grouped_symbols = defaultdict(list)
|
||||
for symbol in symbols:
|
||||
type = symbol.pop("type", "unknown")
|
||||
if len(symbol) == 1:
|
||||
# we only have the name_path key, no need to repeat it in each entry
|
||||
symbol = symbol["name_path"]
|
||||
grouped_symbols[type].append(symbol)
|
||||
response_dict["symbols"] = grouped_symbols
|
||||
result = self._to_json(response_dict)
|
||||
return self._limit_length(result, max_answer_chars)
|
||||
Reference in new issue
Block a user