-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add AI Config judge support #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v7
Are you sure you want to change the base?
Changes from all commits
a5dcb5e
93397a7
6481937
ab416ba
bd3fe09
e9195f0
f8e8ed2
41141b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,7 +102,11 @@ func (c *Client) Config( | |
| builder := NewConfig(). | ||
| WithModelName(parsed.Model.Name). | ||
| WithProviderName(parsed.Provider.Name). | ||
| WithEnabled(parsed.Meta.Enabled) | ||
| WithEnabled(parsed.Meta.Enabled). | ||
| WithMode(parsed.Mode). | ||
| WithEvaluationMetricKey(parsed.EvaluationMetricKey). | ||
| WithEvaluationMetricKeys(parsed.EvaluationMetricKeys). | ||
| WithJudgeConfiguration(parsed.JudgeConfiguration) | ||
|
|
||
| for k, v := range parsed.Model.Parameters { | ||
| builder.WithModelParam(k, v) | ||
|
|
@@ -174,3 +178,38 @@ func interpolateTemplate(template string, variables map[string]interface{}) (str | |
| } | ||
| return m.RenderString(variables) | ||
| } | ||
|
|
||
| // JudgeConfig evaluates an AI Config, tracking it as a judge function. See Config for details. | ||
| // | ||
| // This method extends the provided variables with reserved judge variables: | ||
| // - "message_history": "{{message_history}}" | ||
| // - "response_to_evaluate": "{{response_to_evaluate}}" | ||
| // | ||
| // These literal placeholder strings preserve the Mustache templates through the first interpolation | ||
| // (during config fetch), allowing Judge.Evaluate() to perform a second interpolation with actual values. | ||
| func (c *Client) JudgeConfig( | ||
| key string, | ||
| context ldcontext.Context, | ||
| defaultValue Config, | ||
| variables map[string]interface{}, | ||
| ) (Config, *Tracker) { | ||
| _ = c.sdk.TrackMetric("$ld:ai:judge:function:single", context, 1, ldvalue.String(key)) | ||
|
|
||
| // Extend variables with reserved judge placeholders | ||
| extendedVariables := make(map[string]interface{}) | ||
| for k, v := range variables { | ||
| // Warn if user tries to override reserved variables | ||
| if k == "message_history" || k == "response_to_evaluate" { | ||
| c.logger.Warnf("AI Config '%s': variable '%s' is reserved by judge and will be ignored", key, k) | ||
| continue | ||
| } | ||
| extendedVariables[k] = v | ||
| } | ||
|
|
||
| // Inject reserved variables as literal placeholder strings | ||
| // These will be preserved through the first interpolation and resolved during Judge.Evaluate() | ||
| extendedVariables["message_history"] = "{{message_history}}" | ||
| extendedVariables["response_to_evaluate"] = "{{response_to_evaluate}}" | ||
|
|
||
| return c.Config(key, context, defaultValue, extendedVariables) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||


Uh oh!
There was an error while loading. Please reload this page.