✨Feat:Enhance prompt optimization by integrating openjiuwen and fix related bugs#3190
Open
DongJiBao2001 wants to merge 26 commits into
Open
✨Feat:Enhance prompt optimization by integrating openjiuwen and fix related bugs#3190DongJiBao2001 wants to merge 26 commits into
DongJiBao2001 wants to merge 26 commits into
Conversation
| except NexentCapabilityError as e: | ||
| return JSONResponse( | ||
| status_code=HTTPStatus.BAD_REQUEST, | ||
| content={"message": str(e)}, |
| except NexentCapabilityError as e: | ||
| return JSONResponse( | ||
| status_code=HTTPStatus.BAD_REQUEST, | ||
| content={"message": str(e)}, |
| except NexentCapabilityError as e: | ||
| return JSONResponse( | ||
| status_code=HTTPStatus.BAD_REQUEST, | ||
| content={"message": str(e)}, |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR integrates OpenJiuwen-based prompt optimization into Nexent, exposing fine-grained optimization modes (global/insert/replace/feedback via bad cases) through new backend APIs and updated frontend UX, and aligns the runtime/tooling stack to Python 3.11 plus newer MCP/FastMCP versions.
Changes:
- Add a unified backend
PromptOptimizationServicethat uses Jiuwen SDK when available and falls back to Nexent’s native optimizer where supported. - Add new prompt optimization endpoints (
/prompt/optimize,/prompt/optimize/badcase,/prompt/optimize/from_debug) and update frontend types/UI to support mode-based optimization and agent-debug “optimize from reply”. - Upgrade Python/runtime and dependency baselines (Python 3.11 images/workflows; fastmcp/mcp version bumps; introduce
openjiuwen).
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| test/backend/services/test_prompt_service.py | Adds unit tests for the new optimization service (Jiuwen vs Nexent fallback). |
| test/backend/app/test_prompt_app.py | Updates API tests to mock PromptOptimizationService and cover new endpoints. |
| sdk/pyproject.toml | Bumps mcp/fastmcp dependency ranges for the SDK package. |
| make/mcp/Dockerfile | Moves MCP image base to Python 3.11 and adjusts shell strict-mode usage. |
| make/main/Dockerfile | Moves main image base to Python 3.11. |
| make/data_process/Dockerfile | Moves data_process image base to Python 3.11 and installs SDK extras. |
| frontend/types/agentConfig.ts | Extends prompt optimization request types with mode/positions; adds badcase request/response types. |
| frontend/services/promptService.ts | Keeps /prompt/optimize client; removes badcase client function (commented as automated elsewhere). |
| frontend/public/locales/zh/common.json | Adds i18n strings for prompt optimization and compare UX (ZH). |
| frontend/public/locales/en/common.json | Adds i18n strings for prompt optimization and compare UX (EN). |
| frontend/pnpm-workspace.yaml | Updates pnpm workspace build-related configuration. |
| frontend/app/[locale]/agents/components/agentInfo/PromptTemplateManagerModal.tsx | Defers form initialization to avoid modal mount timing issues; switches modal destroy behavior. |
| frontend/app/[locale]/agents/components/agentInfo/PromptOptimizeModal.tsx | Adds mode selection + insert/select position handling and richer before/after UI. |
| frontend/app/[locale]/agents/components/agentInfo/DebugPromptCompareModal.tsx | New modal for comparing original vs optimized full prompts. |
| frontend/app/[locale]/agents/components/agentInfo/DebugOptimizeModal.tsx | New modal to optimize full system prompt from agent-debug selected reply. |
| frontend/app/[locale]/agents/components/agentInfo/DebugMessageList.tsx | Adds “optimize this reply” action wiring from assistant messages. |
| frontend/app/[locale]/agents/components/agentInfo/DebugConfig.tsx | Integrates new debug optimization flow and applies optimized full prompt back into agent config. |
| frontend/app/[locale]/agents/components/agentInfo/AgentGenerateDetail.tsx | Adjusts optimized-content apply handler to target the correct section fields. |
| backend/services/prompt_service.py | Implements PromptOptimizationService, request/result dataclasses, and Jiuwen/Nexent fallback logic. |
| backend/pyproject.toml | Bumps required Python to 3.11, adds openjiuwen, updates dependencies, and adds uv exclusions. |
| backend/mcp_service.py | Updates FastMCP .mount() call signatures to match newer FastMCP API expectations. |
| backend/consts/model.py | Extends optimize request model with mode/start/end and adds badcase + debug optimization request models. |
| backend/consts/const.py | Adds ENABLE_JIUWEN_SDK env flag. |
| backend/apps/prompt_app.py | Reworks /prompt/optimize to use the new service and adds badcase/from_debug routes with headers. |
| backend/apps/app_factory.py | Adds global handling for NexentCapabilityError as HTTP 400. |
| backend/adapters/jiuwen_sdk_adapter.py | New adapter providing lazy/robust SDK import and feedback/badcase optimization entry points. |
| backend/adapters/exception.py | New adapter exception types for Jiuwen and Nexent capability signaling. |
| backend/adapters/init.py | Exposes adapter symbols and safely imports JiuwenSDKAdapter. |
| .github/workflows/sdk_publish.yml | Updates workflow Python to 3.11. |
| .github/workflows/auto-unit-test.yml | Updates workflow Python to 3.11. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+98
to
+101
| assert response.status_code == 200 | ||
| assert call_args[0][0].mode == "insert" | ||
| assert call_args[0][0].start_pos == 10 | ||
| assert call_args[0][0].end_pos == 20 |
Comment on lines
+2072
to
+2074
| @patch('backend.services.prompt_service.optimize_prompt_section_impl') | ||
| @patch('backend.services.prompt_service.ENABLE_JIUWEN_SDK', False) | ||
| def test_optimize_nexent_fallback_general_mode(self, mock_impl): |
Comment on lines
+2144
to
+2149
| from consts.const import ENABLE_JIUWEN_SDK | ||
|
|
||
| # Patch ENABLE_JIUWEN_SDK to False | ||
| with patch('backend.services.prompt_service.ENABLE_JIUWEN_SDK', False): | ||
| service = PromptOptimizationService(model_id=1, tenant_id="t", language="zh") | ||
| self.assertFalse(service.is_jiuwen_mode_available()) |
Comment on lines
+2151
to
+2171
| @patch('backend.services.prompt_service.ENABLE_JIUWEN_SDK', True) | ||
| @patch('backend.services.prompt_service.sys.modules', {'openjiuwen': MagicMock()} if False else {}) | ||
| def test_is_jiuwen_mode_available_openjiuwen_missing(self): | ||
| """openjiuwen 未安装时 Jiuwen SDK 不可用""" | ||
| import sys | ||
| saved = sys.modules.copy() | ||
|
|
||
| # Simulate openjiuwen not installed | ||
| def fake_import(name, *args, **kwargs): | ||
| if name == 'openjiuwen': | ||
| raise ModuleNotFoundError("No module named 'openjiuwen'") | ||
| return saved.get(name) | ||
|
|
||
| with patch.dict('sys.modules', {'openjiuwen': None}): | ||
| service = PromptOptimizationService(model_id=1, tenant_id="t", language="zh") | ||
| # Mock ENABLE_JIUWEN_SDK to True | ||
| with patch('backend.services.prompt_service.ENABLE_JIUWEN_SDK', True): | ||
| with patch('builtins.__import__', side_effect=fake_import): | ||
| # We need to actually trigger the import check | ||
| # Patch at the point where the check happens | ||
| pass # skip - import already happened at module load |
Comment on lines
+900
to
+912
| def is_jiuwen_mode_available(self) -> bool: | ||
| """判断 Jiuwen SDK 模式是否可用""" | ||
| from consts.const import ENABLE_JIUWEN_SDK | ||
|
|
||
| if not ENABLE_JIUWEN_SDK: | ||
| return False | ||
|
|
||
| try: | ||
| import openjiuwen # noqa: F401 | ||
| except ImportError: | ||
| return False | ||
|
|
||
| return True |
Comment on lines
+34
to
+38
| from dataclasses import dataclass, field | ||
| from typing import Optional as Opt | ||
|
|
||
| from adapters.exception import JiuwenSDKError, NexentCapabilityError | ||
| from adapters.jiuwen_sdk_adapter import JiuwenSDKAdapter |
Comment on lines
26
to
+30
| "scikit-learn>=1.0.0", | ||
| "numpy>=1.24.0", | ||
| "openjiuwen>=0.1.0", | ||
| "pydantic-settings>=2.0.0", | ||
| ] |
Comment on lines
+320
to
325
| {/* Submit Button */} | ||
| <div className="flex justify-end"> | ||
| <Button | ||
| type="primary" | ||
| onClick={handleOptimize} | ||
| loading={isOptimizing} | ||
| > | ||
| <Button type="primary" onClick={handleOptimize}> | ||
| {t("systemPrompt.optimize.submit")} | ||
| </Button> | ||
| </div> |
…ort in prompt_service.py
… test coverage for prompt optimization service
…gging formatting in prompt_service.py
… import paths in prompt_service.py
…s in prompt_service.py and related test files
…ingface_hub version in pyproject.toml
…e paths in test files
…up module imports in data processing tests
…ss multiple test files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Integrated Openjiuwen's prompt optimization feature: supports fine-grained adjustments including global optimization, insertion optimization, replacement optimization, and feedback-based optimization using bad cases on the agent debugging page . #3187



