Conversation
parse_azure_endpoint returned the raw URL including ?api-version=... which AsyncAzureOpenAI then mangled into invalid paths like ...?api-version=2024-06-01/openai/. Strip the query string before returning — api_version is already returned as a separate value and passed to the SDK independently.
3 tasks
black is only used in create_context_prompt() and format_code() -- both cold paths. Moving the import inside the functions avoids loading black and its transitive deps (pathspec, black.nodes, etc.) on every import typeagent.
…crosoft#231) - `parse_azure_endpoint` returned the full URL including `?api-version=...` - `AsyncAzureOpenAI` appends `/openai/` to `azure_endpoint`, producing a mangled URL with the query string in the path - Now strips the query string with `str.split("?", 1)[0]` before returning - Added 6 unit tests covering: basic URL, no version, separate env var, missing env var, empty query string ## Benchmark No performance impact — this is a correctness fix. --- *Generated by codeflash optimization agent*
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.
import blackfrom module level to first use inanswers.pyandutils.pyblack(code formatter + transitive deps: pathspec, black.nodes, etc.) loaded on everyimport typeagentbut only used in two cold formatting pathsblack.format_str()is called in two places:create_context_prompt()inknowpro/answers.py— formats debug context for LLM promptsformat_code()inaitools/utils.py— developer pretty-print utilityNeither runs during normal library operation. Moving the import inside each function eliminates ~78ms of transitive module loading from the import chain.
Benchmark
Azure Standard_D2s_v5 — 2 vCPU, 8 GiB RAM, Python 3.13
Import Time (hyperfine, warmup 5, min-runs 30)
import typeagentOffline E2E Test Suite (hyperfine, warmup 2, min-runs 10)
Generated by codeflash optimization agent
Reproduce the benchmark locally
Test plan
uv run pytest)python -X importtimeconfirms black no longer in import chain