Elffuss BraidHub

kikocis/llama-stack public

main · 1.6 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 enum import Enum
8
9from typing import Any, Dict, List, Optional, Protocol
10
11from llama_models.schema_utils import json_schema_type, webmethod
12
13from pydantic import BaseModel
14
15from llama_models.llama3.api.datatypes import * # noqa: F403
16from llama_stack.apis.reward_scoring import * # noqa: F403
17
18
19class FilteringFunction(Enum):
20 """The type of filtering function."""
21
22 none = "none"
23 random = "random"
24 top_k = "top_k"
25 top_p = "top_p"
26 top_k_top_p = "top_k_top_p"
27 sigmoid = "sigmoid"
28
29
30@json_schema_type
31class SyntheticDataGenerationRequest(BaseModel):
32 """Request to generate synthetic data. A small batch of prompts and a filtering function"""
33
34 dialogs: List[Message]
35 filtering_function: FilteringFunction = FilteringFunction.none
36 model: Optional[str] = None
37
38
39@json_schema_type
40class SyntheticDataGenerationResponse(BaseModel):
41 """Response from the synthetic data generation. Batch of (prompt, response, score) tuples that pass the threshold."""
42
43 synthetic_data: List[ScoredDialogGenerations]
44 statistics: Optional[Dict[str, Any]] = None
45
46
47class SyntheticDataGeneration(Protocol):
48 @webmethod(route="/synthetic_data_generation/generate")
49 def synthetic_data_generate(
50 self,
51 dialogs: List[Message],
52 filtering_function: FilteringFunction = FilteringFunction.none,
53 model: Optional[str] = None,
54 ) -> Union[SyntheticDataGenerationResponse]: ...