-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_factory.py
More file actions
53 lines (48 loc) · 2.18 KB
/
api_factory.py
File metadata and controls
53 lines (48 loc) · 2.18 KB
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
# Copyright (C) 2025 Jakub Budrewicz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from ollama_handler import OllamaHandler
from openai_handler import OpenAIHandler
from anthropic_handler import AnthropicHandler
from grok_handler import GrokHandler
from gemini_handler import GeminiHandler
class APIFactory:
"""Factory class for creating API handlers."""
@staticmethod
def create_handler(api_type, logger, **kwargs):
"""Create an API handler of the specified type.
Args:
api_type: The type of API handler to create ('ollama', 'openai', 'anthropic', 'grok', 'gemini')
logger: The logger instance
**kwargs: Additional arguments to pass to the handler constructor
Returns:
An instance of the specified API handler
"""
if api_type.lower() == 'ollama':
address = kwargs.get('address', 'http://localhost:11434')
return OllamaHandler(logger, address)
elif api_type.lower() == 'openai':
api_key = kwargs.get('api_key', None)
return OpenAIHandler(logger, api_key)
elif api_type.lower() == 'anthropic':
api_key = kwargs.get('api_key', None)
return AnthropicHandler(logger, api_key)
elif api_type.lower() == 'grok':
api_key = kwargs.get('api_key', None)
return GrokHandler(logger, api_key)
elif api_type.lower() == 'gemini':
api_key = kwargs.get('api_key', None)
return GeminiHandler(logger, api_key)
else:
raise ValueError(f"Unknown API type: {api_type}")