Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

assert.py 1.1 KB

You have to be logged in to leave a comment. Sign In
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  1. def get_assert(output, context):
  2. print("Prompt:", context["prompt"])
  3. print("Vars", context["vars"]["topic"])
  4. # You can return a bool...
  5. # return 'bananas' in output.lower()
  6. # A score (where 0 = Fail)...
  7. # return 0.5
  8. # Or an entire grading result, which can be simple...
  9. result = {
  10. "pass": "bananas" in output.lower(),
  11. "score": 0.5,
  12. "reason": "Contains banana",
  13. }
  14. # Or include nested assertions...
  15. result = {
  16. "pass": True,
  17. "score": 0.75,
  18. "reason": "Looks good to me",
  19. "componentResults": [
  20. {
  21. "pass": "bananas" in output.lower(),
  22. "score": 0.5,
  23. "reason": "Contains banana",
  24. "namedScores": {
  25. "Uses banana": 1.0,
  26. },
  27. },
  28. {
  29. "pass": "yellow" in output.lower(),
  30. "score": 0.5,
  31. "reason": "Contains yellow",
  32. "namedScores": {
  33. "Yellowish": 0.66,
  34. },
  35. },
  36. ],
  37. }
  38. return result
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...