Python: feat: Add Astraflow (UCloud) AI provider connector#13908
Python: feat: Add Astraflow (UCloud) AI provider connector#13908ucloudnb666 wants to merge 12 commits intomicrosoft:mainfrom
Conversation
…astraflow/__init__.py
…astraflow/README.md
…astraflow/settings/__init__.py
…astraflow/settings/astraflow_settings.py
…astraflow/prompt_execution_settings/__init__.py
…astraflow/prompt_execution_settings/astraflow_prompt_execution_settings.py
…astraflow/services/__init__.py
…astraflow/services/astraflow_model_types.py
…astraflow/services/astraflow_handler.py
…astraflow/services/astraflow_chat_completion.py
…astraflow/services/astraflow_text_embedding.py
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 93%
✗ Correctness
The Astraflow connector has one blocking bug: streaming chat completions will always crash with an AssertionError because the code asserts that the OpenAI AsyncStream response is an instance of collections.abc.AsyncGenerator, which it is not (verified: issubclass(AsyncStream, AsyncGenerator) is False). Additionally, the _prepare_chat_history_for_request method unnecessarily overrides the base class's robust implementation with a naive one that loses tool-call and structured content information.
✗ Security Reliability
The new Astraflow connector introduces three reliability concerns: (1) the custom
_prepare_chat_history_for_requestoverride bypassesChatMessageContent.to_dict(), which stripstool_calls,tool_call_id, and multi-modal content from the request payload — breaking function/tool calling despite the connector explicitly implementing tool-call parsing; (2)AstraflowTextEmbedding.from_dictomits thebase_urlparameter, silently losing custom endpoint configuration (e.g. China endpoint) during deserialization; (3) the embedding service only warns when no API key is found instead of failing fast, deferring errors to runtime with confusing messages.
✗ Test Coverage
This PR adds a new Astraflow AI connector with chat completion, text embedding, prompt execution settings, a handler, and configuration settings — but includes zero unit tests. Every other AI connector in the project (Nvidia, Ollama, Mistral AI, Anthropic, Azure AI Inference, etc.) has a corresponding test directory under
python/tests/unit/connectors/ai/with tests covering initialization, settings validation, chat completion (mocked), text embedding (mocked), error handling, and serialization round-trips. The complete absence of tests for all new classes is a blocking gap in test coverage.
✗ Design Approach
The connector is a reasonable 'OpenAI-compatible with custom base_url' implementation that follows the existing NVIDIA connector pattern. The most critical design flaw is that _prepare_chat_history_for_request is overridden to use
message.content(plain text only) instead ofmessage.to_dict(), which the base class already provides correctly. This means any conversation involving function/tool calls will silently lose the tool_call_id and structured content from TOOL-role messages, breaking function calling entirely. A secondary issue is that theresponse_formatfield is declared in the settings class but explicitly excluded fromprepare_settings_dict, making JSON mode and structured output silently non-functional.
Flagged Issues
-
_prepare_chat_history_for_request(lines 282-293 of astraflow_chat_completion.py) overrides the base class to build a simple{role, content}dict usingmessage.content(plain text) instead ofmessage.to_dict(). This dropstool_callson assistant messages,tool_call_idon tool-result messages, multi-modal content items, messagename, and ignores theinstruction_rolesetting. Since the connector supports function calling (parses tool_calls in responses, exposestoolsin settings), any multi-turn function-calling conversation will fail. The base classChatCompletionClientBase._prepare_chat_history_for_requestalready handles OpenAI-compatible serialization correctly viamessage.to_dict(). The fix is to remove this override entirely.
Automated review by ucloudnb666's agents
|
@ucloudnb666 These connectors are better supported from from the Astraflow repo |
Summary
This PR adds a new AI provider connector for Astraflow (by UCloud / 优刻得), an OpenAI-compatible AI model aggregation platform that supports 200+ models.
What's added
python/semantic_kernel/connectors/ai/astraflow/— full connector package following the exact same structure as the existingnvidiaconnector:AstraflowSettings) — readsASTRAFLOW_API_KEY(global) orASTRAFLOW_CN_API_KEY(China) from environment, with sensible defaults for both endpoints.AstraflowPromptExecutionSettings,AstraflowChatPromptExecutionSettings,AstraflowEmbeddingPromptExecutionSettings)AstraflowHandler) — thin async wrapper aroundopenai.AsyncOpenAIAstraflowChatCompletion)AstraflowTextEmbedding).env.example— addsASTRAFLOW_API_KEYandASTRAFLOW_CN_API_KEYentriesEndpoints
https://api-us-ca.umodelverse.ai/v1ASTRAFLOW_API_KEYhttps://api.modelverse.cn/v1ASTRAFLOW_CN_API_KEYUsage
Sign up at https://astraflow.ucloud.cn/