refactor(clients/lm): extract _common_prep and _rewrite_for_text_comp…#24
refactor(clients/lm): extract _common_prep and _rewrite_for_text_comp…#24isaacbmiller wants to merge 2 commits intomainfrom
Conversation
…letion Collapses boilerplate shared across the 6 litellm wrapper functions (chat/text/responses x sync/async). Also fixes alitellm_completion streaming to pass dspy-identifier-stamped headers into litellm.acompletion (previously passed None). Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Greptile SummaryThis PR collapses per-function boilerplate (dict copy, Confidence Score: 5/5Safe to merge — behavior is equivalent or strictly improved across all six wrappers. All six wrappers preserve existing behaviour; the only functional delta is the confirmed bug-fix for missing headers in async streaming. No new logic paths, no schema changes, no security concerns. All remaining findings are P2 at most. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[incoming request dict] --> B["_common_prep(request, cache)"]
B --> C["body = dict(request)\nbody.pop('rollout_id')"]
C --> D["headers = _add_dspy_identifier_to_headers(...)"]
D --> E["cache = cache or {no-cache defaults}"]
E --> F["returns (body, headers, cache)"]
F --> G{caller type}
G -- chat --> H["_get_stream_completion_fn(body, cache, sync, headers)"]
H -- stream set --> I["stream_completion()"]
H -- stream None --> J["litellm.completion / acompletion\n(cache, num_retries, headers, **body)"]
G -- text --> K["_rewrite_for_text_completion(body)"]
K --> L["body: model, api_key, api_base, prompt mutated in-place"]
L --> M["litellm.text_completion / atext_completion\n(cache, num_retries, headers, **body)"]
G -- responses --> N["_convert_chat_request_to_responses_request(body)"]
N --> O["litellm.responses / aresponses\n(cache, num_retries, headers, **body)"]
Reviews (2): Last reviewed commit: "refactor(clients/lm): make _rewrite_for_..." | Re-trigger Greptile |
Return None and drop the body = _rewrite_for_text_completion(body) pattern at call sites. body is already a fresh copy produced by _common_prep, so the previous dual mutation+return signature was misleading. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
|
@greptile |
…Collapses boilerplate shared across the 6 litellm wrapper functions (chat/text/responses x sync/async). Also fixes alitellm_completion streaming to pass dspy-identifier-stamped headers into litellm.acompletion (previously passed None).