from withpi import PiClient
python_code = """
import json
def score(response_text: str, input_text: str, kwargs: dict) -> dict:
try:
json.loads(response_text)
return { "score": 1.0 }
except ValueError:
return { "score": 0.0 }
"""
pi = PiClient()
scores = pi.scoring_system.score(
llm_input="What are some good day trips from Milan by train?",
llm_output='{ "locations": ["Lake Como", "Bergamo", "Bernina Express", "Turin", "Verona"] }',
scoring_spec=[
{
"question": "Is the response valid JSON?",
"python_code": python_code,
},
]
)
print('Score:', scores.total_score)