Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌿 Fern Regeneration -- November 7, 2023 #99

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ src
.fernignore
.prettierrc.yml
tsconfig.json
yarn.lock
banner.png
yarn.lock
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cohere-ai",
"version": "7.1.1",
"version": "7.2.0",
"private": false,
"repository": "https://github.com/cohere-ai/cohere-typescript",
"main": "./index.js",
Expand All @@ -22,4 +22,4 @@
"prettier": "2.7.1",
"typescript": "4.6.4"
}
}
}
68 changes: 12 additions & 56 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as Cohere from "./api";
import * as serializers from "./serialization";
import urlJoin from "url-join";
import * as errors from "./errors";
import { Stream } from "core/streaming-fetcher/StreamingFetcher";

export declare namespace CohereClient {
interface Options {
Expand Down Expand Up @@ -43,7 +42,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.0.0",
"X-Fern-SDK-Version": "7.2.0",
},
contentType: "application/json",
body: await serializers.GenerateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -110,7 +109,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.0.0",
"X-Fern-SDK-Version": "7.2.0",
},
contentType: "application/json",
body: await serializers.EmbedRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -174,7 +173,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.0.0",
"X-Fern-SDK-Version": "7.2.0",
},
contentType: "application/json",
body: await serializers.ClassifyRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -224,10 +223,7 @@ export class CohereClient {
* If you have questions or require support, we're here to help! Reach out to your Cohere partner to enable access to this API.
*
*/
public async chat(
request: Cohere.ChatRequest,
requestOptions?: CohereClient.RequestOptions
): Promise<Cohere.NonStreamedChatResponse> {
public async chat(request: Cohere.ChatRequest, requestOptions?: CohereClient.RequestOptions): Promise<void> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.CohereEnvironment.Production,
Expand All @@ -238,22 +234,14 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.0.0",
"X-Fern-SDK-Version": "7.2.0",
},
contentType: "application/json",
body: {
...(await serializers.ChatRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" })),
stream: false,
},
body: await serializers.ChatRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
});
if (_response.ok) {
return await serializers.NonStreamedChatResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
return;
}

if (_response.error.reason === "status-code") {
Expand Down Expand Up @@ -297,7 +285,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.0.0",
"X-Fern-SDK-Version": "7.2.0",
},
contentType: "application/json",
body: await serializers.TokenizeRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -358,7 +346,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.0.0",
"X-Fern-SDK-Version": "7.2.0",
},
contentType: "application/json",
body: await serializers.DetokenizeRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -412,7 +400,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.0.0",
"X-Fern-SDK-Version": "7.2.0",
},
contentType: "application/json",
body: await serializers.DetectLanguageRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -466,7 +454,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.0.0",
"X-Fern-SDK-Version": "7.2.0",
},
contentType: "application/json",
body: await serializers.SummarizeRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -520,7 +508,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.0.0",
"X-Fern-SDK-Version": "7.2.0",
},
contentType: "application/json",
body: await serializers.RerankRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -557,38 +545,6 @@ export class CohereClient {
}
}

public async chatStream(
request: Cohere.ChatRequest,
requestOptions?: CohereClient.RequestOptions
): Promise<Stream<Cohere.StreamedChatResponse>> {
return await core.streamingFetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.CohereEnvironment.Production,
"v1/chat"
),
method: "POST",
headers: {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.0.0",
},
body: {
...(await serializers.ChatRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" })),
stream: true,
},
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
parse: async (data) => {
return await serializers.StreamedChatResponse.parseOrThrow(data, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
},
});
}

protected async _getAuthorizationHeader() {
return `Bearer ${await core.Supplier.get(this._options.token)}`;
}
Expand Down
23 changes: 20 additions & 3 deletions src/api/client/requests/EmbedRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,31 @@ export interface EmbedRequest {
/** An array of strings for the model to embed. Maximum number of texts per call is `96`. We recommend reducing the length of each text to be under `512` tokens for optimal quality. */
texts: string[];
/**
* Defaults to embed-english-v2.0
*
* The identifier of the model. Smaller "light" models are faster, while larger models will perform better. [Custom models](/docs/training-custom-models) can also be supplied with their full ID.
*
* Available models and corresponding embedding dimensions:
* * `embed-english-v2.0` (default) 4096
* * `embed-english-light-v2.0` 1024
* * `embed-multilingual-v2.0` 768
*
* * `embed-english-v3.0` 1024
* * `embed-multilingual-v3.0` 1024
* * `embed-english-light-v3.0` 384
* * `embed-multilingual-light-v3.0` 384
*
* * `embed-english-v2.0` 4096
* * `embed-english-light-v2.0` 1024
* * `embed-multilingual-v2.0` 768
*/
model?: string;
/**
* Specifies the type of input you're giving to the model. Not required for older versions of the embedding models (i.e. anything lower than v3), but is required for more recent versions (i.e. anything bigger than v2).
*
* * `"search_document"`: Use this when you encode documents for embeddings that you store in a vector database for search use-cases.
* * `"search_query"`: Use this when you query your vector DB to find relevant documents.
* * `"classification"`: Use this when you use the embeddings as an input to a text classifier.
* * `"clustering"`: Use this when you want to cluster the embeddings.
*/
inputType?: string;
/**
* One of `NONE|START|END` to specify how the API will handle inputs longer than the maximum token length.
*
Expand Down
3 changes: 2 additions & 1 deletion src/api/client/requests/GenerateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export interface GenerateRequest {
stream?: boolean;
/**
* The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations.
* Defaults to `20`. See [BPE Tokens](/bpe-tokens-wiki) for more details.
*
* This parameter is off by default, and if it's not specified, the model will continue generating until it emits an EOS completion token. See [BPE Tokens](/bpe-tokens-wiki) for more details.
*
* Can only be set to `0` if `return_likelihoods` is set to `ALL` to get the likelihood of the prompt.
*
Expand Down
1 change: 0 additions & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./fetcher";
export * from "./streaming-fetcher";
export * from "./auth";
export * as serialization from "./schemas";
90 changes: 0 additions & 90 deletions src/core/streaming-fetcher/StreamingFetcher.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/core/streaming-fetcher/getHeader.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/core/streaming-fetcher/index.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/serialization/client/requests/EmbedRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export const EmbedRequest: core.serialization.Schema<serializers.EmbedRequest.Ra
core.serialization.object({
texts: core.serialization.list(core.serialization.string()),
model: core.serialization.string().optional(),
inputType: core.serialization.property("input_type", core.serialization.string().optional()),
truncate: core.serialization.lazy(async () => (await import("../..")).EmbedRequestTruncate).optional(),
});

export declare namespace EmbedRequest {
interface Raw {
texts: string[];
model?: string | null;
input_type?: string | null;
truncate?: serializers.EmbedRequestTruncate.Raw | null;
}
}