Skip to content

Commit f5a1958

Browse files
awkoyYaroslav Boiko
andauthored
[OPIK-1779] enable python metrics for threads (#2741)
* [OPIK-1779] enable python metrics for threads * [OPIK-1779] update python thread prompt * [OPIK-1779] add comment to python thread metric --------- Co-authored-by: Yaroslav Boiko <yaroslavboiko@ip-192-168-1-15.ec2.internal>
1 parent cf51396 commit f5a1958

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

apps/opik-frontend/src/components/pages-shared/automations/AddEditRuleDialog/AddEditRuleDialog.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,20 @@ const AddEditRuleDialog: React.FC<AddEditRuleDialogProps> = ({
183183
const handleScopeChange = useCallback(
184184
(value: EVALUATORS_RULE_SCOPE) => {
185185
const applyChange = () => {
186-
if (value === EVALUATORS_RULE_SCOPE.thread) {
187-
form.setValue("uiType", UI_EVALUATORS_RULE_TYPE.llm_judge);
188-
}
189-
190186
const { uiType } = form.getValues();
191187
const type = getBackendRuleType(value, uiType);
192188

193189
form.setValue("scope", value);
194190
form.setValue("type", type);
195191

196-
form.resetField("llmJudgeDetails", {
197-
defaultValue: cloneDeep(DEFAULT_LLM_AS_JUDGE_DATA[value]),
198-
keepDirty: false,
199-
});
200-
form.resetField("pythonCodeDetails", {
201-
defaultValue: cloneDeep(DEFAULT_PYTHON_CODE_DATA[value]),
202-
keepDirty: false,
203-
});
192+
form.setValue(
193+
"llmJudgeDetails",
194+
cloneDeep(DEFAULT_LLM_AS_JUDGE_DATA[value]),
195+
);
196+
form.setValue(
197+
"pythonCodeDetails",
198+
cloneDeep(DEFAULT_PYTHON_CODE_DATA[value]),
199+
);
204200
};
205201

206202
if (
@@ -464,7 +460,7 @@ const AddEditRuleDialog: React.FC<AddEditRuleDialogProps> = ({
464460
)}
465461
/>
466462

467-
{!isEdit && !isThreadScope && (
463+
{!isEdit && (
468464
<FormField
469465
control={form.control}
470466
name="uiType"

apps/opik-frontend/src/constants/llm.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,23 @@ export const DEFAULT_PYTHON_CODE_THREAD_DATA: PythonCodeDetailsThreadForm = {
585585
metric:
586586
"from typing import Union, List, Any\n" +
587587
"from opik.evaluation.metrics import base_metric, score_result\n" +
588-
"from opik.evaluation.types import Conversation\n" +
588+
"from opik.evaluation.metrics.conversation import conversation_thread_metric, types\n" +
589589
"\n" +
590-
"class MyCustomMetric(base_metric.BaseMetric):\n" +
590+
"class MyCustomMetric(conversation_thread_metric.ConversationThreadMetric):\n" +
591591
' """A custom metric for evaluating conversation threads."""\n' +
592+
" def __init__(\n" +
593+
" self,\n" +
594+
' name: str = "my_custom_thread_metric",\n' +
595+
" ):\n" +
596+
" super().__init__(\n" +
597+
" name=name,\n" +
598+
" )\n" +
592599
"\n" +
593600
" def score(\n" +
594-
" self, conversation: Conversation, **kwargs: Any\n" +
601+
" self, conversation: types.Conversation, **kwargs: Any\n" +
595602
" ) -> Union[score_result.ScoreResult, List[score_result.ScoreResult]]:\n" +
603+
" # conversation is a List[Dict] where each dict has:\n" +
604+
' # {"role": "user" | "assistant", "content": "message text"}\n' +
596605
" # Add you logic here\n" +
597606
"\n" +
598607
" return score_result.ScoreResult(\n" +

0 commit comments

Comments
 (0)