first commit
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
from .factory import LLMFactory
|
||||
from .base import BaseLLMClient
|
||||
from .dashscope import DashScopeClient
|
||||
from .openai import OpenAIClient
|
||||
from .anthropic import AnthropicClient
|
||||
|
||||
|
||||
__all__ = [
|
||||
"LLMFactory",
|
||||
"BaseLLMClient",
|
||||
"DashScopeClient",
|
||||
"OpenAIClient",
|
||||
"AnthropicClient",
|
||||
]
|
||||
@@ -0,0 +1,9 @@
|
||||
from .base import BaseLLMClient
|
||||
|
||||
|
||||
class AnthropicClient(BaseLLMClient):
|
||||
def chat(self, messages, **kwargs):
|
||||
pass
|
||||
|
||||
def stream_chat(self, messages, **kwargs):
|
||||
pass
|
||||
@@ -0,0 +1,14 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class BaseLLMClient(ABC):
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
@abstractmethod
|
||||
def chat(self, messages, **kwargs):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def stream_chat(self, messages, **kwargs):
|
||||
pass
|
||||
@@ -0,0 +1,9 @@
|
||||
from .base import BaseLLMClient
|
||||
|
||||
|
||||
class DashScopeClient(BaseLLMClient):
|
||||
def chat(self, messages, **kwargs):
|
||||
pass
|
||||
|
||||
def stream_chat(self, messages, **kwargs):
|
||||
pass
|
||||
@@ -0,0 +1,22 @@
|
||||
from .dashscope import DashScopeClient
|
||||
from .openai import OpenAIClient
|
||||
from .anthropic import AnthropicClient
|
||||
|
||||
|
||||
class LLMFactory:
|
||||
_clients = {
|
||||
"dashscope": DashScopeClient,
|
||||
"openai": OpenAIClient,
|
||||
"anthropic": AnthropicClient,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def create_client(cls, provider, config):
|
||||
client_class = cls._clients.get(provider)
|
||||
if not client_class:
|
||||
raise ValueError(f"不支持的 LLM 提供商: {provider}")
|
||||
return client_class(config)
|
||||
|
||||
@classmethod
|
||||
def register_client(cls, provider, client_class):
|
||||
cls._clients[provider] = client_class
|
||||
@@ -0,0 +1,9 @@
|
||||
from .base import BaseLLMClient
|
||||
|
||||
|
||||
class OpenAIClient(BaseLLMClient):
|
||||
def chat(self, messages, **kwargs):
|
||||
pass
|
||||
|
||||
def stream_chat(self, messages, **kwargs):
|
||||
pass
|
||||
Reference in New Issue
Block a user