File size: 2,895 Bytes
01d5a5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from typing import List, Optional
from datetime import datetime
from pydantic import BaseModel, Field


class BaseUserLLMConfigDTO(BaseModel):
    """Base User LLM Configuration DTO with separate chat and embedding settings"""
    provider_type: str = 'openai'
    key: Optional[str] = None
    
    # Chat configuration
    chat_endpoint: Optional[str] = None
    chat_api_key: Optional[str] = None
    chat_model_name: Optional[str] = None
    
    # Embedding configuration
    embedding_endpoint: Optional[str] = None
    embedding_api_key: Optional[str] = None
    embedding_model_name: Optional[str] = None
    
    # Thinking configuration
    thinking_model_name: Optional[str] = None
    thinking_endpoint: Optional[str] = None
    thinking_api_key: Optional[str] = None
    
    def dict(self, *args, **kwargs):
        result = super().dict(*args, **kwargs)
        return result


class CreateUserLLMConfigDTO(BaseUserLLMConfigDTO):
    """Create User LLM Configuration DTO"""
    pass


class UpdateUserLLMConfigDTO(BaseModel):
    """Update User LLM Configuration DTO"""
    provider_type: Optional[str] = None
    key: Optional[str] = None
    
    # Chat configuration
    chat_endpoint: Optional[str] = None
    chat_api_key: Optional[str] = None
    chat_model_name: Optional[str] = None
    
    # Embedding configuration
    embedding_endpoint: Optional[str] = None
    embedding_api_key: Optional[str] = None
    embedding_model_name: Optional[str] = None
    
    # Thinking configuration
    thinking_model_name: Optional[str] = None
    thinking_endpoint: Optional[str] = None
    thinking_api_key: Optional[str] = None
    
    def dict(self, *args, **kwargs):
        result = super().dict(*args, **kwargs)
        return result


class UserLLMConfigDTO(BaseUserLLMConfigDTO):
    """User LLM Configuration DTO"""
    id: Optional[int] = None
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None

    @classmethod
    def from_model(cls, model):
        """Create DTO from model"""
        if not model:
            return None
        return cls(
            id=model.id,
            provider_type=model.provider_type,
            key=model.key,
            chat_endpoint=model.chat_endpoint,
            chat_api_key=model.chat_api_key,
            chat_model_name=model.chat_model_name,
            embedding_endpoint=model.embedding_endpoint,
            embedding_api_key=model.embedding_api_key,
            embedding_model_name=model.embedding_model_name,
            thinking_model_name=model.thinking_model_name,
            thinking_endpoint=model.thinking_endpoint,
            thinking_api_key=model.thinking_api_key,
            created_at=model.created_at,
            updated_at=model.updated_at
        )


class UserLLMConfigListDTO(BaseModel):
    """User LLM Configuration List DTO"""
    items: List[UserLLMConfigDTO]