Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions openjiuwen/core/foundation/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
from openjiuwen.core.foundation.llm.output_parsers.output_parser import BaseOutputParser

# Configuration
from openjiuwen.core.foundation.llm.schema.config import ModelRequestConfig, ModelClientConfig, ProviderType
from openjiuwen.core.foundation.llm.schema.config import (
LLMApiMode,
LLMAuthMode,
LLMExtensionsConfig,
KVCacheExtensionConfig,
ModelRequestConfig,
ModelClientConfig,
ProviderType,
)
from openjiuwen.core.foundation.llm.schema.mode_info import BaseModelInfo, ModelConfig
# Messages
from openjiuwen.core.foundation.llm.schema.message import (
Expand All @@ -26,8 +34,8 @@
from openjiuwen.core.foundation.llm.schema.tool_call import ToolCall

# Built-in implementations
from openjiuwen.core.foundation.llm.model_clients.anthropic_model_client import AnthropicModelClient
from openjiuwen.core.foundation.llm.model_clients.openai_model_client import OpenAIModelClient
from openjiuwen.core.foundation.llm.model_clients.ascend_affinity_model_client import AscendAffinityModelClient
from openjiuwen.core.foundation.llm.output_parsers.json_output_parser import JsonOutputParser
from openjiuwen.core.foundation.llm.output_parsers.markdown_output_parser import MarkdownOutputParser

Expand All @@ -47,6 +55,10 @@
"ModelRequestConfig",
"ModelClientConfig",
"ProviderType",
"LLMApiMode",
"LLMAuthMode",
"LLMExtensionsConfig",
"KVCacheExtensionConfig",
"BaseModelInfo",
"ModelConfig"
]
Expand All @@ -73,8 +85,8 @@

# Built-in ModelClient implementations
_PREBUILT_MODEL_CLIENTS = [
"AnthropicModelClient",
"OpenAIModelClient",
"AscendAffinityModelClient",
]

# Built-in OutputParser implementations
Expand Down
10 changes: 5 additions & 5 deletions openjiuwen/core/foundation/llm/inference_affinity_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from openjiuwen.core.foundation.tool import ToolInfo
from openjiuwen.core.foundation.llm.schema.config import ModelRequestConfig, ModelClientConfig
from openjiuwen.core.foundation.llm.output_parsers.output_parser import BaseOutputParser
from openjiuwen.core.foundation.llm.model_clients.inference_affinity_model_client import InferenceAffinityModelClient
from openjiuwen.core.foundation.llm.model_clients import create_model_client


class InferenceAffinityModel:
"""InferenceAffinity (vLLM) model unified invocation entry point

Responsibilities:
1. Manage InferenceAffinityModelClient instances
1. Manage OpenAI-compatible clients configured for KV cache release
2. Provide unified asynchronous interfaces (ainvoke, astream)
3. Support release functionality

Expand All @@ -38,10 +38,10 @@ def __init__(
"""
self.model_config = model_config
self.model_client_config = model_client_config
self._client: Optional[InferenceAffinityModelClient] = None
self._client = None

if model_client_config is not None:
self._client = InferenceAffinityModelClient(model_config, model_client_config)
self._client = create_model_client(model_client_config, model_config)
else:
raise build_error(StatusCode.MODEL_SERVICE_CONFIG_ERROR,
error_msg="model client config is none")
Expand Down Expand Up @@ -187,4 +187,4 @@ def build_kv_cache_invoke_kwargs(
extra["session_id"] = session.get_session_id()
if enable_kv_cache_release:
extra["enable_cache_sharing"] = True
return extra
return extra
15 changes: 6 additions & 9 deletions openjiuwen/core/foundation/llm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
VideoGenerationResponse
)
from openjiuwen.core.foundation.llm.model_clients.base_model_client import BaseModelClient
from openjiuwen.core.foundation.llm.model_clients.inference_affinity_model_client import InferenceAffinityModelClient
from openjiuwen.core.runner.callback import trigger


