Class ReinforcementTuningCodeExecutionRewardScorer

java.lang.Object
com.google.genai.JsonSerializable
com.google.genai.types.ReinforcementTuningCodeExecutionRewardScorer

public abstract class ReinforcementTuningCodeExecutionRewardScorer extends JsonSerializable
ReinforcementTuningCodeExecutionRewardScorer allows users to implement a function to evaluate rewards for the sample response. The function signature is as follows: ``` def evaluate(example: dict[str, Any], response: dict[str, Any]) -> float: ... ``` `example` is a ReinforcementTuningExample in ProtoJSON format, (i.e., the format is the same as as one line in the training/validation dataset except that the keys must be in camel case). System instructions (i.e., `example.get("systemInstruction")`) and references (i.e., `example.get("references")`) are also included in the `example` provided that they are set in the training/validation dataset. `response` is a Content in ProtoJSON format (i.e., keys must be in camel case), which is the same as the Online Prediction response for Gemini models. Note: Reward output by the `evaluate` function is clipped to be within `[-1, 1]`, i.e., `reward = max(min(reward, 1.0), -1.0)`. This data type is not supported in Gemini API.
  • Constructor Details

    • ReinforcementTuningCodeExecutionRewardScorer

      public ReinforcementTuningCodeExecutionRewardScorer()
  • Method Details

    • pythonCodeSnippet

      public abstract Optional<String> pythonCodeSnippet()
      The python code snippet as a string for evaluating rewards. The following is an example python code snippet that returns a reward `1.0` for a parsed response matching the user-provided reference answer in per prompt references map. ``` def evaluate(example, response) -> float: response_str = response.get("parts", [])0 references = example.get("references", {}) if response_str == references.get("concise_answer"): return 1.0 return -1.0 ``` Note: Reward output by the evaluate function is clipped to be within `[-1, 1]`, i.e., `reward = max(min(reward, 1.0), -1.0)`.
    • builder

      Instantiates a builder for ReinforcementTuningCodeExecutionRewardScorer.
    • toBuilder

      Creates a builder with the same values as this instance.
    • fromJson

      public static ReinforcementTuningCodeExecutionRewardScorer fromJson(String jsonString)
      Deserializes a JSON string to a ReinforcementTuningCodeExecutionRewardScorer object.