params -> fn

This commit is contained in:
Xi Yan 2025-03-12 00:20:41 -07:00
parent bb86aaf787
commit 124040af77
3 changed files with 16 additions and 54 deletions

View file

@ -9602,29 +9602,9 @@
"RegisterScoringFunctionRequest": { "RegisterScoringFunctionRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
"scoring_fn_type": { "fn": {
"type": "string",
"enum": [
"custom_llm_as_judge",
"regex_parser",
"regex_parser_math_response",
"equality",
"subset_of",
"factuality",
"faithfulness",
"answer_correctness",
"answer_relevancy",
"answer_similarity",
"context_entity_recall",
"context_precision",
"context_recall",
"context_relevancy"
],
"description": "The type of scoring function to register."
},
"params": {
"$ref": "#/components/schemas/ScoringFnParams", "$ref": "#/components/schemas/ScoringFnParams",
"description": "The parameters for the scoring function." "description": "The type and parameters for the scoring function."
}, },
"scoring_fn_id": { "scoring_fn_id": {
"type": "string", "type": "string",
@ -9659,8 +9639,7 @@
}, },
"additionalProperties": false, "additionalProperties": false,
"required": [ "required": [
"scoring_fn_type", "fn"
"params"
], ],
"title": "RegisterScoringFunctionRequest" "title": "RegisterScoringFunctionRequest"
}, },

View file

@ -6534,28 +6534,10 @@ components:
RegisterScoringFunctionRequest: RegisterScoringFunctionRequest:
type: object type: object
properties: properties:
scoring_fn_type: fn:
type: string
enum:
- custom_llm_as_judge
- regex_parser
- regex_parser_math_response
- equality
- subset_of
- factuality
- faithfulness
- answer_correctness
- answer_relevancy
- answer_similarity
- context_entity_recall
- context_precision
- context_recall
- context_relevancy
description: >-
The type of scoring function to register.
params:
$ref: '#/components/schemas/ScoringFnParams' $ref: '#/components/schemas/ScoringFnParams'
description: The parameters for the scoring function. description: >-
The type and parameters for the scoring function.
scoring_fn_id: scoring_fn_id:
type: string type: string
description: >- description: >-
@ -6576,8 +6558,7 @@ components:
- E.g. {"description": "This scoring function is used for ..."} - E.g. {"description": "This scoring function is used for ..."}
additionalProperties: false additionalProperties: false
required: required:
- scoring_fn_type - fn
- params
title: RegisterScoringFunctionRequest title: RegisterScoringFunctionRequest
RegisterShieldRequest: RegisterShieldRequest:
type: object type: object

View file

@ -12,8 +12,8 @@ from typing import (
Literal, Literal,
Optional, Optional,
Protocol, Protocol,
Union,
runtime_checkable, runtime_checkable,
Union,
) )
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -218,7 +218,9 @@ class CommonScoringFnFields(BaseModel):
@json_schema_type @json_schema_type
class ScoringFn(CommonScoringFnFields, Resource): class ScoringFn(CommonScoringFnFields, Resource):
type: Literal[ResourceType.scoring_function.value] = ResourceType.scoring_function.value type: Literal[ResourceType.scoring_function.value] = (
ResourceType.scoring_function.value
)
@property @property
def scoring_fn_id(self) -> str: def scoring_fn_id(self) -> str:
@ -245,13 +247,14 @@ class ScoringFunctions(Protocol):
async def list_scoring_functions(self) -> ListScoringFunctionsResponse: ... async def list_scoring_functions(self) -> ListScoringFunctionsResponse: ...
@webmethod(route="/scoring-functions/{scoring_fn_id:path}", method="GET") @webmethod(route="/scoring-functions/{scoring_fn_id:path}", method="GET")
async def get_scoring_function(self, scoring_fn_id: str, /) -> Optional[ScoringFn]: ... async def get_scoring_function(
self, scoring_fn_id: str, /
) -> Optional[ScoringFn]: ...
@webmethod(route="/scoring-functions", method="POST") @webmethod(route="/scoring-functions", method="POST")
async def register_scoring_function( async def register_scoring_function(
self, self,
scoring_fn_type: ScoringFunctionType, fn: ScoringFnParams,
params: ScoringFnParams = None,
scoring_fn_id: Optional[str] = None, scoring_fn_id: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None, metadata: Optional[Dict[str, Any]] = None,
) -> ScoringFn: ) -> ScoringFn:
@ -259,8 +262,7 @@ class ScoringFunctions(Protocol):
Register a new scoring function with given parameters. Register a new scoring function with given parameters.
Only valid scoring function type that can be parameterized can be registered. Only valid scoring function type that can be parameterized can be registered.
:param scoring_fn_type: The type of scoring function to register. :param fn: The type and parameters for the scoring function.
:param params: The parameters for the scoring function.
:param scoring_fn_id: (Optional) The ID of the scoring function to register. If not provided, a random ID will be generated. :param scoring_fn_id: (Optional) The ID of the scoring function to register. If not provided, a random ID will be generated.
:param metadata: (Optional) Any additional metadata to be associated with the scoring function. :param metadata: (Optional) Any additional metadata to be associated with the scoring function.
- E.g. {"description": "This scoring function is used for ..."} - E.g. {"description": "This scoring function is used for ..."}