-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscorer.py
More file actions
27 lines (22 loc) · 922 Bytes
/
scorer.py
File metadata and controls
27 lines (22 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import json
from typing import List, Dict, Type, Any
def scorer_fn(*, node_input: str, node_output: str, **kwargs) -> int:
"""
Define a scorer function on a single node.
This function checks the planner_output key in the JSON output.
If planner_output is "unknown", returns 0. Otherwise returns 1.
Available args: node_input, node_output, node_name, tools, credentials
"""
try:
# Parse the node_output as JSON
output_data = json.loads(node_output)
# Check the planner_output key
planner_output = output_data.get("planner_output", "")
# Return 0 if unknown, 1 otherwise
if planner_output == "unknown":
return 0
else:
return 1
except (json.JSONDecodeError, KeyError, TypeError):
# If there's any error parsing the JSON or accessing the key, return 0
return 0