Skip to content

feat(llm): add iFlytek Spark chat client - #672

Merged
sicoyle merged 3 commits into
dapr:mainfrom
FenjuFu:feat/iflytek-spark-chat-client
Jul 14, 2026
Merged

sicoyle merged 3 commits into
dapr:mainfrom
FenjuFu:feat/iflytek-spark-chat-client

Conversation

@FenjuFu

@FenjuFu FenjuFu commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

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 OpenAI
SDK for transport and the shared OpenAI-compatible request / response /
streaming / structured-output / tool-formatting paths — mirroring the existing
nvidia provider rather than adding a bespoke client.

What's included

  • New dapr_agents/llm/iflytek package: IFlytekClientBase and IFlytekChatClient
  • IFlytekClientConfig, IFlytekModelConfig, and IFlytekChatCompletionParams
    types, plus Prompty configuration/parameters wiring (type: iflytek)
  • iflytek registered alongside openai/nvidia in the OpenAI-compatible
    branches of the response, stream, structured-output, tool-formatting and
    observability helpers
  • IFlytekChatClient exported from dapr_agents.llm
  • Unit tests covering initialization, generation (mocked), missing-key error,
    and from_prompty

Usage

from dapr_agents.llm import IFlytekChatClient

# IFLYTEK_API_KEY = the HTTP API password from the iFlytek open-platform console
llm = IFlytekChatClient(model="generalv3.5")
resp = llm.generate("Hello")

Testing

  • pytest tests/llm → all pass (incl. new tests/llm/test_iflytek.py)
  • pytest tests/tool → all pass (no regression from the shared tool-format change)
  • ruff check / ruff format --check clean

Issue reference

N/A — additive new provider; no behavior change to existing providers.

@FenjuFu
FenjuFu requested review from a team as code owners June 29, 2026 09:33
@sicoyle
sicoyle requested a review from Copilot July 7, 2026 20:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/iflytek with IFlytekClientBase and IFlytekChatClient, including Prompty wiring via type: 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.

Comment thread dapr_agents/types/llm.py
Comment on lines +434 to +436
tools: Optional[List[Dict[str, Any]]] = Field(
None, description="List of tools the model may call"
)
Comment on lines +67 to +73
max_tokens: Optional[int] = Field(
default=1024,
description=(
"Maximum number of tokens to generate in a single call. "
"Must be ≥1; defaults to 1024."
),
)
Comment on lines 252 to 256
# 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
)
FenjuFu added 2 commits July 14, 2026 15:11
@
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>
@FenjuFu
FenjuFu force-pushed the feat/iflytek-spark-chat-client branch from 41ac651 to bbd0f3d Compare July 14, 2026 07:45
@FenjuFu

FenjuFu commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

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 sicoyle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing addition. Thank you for your interest in Dapr Agents!! 🙌

@sicoyle
sicoyle merged commit 2dff98f into dapr:main Jul 14, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants