Skip to content

Commit

Permalink
Support "Prompts" property in LLMEvaluator association specs
Browse files Browse the repository at this point in the history
  • Loading branch information
rhennigan committed Nov 1, 2023
1 parent a410fc0 commit 37e9711
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Source/Chatbook/ChatMessages.wl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ constructMessages[ settings_Association? AssociationQ, messages0: { __Associatio
messagePrint[ "InvalidMessages", getProcessingFunction[ settings, "ChatMessages" ], processed ];
processed = messages
];
processed //= DeleteCases @ KeyValuePattern[ "Content" -> "" ];
Sow[ <| "Messages" -> processed |>, $chatDataTag ];

$lastSettings = settings;
Expand Down Expand Up @@ -340,11 +341,14 @@ getPrePrompt[ as_Association ] := toPromptString @ FirstCase[
as[ "LLMEvaluator", "ChatContextPreprompt" ],
as[ "LLMEvaluator", "Pre" ],
as[ "LLMEvaluator", "PromptTemplate" ],
as[ "LLMEvaluator", "Prompts" ],
as[ "ChatContextPreprompt" ],
as[ "Pre" ],
as[ "PromptTemplate" ]
},
expr_ :> With[ { e = expr }, e /; MatchQ[ e, _String | _TemplateObject ] ]
expr_ :> With[ { e = expr },
e /; MatchQ[ e, _String | _TemplateObject | { (_String|_TemplateObject) ... } ]
]
];

getPrePrompt // endDefinition;
Expand Down Expand Up @@ -412,6 +416,12 @@ toPromptString // beginDefinition;
toPromptString[ string_String ] := string;
toPromptString[ template_TemplateObject ] := With[ { string = TemplateApply @ template }, string /; StringQ @ string ];
toPromptString[ _Missing | Automatic | Inherited | None ] := Missing[ ];

toPromptString[ prompts_List ] :=
With[ { strings = DeleteMissing[ toPromptString /@ prompts ] },
StringRiffle[ prompts, "\n\n" ] /; MatchQ[ strings, { ___String } ]
];

toPromptString // endDefinition;

(* ::**************************************************************************************************************:: *)
Expand Down

0 comments on commit 37e9711

Please sign in to comment.