Fetch WolframAlpha images in parallel via URLSubmit#185
Merged
Conversation
Replace the sequential `Import[..., "Image"]` loop in `extractWolframAlphaImages` with concurrent `URLSubmit` requests bounded by a single `TaskWait[TimeConstraint -> $waImageFetchTimeout]`, so total latency is the slowest image rather than the sum. The new `makeImageContent` helper passes the server's original bytes and mime type through (preserving animated GIFs), avoiding the prior Rasterize/PNG round-trip. The URL pattern also picks up `.webp` and `.svg`. Loosened one test to accommodate the merged-adjacent-text shape on failed fetches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Parallelizes WolframAlpha image fetching in extractWolframAlphaImages using concurrent URLSubmit tasks bounded by a single TaskWait timeout, and passes through the server's original image bytes/mime-type instead of rasterizing through PNG. Also widens the URL pattern to accept .webp/.svg and merges adjacent text items in the structured output.
Changes:
- Refactor
extractWolframAlphaImagesto submit all image URLs concurrently viaURLSubmit, with a per-URL handler that overwrites a prefilled text fallback in afetchedassociation; the whole batch is bounded byTaskWait[TimeConstraint -> $waImageFetchTimeout]. - Introduce
makeImageContenthelper that produces{text, image}content items directly from the HTTP response, preserving the originalcontent-type(e.g. animated GIFs, WebP, SVG) instead of going throughRasterize/PNG. - Extend the WA image URL pattern with
.webpand.svg, collapse adjacent text items withSequenceReplace, addwebpto.cspell.json, and loosen theMultipleContentItemstest to accept the merged-text shape.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Kernel/StartMCPServer.wl | New $waImageFetchTimeout config, new makeImageContent helper, rewritten extractWolframAlphaImages using concurrent URLSubmit + TaskWait, expanded URL pattern, adjacent-text merging. |
| Tests/Graphics.wlt | Loosens MultipleContentItems assertion to tolerate merged adjacent text items; renumbers TestIDs. |
| .cspell.json | Adds webp to dictionary. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Import[..., "Image"]loop inextractWolframAlphaImageswith concurrentURLSubmitrequests bounded by a singleTaskWait[TimeConstraint -> $waImageFetchTimeout], so total batch latency tracks the slowest fetch instead of summing across all images.makeImageContenthelper passes the server's original bytes andcontent-typestraight through (preserving animated GIFs), eliminating the priorRasterize/PNG round-trip..webpand.svg, and merge adjacent text items in the final content list so the output stays compact when fetches fail.Test plan
TestReportforTests/Graphics.wltpasses, including the loosenedextractWolframAlphaImages-MultipleContentItemsassertion that now accepts the merged-adjacent-text shape on failed fetches.CodeInspectorclean onKernel/StartMCPServer.wl.imageitem per successful URL (with the original mime type) and falls back to the markdown text link when a fetch times out.🤖 Generated with Claude Code