-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEvalContext.cs
More file actions
88 lines (79 loc) · 3.16 KB
/
EvalContext.cs
File metadata and controls
88 lines (79 loc) · 3.16 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Collections.Generic;
namespace GameEngine.LLM;
/// <summary>
/// Evaluation context for determining which criteria to include in the prompt.
/// Port of EvalContext from schemas.py and eval_context.py.
/// </summary>
public enum EvalContextType
{
/// <summary>There is at least one unmet goal remaining</summary>
PursuingGoal = 1,
/// <summary>All goals met, available actions to pursue</summary>
ActNow = 2,
/// <summary>All goals met, all available actions taken</summary>
JustResponsiveness = 3
}
/// <summary>
/// Utilities for evaluation context determination and prompt assembly.
/// Port of eval_context.py and eval_prompt.py.
/// </summary>
public static class EvalContextUtil
{
/// <summary>
/// Determine the evaluation context based on unmet goals and available actions.
/// Port of determine_eval_context() from utils/eval_context.py.
/// </summary>
public static EvalContextType DetermineEvalContext(
List<string> unmetGoals,
Dictionary<string, string> availableActions)
{
if (unmetGoals.Count > 0)
return EvalContextType.PursuingGoal;
if (availableActions.Count > 0)
return EvalContextType.ActNow;
return EvalContextType.JustResponsiveness;
}
/// <summary>
/// Build the evaluation context text for the prompt.
/// Port of make_evaluator_context() from utils/eval_prompt.py.
/// </summary>
/// <param name="evalCondition">Current eval context type</param>
/// <param name="parameterSetting">"strict" or "lenient"</param>
/// <param name="vocabList">Advanced concepts vocabulary list</param>
/// <param name="evalBaseText">Contents of EVAL_BASE.txt</param>
/// <param name="criteriaFullText">Contents of CRITERIA_FULL.txt</param>
/// <param name="criteriaRespOnlyText">Contents of CRITERIA_RESP_ONLY.txt</param>
/// <param name="reflectionStrictText">Contents of REFLECTION_STRICT.txt</param>
/// <param name="reflectionLenientText">Contents of REFLECTION_LENIENT.txt</param>
public static string MakeEvaluatorContext(
EvalContextType evalCondition,
string? parameterSetting,
List<string>? vocabList,
string evalBaseText,
string criteriaFullText,
string criteriaRespOnlyText,
string reflectionStrictText,
string reflectionLenientText)
{
var criteriaBlock = evalCondition == EvalContextType.JustResponsiveness
? criteriaRespOnlyText
: criteriaFullText;
var vocabStr = vocabList != null ? string.Join(", ", vocabList) : "";
string reflectionBlock;
switch (parameterSetting)
{
case "strict":
reflectionBlock = reflectionStrictText.Replace("{vocab_list}", vocabStr);
break;
case "lenient":
reflectionBlock = reflectionLenientText.Replace("{vocab_list}", vocabStr);
break;
default:
reflectionBlock = "";
break;
}
return evalBaseText
.Replace("{criteria_block}", criteriaBlock)
.Replace("{reflection_block}", reflectionBlock);
}
}