fix: bind ClientV2 legacy methods to v1 client - #297
Open
euisuh wants to merge 1 commit into
Open
Conversation
CohereClientV2 exposes legacy v1 endpoints through an internal CohereClient, so bind those methods to that client instance instead of the V2 client. Add regression coverage for generate routing to the v1 endpoint.
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
Fix
CohereClientV2legacy v1 endpoint methods so they are bound to the internalCohereClientinstance instead of theV2Clientinstance.CohereClientV2exposes v2 methods throughV2Client, but also keeps legacy v1 methods such asgenerate,classify,summarize,tokenize,detokenize, andcheckApiKeyby delegating to an internal v1CohereClient. Those delegated methods need the v1 client asthis; binding them toclientV2can break legacy calls because the v2 client does not own the v1 request helpers/state.This adds regression coverage that
CohereClientV2.generate()routes through the v1/v1/generateendpoint and sends the expected request body.Test Plan
pnpm exec vitest src/test/client.test.ts --runpnpm buildpnpm check src/ClientV2.ts src/test/client.test.tsgit diff --checkNote
Medium Risk
Fixes runtime behavior for all legacy v1 methods on
CohereClientV2; incorrect binding could have caused subtle failures in production SDK usage.Overview
Fixes incorrect
thisbinding onCohereClientV2legacy v1 APIs (generate,generateStream,classify,summarize,tokenize,detokenize,checkApiKey). Those methods were bound to the internalV2Clientinstead of the v1CohereClient, which could break calls that rely on v1 request helpers and routing.Legacy calls now delegate to the v1 client with the correct binding so requests hit v1 paths (e.g.
/v1/generate) as intended.Adds a regression test that
CohereClientV2.generate()targetshttps://api.cohere.com/v1/generatewith the expected body. Minor cleanup: type-onlycoreimport and formatting inClientV2.ts/ existing tests.Reviewed by Cursor Bugbot for commit dd4ada0. Bugbot is set up for automated code reviews on this repo. Configure here.