Expand Down Expand Up @@ -303,15 +302,13 @@ def build_kv_cache_invoke_kwargs(
- session_id: use session.get_session_id() if provided
- enable_cache_sharing: follow enable_kv_cache_release
"""
if not isinstance(self._client, InferenceAffinityModelClient):
build_fn = getattr(self._client, "build_kv_cache_invoke_kwargs", None)
if not callable(build_fn):
return {}

extra: dict = {}
if session is not None and hasattr(session, "get_session_id"):
extra["session_id"] = session.get_session_id()
if enable_kv_cache_release:
extra["enable_cache_sharing"] = True
return extra
return build_fn(
session=session,
enable_kv_cache_release=enable_kv_cache_release,
)

def build_kv_cache_affinity_invoke_kwargs(
self,
Expand Down
57 changes: 26 additions & 31 deletions openjiuwen/core/foundation/llm/model_clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,28 @@
from openjiuwen.core.common.exception.codes import StatusCode
from openjiuwen.core.common.exception.errors import build_error
from openjiuwen.core.foundation.llm.model_clients.base_model_client import BaseModelClient
from openjiuwen.core.foundation.llm.schema.config import ModelRequestConfig, ModelClientConfig, ProviderType
from openjiuwen.core.foundation.llm.schema.config import (
LLMAuthMode,
ModelRequestConfig,
ModelClientConfig,
ProviderType,
)
from openjiuwen.core.foundation.llm.utils.endpoint_profiles import normalize_model_client_config


def _value(value):
return value.value if hasattr(value, "value") else value


def _implementation_provider(client_config: ModelClientConfig) -> str:
provider = _value(client_config.client_provider)
if provider != ProviderType.OpenAI.value:
return provider

auth_mode = _value(getattr(client_config, "auth_mode", LLMAuthMode.ApiKey.value))
if auth_mode == LLMAuthMode.OpenAIAccountOAuth.value:
return ProviderType.OpenAIAccount.value
return ProviderType.OpenAI.value


def _builtin_model_client(provider, client_config: ModelClientConfig, model_config: ModelRequestConfig):
Expand All @@ -18,39 +39,10 @@ def _builtin_model_client(provider, client_config: ModelClientConfig, model_conf
from openjiuwen.core.foundation.llm.model_clients.openai_account_model_client import OpenAIAccountModelClient
return OpenAIAccountModelClient(model_config=model_config, model_client_config=client_config)

if provider == ProviderType.OpenRouter.value:
from openjiuwen.core.foundation.llm.model_clients.openrouter_model_client import OpenRouterModelClient
return OpenRouterModelClient(model_config=model_config, model_client_config=client_config)

if provider == ProviderType.Anthropic.value:
from openjiuwen.core.foundation.llm.model_clients.anthropic_model_client import AnthropicModelClient
return AnthropicModelClient(model_config=model_config, model_client_config=client_config)

if provider == ProviderType.SiliconFlow.value:
from openjiuwen.core.foundation.llm.model_clients.siliconflow_model_client import \
SiliconFlowModelClient
return SiliconFlowModelClient(model_config=model_config, model_client_config=client_config)

if provider == ProviderType.DashScope.value:
from openjiuwen.core.foundation.llm.model_clients.dashscope_model_client import \
DashScopeModelClient
return DashScopeModelClient(model_config=model_config, model_client_config=client_config)

if provider == ProviderType.InferenceAffinity.value:
from openjiuwen.core.foundation.llm.model_clients.inference_affinity_model_client import \
InferenceAffinityModelClient
return InferenceAffinityModelClient(model_config=model_config, model_client_config=client_config)

if provider == ProviderType.AscendAffinity.value:
from openjiuwen.core.foundation.llm.model_clients.ascend_affinity_model_client import \
AscendAffinityModelClient
return AscendAffinityModelClient(model_config=model_config, model_client_config=client_config)

if provider == ProviderType.DeepSeek.value:
from openjiuwen.core.foundation.llm.model_clients.deepseek_model_client import \
DeepSeekModelClient
return DeepSeekModelClient(model_config=model_config, model_client_config=client_config)

if provider == ProviderType.IntelliRouter.value:
from openjiuwen.core.foundation.llm.model_clients.intelli_router_model_client import \
IntelliRouterModelClient
Expand Down Expand Up @@ -78,7 +70,10 @@ def create_model_client(client_config: ModelClientConfig, model_config: ModelReq
error_msg="model client config client_id is none")
provider = client_config.client_provider.value if isinstance(client_config.client_provider, ProviderType)\
else client_config.client_provider
client = _builtin_model_client(provider, client_config, model_config)
normalized_config = normalize_model_client_config(client_config)
dispatch_provider = _implementation_provider(normalized_config)
dispatch_config = normalized_config
client = _builtin_model_client(dispatch_provider, dispatch_config, model_config)
if client is not None:
return client
try:
Expand Down
Loading