fix: modernize OpenAI and LangChain support for GPT-5.1 - #2572
fix: modernize OpenAI and LangChain support for GPT-5.1#2572ranadeepsingh wants to merge 9 commits into
Conversation
## Summary Move Azure OpenAI tests and examples to synapseml-openai-3 with GPT-5.1 and GPT-5-mini deployments. Modernize OpenAI and LangChain dependencies, Azure v1 endpoint usage, reasoning token parameters, Runnable pipelines, and Responses API output handling. ## Prompting Intent The engineer asked to eliminate test coverage on models older than GPT-5.1, allow GPT-5-mini for smaller-model scenarios, remove temperature and top_p from reasoning-model requests, use the synapseml-openai-3 resource, modernize deprecated clients and parameters, and fix the failures motivating the migration. ## Linked Sources - Azure OpenAI API lifecycle: https://learn.microsoft.com/azure/ai-foundry/openai/api-version-lifecycle - OpenAI reasoning guide: https://platform.openai.com/docs/guides/reasoning - LangChain OpenAI integration: https://docs.langchain.com/oss/python/integrations/chat/openai - Internal incident references supplied by the engineer are intentionally omitted from public history. ## Rationale Use GPT-5.1 for full-model validation and GPT-5-mini where the prior test targeted a smaller model. Omit sampling controls because reasoning models reject them, while using low reasoning effort and larger completion budgets to avoid empty visible output. Keep explicit legacy serialization tests so backward-compatibility behavior remains covered while live examples use current OpenAI v1 and LangChain Runnable APIs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: dda7be17-25f0-41e2-bdeb-2f3f3c02438b
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Hey @ranadeepsingh 👋! We use semantic commit messages to streamline the release process. Examples of commit messages with semantic prefixes:
To test your commit locally, please follow our guild on building from source. |
|
/azp run |
|
Azure Pipelines: No pipelines were found matching this branch/path. |
There was a problem hiding this comment.
Pull request overview
This PR migrates SynapseML’s Azure OpenAI examples and test suites to the synapseml-openai-3 resource, updating model coverage to GPT‑5.1 / GPT‑5‑mini and modernizing OpenAI + LangChain usage (OpenAI v1 endpoints, reasoning token parameters, and Runnable pipelines).
Changes:
- Updated Python dependencies to OpenAI SDK v2 and modern LangChain packages (incl.
langchain-openai,langchain-community, andlangchain-classic). - Migrated notebooks to GPT‑5.1 / GPT‑5‑mini deployments, OpenAI v1 endpoint patterns, and reasoning-model parameter conventions (
max_completion_tokens,reasoning_effort). - Updated Scala/Python OpenAI and LangChain tests to remove unsupported sampling params for reasoning models and align expected payloads/output handling.
Show a summary per file
| File | Description |
|---|---|
| environment.yml | Updates OpenAI + LangChain dependency versions to the new stack. |
| docs/Explore Algorithms/OpenAI/Quickstart - Understand and Search Forms.ipynb | Moves to OpenAI SDK v2 client + v1 endpoint style; updates reasoning token parameters. |
| docs/Explore Algorithms/OpenAI/Quickstart - OpenAI Embedding.ipynb | Switches resource/key to synapseml-openai-3. |
| docs/Explore Algorithms/OpenAI/Quickstart - OpenAI Embedding and GPU based KNN.ipynb | Switches resource/key to synapseml-openai-3. |
| docs/Explore Algorithms/OpenAI/Quickstart - Multimodal OpenAI Prompter with Responses API.ipynb | Updates deployment to gpt-5.1 and new secret/resource. |
| docs/Explore Algorithms/OpenAI/OpenAI.ipynb | Updates deployments, removes sampling defaults for reasoning models, and modernizes Responses output extraction. |
| docs/Explore Algorithms/OpenAI/Langchain.ipynb | Migrates to LangChain Runnable pipelines + ChatOpenAI and updates endpoint/key usage. |
| docs/Explore Algorithms/AI Services/Quickstart - Document Question and Answering with PDFs.ipynb | Updates LangChain imports and AOAI config to GPT‑5.1 + v1 endpoint base URL. |
| core/src/test/scala/com/microsoft/azure/synapse/ml/Secrets.scala | Updates the OpenAI test secret name to openai-api-key-3. |
| cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIV1EndpointSuite.scala | Updates expected request URL/model mapping tests to GPT‑5.1. |
| cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIResponsesSuite.scala | Removes temperature usage and updates model strings/output expectations. |
| cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPromptSuite.scala | Removes temperature usage and updates prompt text/headers/tests to GPT‑5.x naming. |
| cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPromptResponsesSuite.scala | Switches live Responses tests to GPT‑5.1 and GPT‑5‑mini. |
| cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbeddingsSuite.scala | Updates default non-embedding deployment used in defaults test to GPT‑5‑mini. |
| cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIDefaultsSuite.scala | Adds per-test default resets and updates globals usage for reasoning models. |
| cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletionSuite.scala | Removes temperature usage and retargets reasoning/sampling behavior tests to new deployments. |
| cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIAPIKey.scala | Updates env var names and standard test deployment names to GPT‑5.1 / GPT‑5‑mini. |
| cognitive/src/test/python/synapsemltest/services/openai/test_StructuredOutput.py | Updates secret/resource/deployment and resets unsupported sampling defaults. |
| cognitive/src/test/python/synapsemltest/services/openai/test_OpenAIDefaults.py | Updates secret/resource/deployment and adds teardown resets for defaults. |
| cognitive/src/test/python/synapsemltest/services/langchain/test_LangchainTransform.py | Migrates tests to Runnable pipelines + ChatOpenAI with reasoning token parameters. |
| cognitive/src/main/python/synapse/ml/services/langchain/LangchainTransform.py | Updates serialization to langchain-core dumps/loads and supports Runnable invoke() with result normalization. |
Review details
Comments suppressed due to low confidence (1)
cognitive/src/main/python/synapse/ml/services/langchain/LangchainTransform.py:267
- The OpenAI <1.0 Azure configuration path no longer sets openai.api_type = "azure". For legacy openai SDK versions, omitting api_type can cause requests to be routed as non-Azure (or otherwise misconfigured), breaking existing LangchainTransformer usage when users rely on the transformer's subscriptionKey/url/apiVersion wiring.
else:
if self.isSet(self.subscriptionKey):
openai.api_key = self.getSubscriptionKey()
if self.isSet(self.url):
openai.api_base = self.getUrl()
- Files reviewed: 21/21 changed files
- Comments generated: 1
- Review effort level: Low
|
/azp run |
|
Azure Pipelines: No pipelines were found matching this branch/path. |
AB#5467643 ## Summary Remove OpenAI SDK 0.x compatibility and module-global client configuration, upgrade active Databricks LangChain dependencies, and make LangchainTransformer reject non-picklable network clients before Spark execution. Update the LangChain notebook to use current batching APIs and limit release compatibility coverage to Spark 3.5 and Spark 4.1. ## Prompting Intent The engineer asked to modernize SynapseML OpenAI tests and examples for GPT-5.1 or GPT-5-mini, remove support for openai<1.0, avoid deprecated APIs and reasoning-incompatible parameters, and update CI to support only Spark 3.5 and Spark 4.1. The engineer also required clean code review and validation before committing and pushing the changes. ## Linked Sources - Tracking bug: https://dev.azure.com/msdata/A365/_workitems/edit/5467643 - Pull request: microsoft#2572 ## Rationale Modern OpenAI clients contain non-picklable HTTP transport state. Rebuilding clients on workers from partial manifests changed authentication, transport, streaming, and rate-limiting behavior, so the transformer now preserves semantics by accepting only genuinely Spark-picklable Runnables and failing clearly otherwise. LangChain batching or SynapseML native OpenAI transformers remain the safe choices for network inference. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: dda7be17-25f0-41e2-bdeb-2f3f3c02438b
AB#5467643 ## Summary Bring the latest upstream master changes, including the restored Azure pipeline and Databricks test infrastructure, into the branch for PR microsoft#2572 while preserving its OpenAI and LangChain modernization changes. ## Prompting Intent The engineer asked to fetch the latest changes from master and apply them to the published PR branch so PR microsoft#2572 is current with its base branch. ## Linked Sources - Pull request: microsoft#2572 - Upstream pipeline fix: microsoft#2573 - Tracking bug: https://dev.azure.com/msdata/A365/_workitems/edit/5467643 ## Rationale Merged upstream master rather than rebasing because the branch is already published and used by an open pull request. This avoids rewriting shared history while retaining the Spark 3.5 and Spark 4.1 compatibility matrix and the modern OpenAI and LangChain dependency pins. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: dda7be17-25f0-41e2-bdeb-2f3f3c02438b
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2572 +/- ##
==========================================
+ Coverage 84.75% 84.79% +0.03%
==========================================
Files 334 334
Lines 17801 17801
Branches 1619 1619
==========================================
+ Hits 15088 15094 +6
+ Misses 2713 2707 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
## Summary Reject LangChain runnables that serialize to unloadable not-implemented stubs, fix Responses API text extraction in the OpenAI notebook, and format the LangChain notebook for the Azure Style check. ## Prompting Intent Review PR 2572 file by file with multiple independent reviewers, fix concrete regression risks, diagnose the failing microsoft.SynapseML Style job, and keep the Azure pipeline running until the updated branch is healthy. ## Linked Sources - Pull request: microsoft#2572 - Azure Style build: https://msdata.visualstudio.com/b9b2accc-2d1c-45b3-9d24-0eb5d78cc47f/_build/results?buildId=228488456 ## Rationale Detecting langchain-core's not-implemented markers before writing metadata prevents artifacts that save successfully but cannot be loaded. The notebook expression now follows the response schema and the library's own extraction logic instead of depending on a nonexistent output-item field. Notebook-only formatting is kept to Black 22.3.0's output so local and Azure style checks agree. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
## Summary Convert LangChain batch results to plain Python strings before creating Spark DataFrames in the LangChain notebook. ## Prompting Intent Continue the file-by-file PR 2572 review, diagnose failures from repeated Azure pipeline runs, and fix only confirmed regressions until the pipeline is green. ## Linked Sources - Pull request: microsoft#2572 - Failed Azure build: https://msdata.visualstudio.com/b9b2accc-2d1c-45b3-9d24-0eb5d78cc47f/_build/results?buildId=228492786 - Failed Databricks job: https://adb-1885762835647850.10.azuredatabricks.net/?o=1885762835647850#job/739517431283627/run/130481332244171 ## Rationale LangChain 1.x returns TextAccessor values from StrOutputParser. Although they behave like strings, PySpark cannot infer their schema. Converting at the notebook boundary preserves displayed content while producing supported Spark StringType values for both example DataFrames. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
## Summary Pin the LangChain notebook to the same unstructured version used by the Databricks test cluster. ## Prompting Intent Continue reviewing PR 2572 file by file, diagnose each Azure pipeline failure, and make only necessary regression fixes until the branch pipeline is green. ## Linked Sources - Pull request: microsoft#2572 - Failed Azure build: https://msdata.visualstudio.com/b9b2accc-2d1c-45b3-9d24-0eb5d78cc47f/_build/results?buildId=228498245 - Failed Databricks run: https://adb-1885762835647850.10.azuredatabricks.net/?o=1885762835647850#job/454662474064029/run/561429143528719 ## Rationale The notebook's unpinned upgrade replaced the cluster's tested unstructured==0.10.24 installation with a newer release that imports pi_heif, which is not installed. Reusing the existing cluster pin avoids an unnecessary dependency and keeps notebook and CI environments consistent. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
## Summary Pin NLTK 3.8.1 in the LangChain notebook so unstructured 0.10.24 can tokenize PDF text without the newer punkt_tab resource. ## Prompting Intent Continue reviewing PR 2572 file by file, diagnose each Azure pipeline failure, and make only necessary regression fixes until the branch pipeline is green. ## Linked Sources - Pull request: microsoft#2572 - Failed Azure build: https://msdata.visualstudio.com/b9b2accc-2d1c-45b3-9d24-0eb5d78cc47f/_build/results?buildId=228502637 - Failed Databricks run: https://adb-1885762835647850.10.azuredatabricks.net/?o=1885762835647850#job/994359116237647/run/718696557480018 ## Rationale The PR removed the notebook base version's existing nltk==3.8.1 pin. Current NLTK requests punkt_tab, while unstructured==0.10.24 only provisions the older punkt resource. Restoring the prior compatible pin is narrower and more reproducible than adding runtime downloader side effects. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
## Summary Pin NumPy 1.26.4 in environment.yml so the upgraded LangChain dependency set remains binary-compatible with pandas 2.0.3 and PyArrow 10. ## Prompting Intent Continue reviewing PR 2572 file by file, diagnose each Azure pipeline failure, and make only necessary regression fixes until the branch pipeline is green. ## Linked Sources - Pull request: microsoft#2572 - Failed Azure build: https://msdata.visualstudio.com/b9b2accc-2d1c-45b3-9d24-0eb5d78cc47f/_build/results?buildId=228507594 - OpenCV Python failure: Azure job f3f808a3-a9f8-5179-a4b0-94b8425d1004 - VW Python failure: Azure job 1308dffb-2cf2-56a1-9668-a2c9f65e760f ## Rationale The previous LangChain package constrained NumPy below 2 indirectly. After the upgrade, pip selected NumPy 2.4.6 alongside pandas 2.0.3, causing binary incompatibility during test collection. An explicit NumPy 1.26.4 pin restores deterministic resolution, satisfies the new LangChain requirements, and matches the existing Databricks test environment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
## Summary Update the live Responses API test to validate the final extracted message text rather than requiring every output item, including GPT-5 reasoning entries, to contain text. Use low reasoning effort for predictable test cost and latency. ## Prompting Intent Continue reviewing PR 2572 file by file, diagnose each Azure pipeline failure, and make only necessary regression fixes until the branch pipeline is green. ## Linked Sources - Pull request: microsoft#2572 - Failed Azure build: https://msdata.visualstudio.com/b9b2accc-2d1c-45b3-9d24-0eb5d78cc47f/_build/results?buildId=228511571 - Failed Azure job: UnitTests openai, job 30886130-6c10-51cc-2b7c-fdfe28a165e1 ## Rationale GPT-5 Responses legitimately include a leading reasoning output item with no user-visible text. The production extraction path selects the final message item, so the test should validate that same contract instead of treating reasoning metadata as an empty answer. Low reasoning effort reduces unnecessary token use without weakening the output assertion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (2)
cognitive/src/test/python/synapsemltest/services/openai/test_OpenAIDefaults.py:32
tearDown()resets several OpenAIDefaults fields, but it does not reset newer mutable defaults (verbosity,reasoning_effort,api_type). Since these defaults are JVM-global and shared across tests, leaving them set can cause cross-test state leakage (the PR description mentions preventing this).
def tearDown(self):
defaults = OpenAIDefaults()
defaults.reset_deployment_name()
defaults.reset_subscription_key()
defaults.reset_temperature()
cognitive/src/test/python/synapsemltest/services/openai/test_StructuredOutput.py:67
setUpClass()resets model/sampling defaults, but it does not reset newer global OpenAIDefaults fields (verbosity,reasoning_effort,api_type). Because OpenAIDefaults are shared across tests, a prior test that sets these fields can leak into this suite and change request behavior.
defaults = OpenAIDefaults()
defaults.reset_model()
defaults.reset_temperature()
defaults.reset_top_p()
defaults.reset_seed()
- Files reviewed: 23/23 changed files
- Comments generated: 1
- Review effort level: Low
| "from openai import OpenAI\n", | ||
| "\n", | ||
| "openai.api_type = \"azure\"\n", | ||
| "openai.api_base = openai_url\n", | ||
| "openai.api_key = openai_key\n", | ||
| "openai.api_version = \"2023-03-15-preview\"\n", | ||
| "openai_client = OpenAI(\n", | ||
| " api_key=openai_key,\n", | ||
| " base_url=f\"{openai_url.rstrip('/')}/openai/v1/\",\n", | ||
| ")\n", |
Summary
Modernize SynapseML's Azure OpenAI tests, examples, packages, and LangChain integration for
gpt-5.1andgpt-5-minion thesynapseml-openai-3resource. Remove OpenAI SDK 0.x compatibility, use current Azure OpenAI v1 APIs, and update release compatibility coverage to Spark 3.5 and Spark 4.1.Why
The previous coverage depended on old deployments, SDKs, and request behavior that is incompatible with current GPT-5 reasoning models:
temperatureandtop_p.What changed
gpt-5.1orgpt-5-mini.synapseml-openai-3/openai-api-key-3.max_completion_tokens/max_output_tokens.openai<1.0exception handling, legacyopenai.api_*global configuration, and legacy LangChain chain-loading fallback.LangchainTransformerto support Spark-picklable Runnables, normalize modern LangChain string outputs, capture currentOpenAIErrorexceptions, and fail clearly when a chain captures a non-picklable OpenAI client.pipeline.yamltriggers and release compatibility checks to support only Spark 3.5/JDK 11 and Spark 4.1/JDK 17.Validation
sbt "core/Test/compile" scalastyle test:scalastylesbt cognitive/Test/compileOpenAIDefaultsSuiteandOpenAIV1EndpointSuiteblack --check --extend-exclude 'docs/' .Dependency changes
langchain:0.0.152->1.3.14openai:0.27.5->2.47.0langchain-classic==1.0.8langchain-community==0.4.2langchain-openai==1.4.0Compatibility notes
LangchainTransformerno longer configures OpenAI through module-global state.