Repository navigation
feat(llm): add iFlytek Spark chat client - #672
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new iFlytek Spark chat provider to dapr_agents.llm, implemented as an OpenAI-compatible client (reusing the shared OpenAI-compatible request/response/streaming/tooling paths, similar to the existing NVIDIA provider).
Changes:
- Introduces
dapr_agents/llm/iflytekwithIFlytekClientBaseandIFlytekChatClient, including Prompty wiring viatype: iflytek. - Extends shared OpenAI-compatible utilities (response/stream/structured-output/tool-formatting/observability) to recognize
"iflytek"as a provider. - Adds unit tests for initialization, missing-key behavior, mocked generation, and
from_prompty.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/llm/test_iflytek.py | Adds unit coverage for the new iFlytek client (init, generate, env/key handling, Prompty). |
| dapr_agents/types/llm.py | Adds IFlytek config + Prompty parameter model types and integrates them into Prompty unions/validation. |
| dapr_agents/tool/utils/function_calling.py | Treats iflytek as an OpenAI-style tool/function schema for tool formatting/validation. |
| dapr_agents/observability/utils.py | Resolves provider name "iflytek" for observability based on module path. |
| dapr_agents/observability/instrumentor.py | Discovers iFlytek chat clients during provider module scanning. |
| dapr_agents/llm/utils/structure.py | Enables structured-output extraction for iflytek via the OpenAI-compatible branch. |
| dapr_agents/llm/utils/stream.py | Routes iflytek streaming responses through the OpenAI-compatible stream processor. |
| dapr_agents/llm/utils/response.py | Routes iflytek non-stream responses through the OpenAI-compatible response processor. |
| dapr_agents/llm/iflytek/client.py | New OpenAI-transport-based client base handling env key fallback and client construction. |
| dapr_agents/llm/iflytek/chat.py | New chat client implementing generate() with shared request/response handlers and Prompty integration. |
| dapr_agents/llm/iflytek/init.py | Exposes IFlytekChatClient from the provider package. |
| dapr_agents/llm/init.py | Exports IFlytekChatClient from the public dapr_agents.llm surface. |
Comments suppressed due to low confidence (1)
dapr_agents/tool/utils/function_calling.py:302
- The validate_and_format_tool docstring lists the OpenAI-style tool_format values but does not include iflytek, even though the implementation now supports it. Keeping the docstring in sync avoids confusion when adding new OpenAI-compatible providers.
try:
if fmt in ("openai", "azure_openai", "nvidia", "huggingface", "iflytek"):
validated = (
OAIFunctionDefinition(**tool)
if use_deprecated
else OAIToolDefinition(**tool)
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tools: Optional[List[Dict[str, Any]]] = Field( | ||
| None, description="List of tools the model may call" | ||
| ) |
| max_tokens: Optional[int] = Field( | ||
| default=1024, | ||
| description=( | ||
| "Maximum number of tokens to generate in a single call. " | ||
| "Must be ≥1; defaults to 1024." | ||
| ), | ||
| ) |
| # OpenAI‑style wrapper schema: | ||
| if fmt in ("openai", "nvidia", "huggingface", "dapr"): | ||
| if fmt in ("openai", "nvidia", "huggingface", "dapr", "iflytek"): | ||
| return to_openai_function_call_definition( | ||
| name, description, args_schema, use_deprecated | ||
| ) |
feat(llm): add iFlytek Spark chat client Add an iFlytek Spark chat client provider. iFlytek Spark exposes an OpenAI-compatible chat-completions endpoint (https://spark-api-open.xf-yun.com/v1), so the client reuses the OpenAI SDK for transport and the shared OpenAI-compatible request/response, streaming, structured-output and tool-formatting paths, mirroring the existing NVIDIA provider. - New dapr_agents/llm/iflytek package (IFlytekClientBase, IFlytekChatClient) - IFlytekClientConfig / IFlytekModelConfig / IFlytekChatCompletionParams types and Prompty configuration/parameters wiring - Register iflytek in the OpenAI-compatible branches of the response, stream, structured-output, tool-formatting and observability helpers - Export IFlytekChatClient from dapr_agents.llm - Unit tests for initialization, generation, missing key and from_prompty @ Signed-off-by: FenjuFu <92919259+FenjuFu@users.noreply.github.com>
fix(llm): address review feedback on iFlytek provider Add max_length=64 to IFlytekChatCompletionParams.tools and ge=1 to the chat client max_tokens field, matching the other OpenAI-compatible providers, and update the to_function_call_definition docstring to list all formats sharing the OpenAI-style schema. @ Signed-off-by: FenjuFu <92919259+FenjuFu@users.noreply.github.com>
41ac651 to
bbd0f3d
Compare
|
Addressed the review feedback: added max_length=64 to IFlytekChatCompletionParams.tools and ge=1 to the chat client max_tokens field (matching the other OpenAI-compatible providers), and updated the to_function_call_definition docstring to list all formats sharing the OpenAI-style schema. Also rebased onto main to resolve the conflict with the new litellm provider; the shared OpenAI-compatible branches now include both providers. Full llm+tool test suite passes locally (204 tests). |
sicoyle
left a comment
There was a problem hiding this comment.
amazing addition. Thank you for your interest in Dapr Agents!! 🙌
Description
Adds an iFlytek Spark chat client provider.
iFlytek Spark exposes an OpenAI-compatible chat-completions endpoint
(
https://spark-api-open.xf-yun.com/v1), so the new client reuses the OpenAISDK for transport and the shared OpenAI-compatible request / response /
streaming / structured-output / tool-formatting paths — mirroring the existing
nvidiaprovider rather than adding a bespoke client.What's included
dapr_agents/llm/iflytekpackage:IFlytekClientBaseandIFlytekChatClientIFlytekClientConfig,IFlytekModelConfig, andIFlytekChatCompletionParamstypes, plus Prompty configuration/parameters wiring (
type: iflytek)iflytekregistered alongsideopenai/nvidiain the OpenAI-compatiblebranches of the response, stream, structured-output, tool-formatting and
observability helpers
IFlytekChatClientexported fromdapr_agents.llmand
from_promptyUsage
Testing
pytest tests/llm→ all pass (incl. newtests/llm/test_iflytek.py)pytest tests/tool→ all pass (no regression from the shared tool-format change)ruff check/ruff format --checkcleanIssue reference
N/A — additive new provider; no behavior change to existing providers.