From 4e86e3720286ed29e6b19c858f0ded8b230d5a9c Mon Sep 17 00:00:00 2001 From: gongzhiyong Date: Sun, 26 Apr 2026 15:43:09 +0800 Subject: [PATCH] Fix long tool call id handling and add Chinese quick usage. Normalize tool call IDs to Azure's 64-char limit and document a Chinese quick setup flow for Cursor + Azure GPT-5.4 deployment. Made-with: Cursor --- README.md | 30 +++++++++++++++++++++++++++++- app/azure/request_adapter.py | 10 ++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9ffeb52..f2c5f23 100644 --- a/README.md +++ b/README.md @@ -280,4 +280,32 @@ docker tag app-production your-tag docker push your-tag ``` - \ No newline at end of file + + +## Chinese Quick Usage (Cursor + Azure GPT-5.4) + +1. Deploy and run service: + +```bash +docker compose up -d flask-prod +``` + +2. Set `.env` key values: + +```env +SERVICE_API_KEY=change-me +AZURE_BASE_URL=https://.cognitiveservices.azure.com +AZURE_API_KEY= +AZURE_DEPLOYMENT=gpt-5.4 +``` + +3. In Cursor settings: + - Override OpenAI Base URL: your public URL, e.g. `https://.trycloudflare.com` + - OpenAI API Key: same as `SERVICE_API_KEY` + - Add custom models: `gpt-high`, `gpt-medium`, `gpt-low`, `gpt-minimal` + +4. Optional quick tunnel: + +```bash +cloudflared tunnel --url http://localhost:8080 +``` \ No newline at end of file diff --git a/app/azure/request_adapter.py b/app/azure/request_adapter.py index 8c8e1c3..ebe7bb1 100644 --- a/app/azure/request_adapter.py +++ b/app/azure/request_adapter.py @@ -58,6 +58,12 @@ class RequestAdapter: headers["api-key"] = api_key return headers + def _normalize_call_id(self, call_id: Any) -> str: + """Return an Azure-compatible call_id (max length 64).""" + if call_id is None: + return "" + return str(call_id)[:64] + def _messages_to_responses_input_and_instructions( self, messages: List[Dict[str, Any]] ) -> Dict[str, Any]: @@ -72,7 +78,7 @@ class RequestAdapter: continue # For user/assistant/tools as inputs if role == "tool": - call_id = m.get("tool_call_id") + call_id = self._normalize_call_id(m.get("tool_call_id")) item = { "type": "function_call_output", "output": self._content_to_text(content), @@ -96,7 +102,7 @@ class RequestAdapter: if tool_calls := m.get("tool_calls"): for tool_call in tool_calls: function = tool_call.get("function", {}) - call_id = tool_call.get("id") + call_id = self._normalize_call_id(tool_call.get("id")) item = { "type": "function_call", "name": function.get("name"),