File size: 898 Bytes
5e028bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from pydantic import BaseModel, Field, model_validator
from typing import Dict, Optional, Type, Any, List, ClassVar

class TopicSegmenterConfig(BaseModel):
    model_name: str = Field(description="The TopicSegmenter model or Deployment platform (e.g., 'identity', 'llmlingua-2')", default="llmlingua-2")

    _model_list: ClassVar[List[str]] = [
        "identity",
        "llmlingua-2"
    ]

    configs: Optional[dict] = Field(description="Configuration for the specific TopicSegmenter model", default={})

    @model_validator(mode='before')
    def validate_model_name(cls, values):
        default_model = cls.__pydantic_fields__["model_name"].default
        model_name = values.get("model_name", default_model)

        if model_name not in cls._model_list:
            raise ValueError(f"Unsupported model: {model_name}.")

        values["model_name"] = model_name
        return values