Elffuss BraidHub

kikocis/llama-stack public

efac2a2f572e · 1.4 KiBRawPermalink
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2# All rights reserved.
3#
4# This source code is licensed under the terms described in the LICENSE file in
5# the root directory of this source tree.
6
7from typing import List, Protocol, Union
8
9from llama_models.schema_utils import json_schema_type, webmethod
10
11from pydantic import BaseModel
12
13from llama_models.llama3.api.datatypes import * # noqa: F403
14
15
16@json_schema_type
17class ScoredMessage(BaseModel):
18 message: Message
19 score: float
20
21
22@json_schema_type
23class DialogGenerations(BaseModel):
24 dialog: List[Message]
25 sampled_generations: List[Message]
26
27
28@json_schema_type
29class ScoredDialogGenerations(BaseModel):
30 dialog: List[Message]
31 scored_generations: List[ScoredMessage]
32
33
34@json_schema_type
35class RewardScoringRequest(BaseModel):
36 """Request to score a reward function. A list of prompts and a list of responses per prompt."""
37
38 dialog_generations: List[DialogGenerations]
39 model: str
40
41
42@json_schema_type
43class RewardScoringResponse(BaseModel):
44 """Response from the reward scoring. Batch of (prompt, response, score) tuples that pass the threshold."""
45
46 scored_generations: List[ScoredDialogGenerations]
47
48
49class RewardScoring(Protocol):
50 @webmethod(route="/reward_scoring/score")
51 def reward_score(
52 self,
53 dialog_generations: List[DialogGenerations],
54 model: str,
55 ) -> Union[RewardScoringResponse]: ...