|
| 1 | +from root import RootSignals |
| 2 | + |
| 3 | +client = RootSignals() |
| 4 | + |
| 5 | +# Run a root evaluator by name using the run_by_name method |
| 6 | +result = client.evaluators.run_by_name( |
| 7 | + name="Helpfulness", |
| 8 | + response="You can find the instructions from our Careers page.", |
| 9 | + request="Where can I find the application instructions?", |
| 10 | +) |
| 11 | + |
| 12 | +print(f"Score: {result.score} / 1.0") |
| 13 | +print(f"Justification: {result.justification}") |
| 14 | + |
| 15 | +# Run a custom evaluator by name |
| 16 | +# Assuming you have created a custom evaluator named "Network Troubleshooting" |
| 17 | +try: |
| 18 | + custom_result = client.evaluators.run_by_name( |
| 19 | + name="Network Troubleshooting", |
| 20 | + request="My internet is not working.", |
| 21 | + response=""" |
| 22 | + I'm sorry to hear that your internet isn't working. |
| 23 | + Let's troubleshoot this step by step: |
| 24 | + 1. Check if your router is powered on and all cables are properly connected |
| 25 | + 2. Try restarting your router and modem |
| 26 | + 3. Check if other devices can connect to the network |
| 27 | + 4. Try connecting to a different network if available |
| 28 | + """, |
| 29 | + ) |
| 30 | + |
| 31 | + print(f"Score: {custom_result.score} / 1.0") |
| 32 | + print(f"Justification: {custom_result.justification}") |
| 33 | +except Exception as e: |
| 34 | + print(f"Error: {e}") |
| 35 | + print( |
| 36 | + "Note: This example requires that you have previously created a custom evaluator named 'Network Troubleshooting'" |
| 37 | + ) |
| 38 | + |
| 39 | +result_with_context = client.evaluators.run_by_name( |
| 40 | + name="Context_Precision", |
| 41 | + response="The capital of France is Paris, which is known for the Eiffel Tower.", |
| 42 | + request="What is the capital of France?", |
| 43 | + contexts=["France is a country in Western Europe with a population of about 67 million people."], |
| 44 | + variables={"criteria": "geographical accuracy"}, |
| 45 | +) |
| 46 | + |
| 47 | +print(f"Score: {result_with_context.score} / 1.0") |
| 48 | +print(f"Justification: {result_with_context.justification}") |
0 commit comments