-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb98f0a
commit 3068c78
Showing
5 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CohereClient } from "./Client"; | ||
|
||
export class CustomClient extends CohereClient { | ||
constructor(protected readonly _options: CohereClient.Options = {}) { | ||
try { | ||
// if url ends with /v1, drop it for back compat | ||
const match = /\/v1\/?$/ | ||
const fixed = _options.environment?.toString().replace(match, ""); | ||
if (fixed !== _options.environment?.toString()) { | ||
_options.environment = fixed | ||
} | ||
} catch { } | ||
|
||
super(_options) | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`v1 back compat https://api.cohere.com/ 1`] = `"https://api.cohere.com/v1/chat"`; | ||
|
||
exports[`v1 back compat https://api.cohere.com/v1 1`] = `"https://api.cohere.com/v1/chat"`; | ||
|
||
exports[`v1 back compat https://api.cohere.com/v1/ 1`] = `"https://api.cohere.com/v1/chat"`; | ||
|
||
exports[`v1 back compat https://api.cohere.com/v1// 1`] = `"https://api.cohere.com/v1/v1/chat"`; | ||
|
||
exports[`v1 back compat https://api.cohere.com/v2 1`] = `"https://api.cohere.com/v2/v1/chat"`; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, test } from "@jest/globals"; | ||
import { CohereClient } from "../index"; | ||
|
||
describe("v1 back compat", () => { | ||
test.each([ | ||
"https://api.cohere.com/", | ||
"https://api.cohere.com/v1", | ||
"https://api.cohere.com/v1/", | ||
"https://api.cohere.com/v1//", | ||
"https://api.cohere.com/v2", | ||
])("%s", async (environment) => { | ||
let url = "" | ||
|
||
const cohere = new CohereClient({ | ||
token: "token", | ||
environment, | ||
fetcher: (async (opts) => { | ||
url = opts.url | ||
throw "we're done" | ||
}) | ||
}) | ||
|
||
try { | ||
await cohere.chat({ message: "hello" }) | ||
} catch { } | ||
|
||
expect(url).toMatchSnapshot() | ||
}) | ||
}); |
This file contains 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