Skip to content

Commit 0faaff8

Browse files
committed
feat(models): add base configuration classes for local model providers
1 parent 8947d56 commit 0faaff8

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Base configuration classes for local model providers.
4+
5+
This module defines the base classes and enums for local model provider
6+
configurations like Ollama.
7+
"""
8+
9+
from abc import ABC, abstractmethod
10+
from enum import Enum
11+
from typing import Any, Dict, List, Optional, Type
12+
13+
from pydantic import BaseModel
14+
15+
16+
class ProviderType(str, Enum):
17+
"""Enum for supported local model providers.
18+
19+
Attributes:
20+
OLLAMA: Ollama local inference server.
21+
"""
22+
23+
OLLAMA = "ollama"
24+
25+
26+
class BaseProviderConfig(ABC):
27+
"""Abstract base class for local model provider configurations.
28+
29+
This class defines the interface for provider-specific configurations,
30+
including parameter mapping, environment validation, and URL handling.
31+
32+
Example:
33+
>>> class MyProviderConfig(BaseProviderConfig):
34+
... @property
35+
... def provider_type(self) -> ProviderType:
36+
... return ProviderType.OLLAMA
37+
... # Implement other abstract methods...
38+
"""
39+
40+
@property
41+
@abstractmethod
42+
def provider_type(self) -> ProviderType:
43+
"""Return the provider type.
44+
45+
Returns:
46+
The ProviderType enum value for this provider.
47+
"""
48+
pass
49+
50+
@abstractmethod
51+
def get_supported_openai_params(self, model: str) -> List[str]:
52+
"""Get list of supported OpenAI standard parameters.
53+
54+
Args:
55+
model: The model name.
56+
57+
Returns:
58+
List of supported parameter names.
59+
"""
60+
pass
61+
62+
@abstractmethod
63+
def map_openai_params(
64+
self,
65+
openai_params: Dict[str, Any],
66+
model: str,
67+
drop_unsupported: bool = True,
68+
) -> Dict[str, Any]:
69+
"""Map OpenAI parameters to provider-specific format.
70+
71+
Args:
72+
openai_params: Dictionary of OpenAI format parameters.
73+
model: The model name being used.
74+
drop_unsupported: If True, drop unsupported parameters.
75+
76+
Returns:
77+
Dictionary of provider-compatible parameters.
78+
"""
79+
pass
80+
81+
@abstractmethod
82+
def get_structured_output_config(
83+
self,
84+
structured_model: Optional[Type[BaseModel]] = None,
85+
) -> Dict[str, Any]:
86+
"""Get configuration for structured output generation.
87+
88+
Args:
89+
structured_model: Optional Pydantic model defining the output schema.
90+
91+
Returns:
92+
Dictionary containing structured output configuration.
93+
"""
94+
pass
95+
96+
@abstractmethod
97+
def validate_environment(
98+
self,
99+
api_key: Optional[str] = None,
100+
api_base: Optional[str] = None,
101+
**kwargs: Any,
102+
) -> Dict[str, Any]:
103+
"""Validate environment for API calls.
104+
105+
Args:
106+
api_key: Optional API key.
107+
api_base: Optional base URL.
108+
**kwargs: Additional arguments.
109+
110+
Returns:
111+
Dictionary containing validated configuration.
112+
"""
113+
pass
114+
115+
@abstractmethod
116+
def get_default_api_base(self) -> Optional[str]:
117+
"""Get the default API base URL.
118+
119+
Returns:
120+
Default API base URL or None.
121+
"""
122+
pass
123+
124+
@abstractmethod
125+
def get_complete_url(
126+
self,
127+
api_base: Optional[str] = None,
128+
endpoint: Optional[str] = None,
129+
) -> str:
130+
"""Get the complete URL for API calls.
131+
132+
Args:
133+
api_base: Optional base URL.
134+
endpoint: Optional endpoint path.
135+
136+
Returns:
137+
Complete URL for the API call.
138+
"""
139+
pass
140+
141+
@abstractmethod
142+
def get_headers(
143+
self,
144+
api_key: Optional[str] = None,
145+
extra_headers: Optional[Dict[str, str]] = None,
146+
) -> Dict[str, str]:
147+
"""Get HTTP headers for API calls.
148+
149+
Args:
150+
api_key: Optional API key for authentication.
151+
extra_headers: Optional additional headers.
152+
153+
Returns:
154+
Dictionary of HTTP headers.
155+
"""
156+
pass
157+

0 commit comments

Comments
 (0)