Skip to content

feat: prefer outbound format equals to inbound format#1592

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
May 4, 2026
Merged

feat: prefer outbound format equals to inbound format#1592
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented May 3, 2026

Copy link
Copy Markdown
Owner

No description provided.

@greptile-apps

greptile-apps Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors endpoint format selection by renaming custom_endpoints.goselect_endpoints.go and updating SelectAPIFormatForRequestTypeSelectAPIFormat, which now accepts the full *llm.Request so it can prefer an outbound endpoint whose API format matches the inbound format (enabling transparent pass-through). Two new format maps (compactCapableAPIFormats, videoCapableAPIFormats) and their corresponding switch cases for RequestTypeCompact and RequestTypeVideo are also added, covering all seven RequestType values.

Confidence Score: 5/5

Safe to merge — the previously identified P1 concern about compact format routing is fully resolved by the new RequestTypeCompact handling, and all seven request types are now covered.

No P0 or P1 issues remain. The new SelectAPIFormat correctly separates compact requests (RequestTypeCompact → compactCapableAPIFormats) from chat requests (RequestTypeChat → chatCapableAPIFormats), resolving the earlier concern. All request types are accounted for in the switch, call sites are updated consistently, and test coverage is comprehensive.

No files require special attention.

Important Files Changed

Filename Overview
internal/server/orchestrator/select_endpoints.go Core change: renamed from custom_endpoints.go, adds preferred-format pass-through logic and new format maps for compact and video; all 7 RequestTypes now covered
internal/server/orchestrator/candidates.go Two call sites updated from SelectAPIFormatForRequestType(endpoints, req.RequestType) to SelectAPIFormat(endpoints, req); no logic change beyond threading the full request
internal/server/orchestrator/candidates_condition.go populateAPIFormat signature updated to accept *llm.Request; both call sites updated accordingly with correct nil guards already in place
internal/server/orchestrator/select_endpoints_test.go New test file replaces custom_endpoints_test.go; adds coverage for preferred-format matching, fallback, video, and compact request types
internal/server/orchestrator/custom_endpoints_test.go Deleted; superseded by select_endpoints_test.go with equivalent and extended coverage

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[SelectAPIFormat called\nwith endpoints + req] --> B{endpoints empty?}
    B -- yes --> C[return empty string]
    B -- no --> D[requestType = req.RequestType\npreferredFormat = req.APIFormat]
    D --> E{switch requestType}
    E -- RequestTypeChat --> F[allowed = chatCapableAPIFormats]
    E -- RequestTypeCompact --> G[allowed = compactCapableAPIFormats]
    E -- RequestTypeCompletion --> H[allowed = completionCapableAPIFormats]
    E -- RequestTypeEmbedding --> I[allowed = embeddingCapableAPIFormats]
    E -- RequestTypeImage --> J[allowed = imageCapableAPIFormats]
    E -- RequestTypeRerank --> K[allowed = rerankCapableAPIFormats]
    E -- RequestTypeVideo --> L[allowed = videoCapableAPIFormats]
    F & G & H & I & J & K & L --> M{allowed != nil?}
    M -- no --> P[return endpoints 0 .APIFormat]
    M -- yes --> N{preferredFormat != empty?}
    N -- yes --> O[Loop: find ep where\nallowed AND ep.APIFormat == preferredFormat]
    O -- found --> Q[return ep.APIFormat pref match]
    O -- not found --> R[Loop: find first ep in allowed]
    N -- no --> R
    R -- found --> S[return ep.APIFormat first capable]
    R -- not found --> P
Loading

Reviews (4): Last reviewed commit: "feat: prefer outbound format equals to i..." | Re-trigger Greptile

Comment thread internal/server/orchestrator/custom_endpoints.go Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a preferredFormat parameter to the API format selection logic, allowing the orchestrator to prioritize specific formats to enable pass-through functionality. These changes are applied across the candidate selection and population processes, with accompanying unit tests. Feedback was provided regarding a typo in a code comment and a suggestion to optimize the format selection logic into a single pass for better efficiency.

Comment thread internal/server/orchestrator/custom_endpoints.go Outdated
@looplj looplj force-pushed the dev-tmp branch 2 times, most recently from 45fd09c to 9aad4c4 Compare May 4, 2026 02:19
@looplj looplj merged commit 3a5f349 into unstable May 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant