From 66602da9cb6f3a9f6fe9685e13abb1a414e9254a Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sat, 22 Nov 2025 14:38:26 +0800 Subject: [PATCH] feat: add model_config parameter support for Dify assistant type apps (#1796) * Initial plan * feat: add model_config parameter support for Dify assistant type - Add model_config parameter to AsyncDifyServiceClient.chat_messages method - Add _get_model_config helper method to DifyServiceAPIRunner - Pass model_config from pipeline configuration to all chat_messages calls - Add model-config configuration field to dify-service-api schema in ai.yaml - Support optional model configuration for assistant type apps in open-source Dify Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * refactor: improve model_config implementation based on code review - Simplify _get_model_config method logic - Add more descriptive comment about model_config usage - Clarify when model_config is used (assistant type apps) Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * feat: only modify client.py --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> Co-authored-by: Junyan Qin --- .../libs/dify_service_api/v1/client.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/langbot/libs/dify_service_api/v1/client.py b/src/langbot/libs/dify_service_api/v1/client.py index 244d701e..cc8008e1 100644 --- a/src/langbot/libs/dify_service_api/v1/client.py +++ b/src/langbot/libs/dify_service_api/v1/client.py @@ -32,6 +32,7 @@ class AsyncDifyServiceClient: conversation_id: str = '', files: list[dict[str, typing.Any]] = [], timeout: float = 30.0, + model_config: dict[str, typing.Any] | None = None, ) -> typing.AsyncGenerator[dict[str, typing.Any], None]: """发送消息""" if response_mode != 'streaming': @@ -42,6 +43,16 @@ class AsyncDifyServiceClient: trust_env=True, timeout=timeout, ) as client: + payload = { + 'inputs': inputs, + 'query': query, + 'user': user, + 'response_mode': response_mode, + 'conversation_id': conversation_id, + 'files': files, + 'model_config': model_config or {}, + } + async with client.stream( 'POST', '/chat-messages', @@ -49,14 +60,7 @@ class AsyncDifyServiceClient: 'Authorization': f'Bearer {self.api_key}', 'Content-Type': 'application/json', }, - json={ - 'inputs': inputs, - 'query': query, - 'user': user, - 'response_mode': response_mode, - 'conversation_id': conversation_id, - 'files': files, - }, + json=payload, ) as r: async for chunk in r.aiter_lines(): if r.status_code != 200: