Skip to content

Commit

Permalink
Release 7.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Dec 13, 2023
1 parent f86229c commit 4f2d9b1
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 170 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cohere-ai",
"version": "7.6.0",
"version": "7.6.1",
"private": false,
"repository": "https://github.com/cohere-ai/cohere-typescript",
"main": "./index.js",
Expand All @@ -12,13 +12,15 @@
},
"dependencies": {
"url-join": "4.0.1",
"@types/url-join": "4.0.1",
"axios": "0.27.2",
"form-data": "4.0.0",
"node-fetch": "2.7.0",
"qs": "6.11.2",
"@types/qs": "6.9.8",
"js-base64": "3.7.2"
},
"devDependencies": {
"@types/url-join": "4.0.1",
"@types/qs": "6.9.8",
"@types/node-fetch": "2.6.9",
"@types/node": "17.0.33",
"prettier": "2.7.1",
"typescript": "4.6.4"
Expand Down
79 changes: 52 additions & 27 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as core from "./core";
import * as Cohere from "./api";
import * as serializers from "./serialization";
import urlJoin from "url-join";
import * as stream from "stream";
import * as errors from "./errors";
import { Connectors } from "./api/resources/connectors/client/Client";

Expand All @@ -27,15 +28,14 @@ export class CohereClient {

/**
* The `chat` endpoint allows users to have conversations with a Large Language Model (LLM) from Cohere. Users can send messages as part of a persisted conversation using the `conversation_id` parameter, or they can pass in their own conversation history using the `chat_history` parameter.
* The endpoint features additional parameters such as `connectors` and `documents` that enable conversations enriched by external knowledge. We call this "Retrieval Augmented Generation", or "RAG".
* If you have questions or require support, we're here to help! Reach out to your Cohere partner to enable access to this API.
* The endpoint features additional parameters such as [connectors](https://docs.cohere.com/docs/connectors) and `documents` that enable conversations enriched by external knowledge. We call this "Retrieval Augmented Generation", or "RAG".
*
*/
public async chatStream(
request: Cohere.ChatStreamRequest,
requestOptions?: CohereClient.RequestOptions
): Promise<core.Stream<Cohere.StreamedChatResponse>> {
const _response = await core.streamingFetcher({
const _response = await core.fetcher<stream.Readable>({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.CohereEnvironment.Production,
"v1/chat"
Expand All @@ -45,33 +45,58 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: {
...(await serializers.ChatStreamRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" })),
stream: true,
},
responseType: "streaming",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
return new core.Stream({
stream: _response.data,
terminator: "\n",
parse: async (data) => {
return await serializers.StreamedChatResponse.parseOrThrow(data, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
if (_response.ok) {
return new core.Stream({
stream: _response.body,
terminator: "\n",
parse: async (data) => {
return await serializers.StreamedChatResponse.parseOrThrow(data, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
});
},
});
}

if (_response.error.reason === "status-code") {
throw new errors.CohereError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}

switch (_response.error.reason) {
case "non-json":
throw new errors.CohereError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
},
});
case "timeout":
throw new errors.CohereTimeoutError();
case "unknown":
throw new errors.CohereError({
message: _response.error.errorMessage,
});
}
}

/**
* The `chat` endpoint allows users to have conversations with a Large Language Model (LLM) from Cohere. Users can send messages as part of a persisted conversation using the `conversation_id` parameter, or they can pass in their own conversation history using the `chat_history` parameter.
* The endpoint features additional parameters such as `connectors` and `documents` that enable conversations enriched by external knowledge. We call this "Retrieval Augmented Generation", or "RAG".
* If you have questions or require support, we're here to help! Reach out to your Cohere partner to enable access to this API.
* The endpoint features additional parameters such as [connectors](https://docs.cohere.com/docs/connectors) and `documents` that enable conversations enriched by external knowledge. We call this "Retrieval Augmented Generation", or "RAG".
*
*/
public async chat(
Expand All @@ -88,7 +113,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: {
Expand Down Expand Up @@ -149,7 +174,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: await serializers.GenerateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -218,7 +243,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: await serializers.EmbedRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -281,7 +306,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: await serializers.RerankRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -340,7 +365,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: await serializers.ClassifyRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -408,7 +433,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: await serializers.DetectLanguageRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -464,7 +489,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: await serializers.SummarizeRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -522,7 +547,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: await serializers.TokenizeRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -585,7 +610,7 @@ export class CohereClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: await serializers.DetokenizeRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down
2 changes: 1 addition & 1 deletion src/api/client/requests/ChatRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface ChatRequest {
*/
promptTruncation?: Cohere.ChatRequestPromptTruncation;
/**
* Accepts `{"id": "web-search"}`, and/or the `"id"` for a custom connector, if you've made one.
* Accepts `{"id": "web-search"}`, and/or the `"id"` for a custom [connector](https://docs.cohere.com/docs/connectors), if you've [created](https://docs.cohere.com/docs/creating-and-deploying-a-connector) one.
* When specified, the model's reply will be enriched with information found by quering each of the connectors (RAG).
*
*/
Expand Down
2 changes: 1 addition & 1 deletion src/api/client/requests/ChatStreamRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface ChatStreamRequest {
*/
promptTruncation?: Cohere.ChatStreamRequestPromptTruncation;
/**
* Accepts `{"id": "web-search"}`, and/or the `"id"` for a custom connector, if you've made one.
* Accepts `{"id": "web-search"}`, and/or the `"id"` for a custom [connector](https://docs.cohere.com/docs/connectors), if you've [created](https://docs.cohere.com/docs/creating-and-deploying-a-connector) one.
* When specified, the model's reply will be enriched with information found by quering each of the connectors (RAG).
*
*/
Expand Down
12 changes: 6 additions & 6 deletions src/api/resources/connectors/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Connectors {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
queryParameters: _queryParams,
Expand Down Expand Up @@ -126,7 +126,7 @@ export class Connectors {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: await serializers.CreateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -191,7 +191,7 @@ export class Connectors {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
Expand Down Expand Up @@ -259,7 +259,7 @@ export class Connectors {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
Expand Down Expand Up @@ -330,7 +330,7 @@ export class Connectors {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
body: await serializers.UpdateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -403,7 +403,7 @@ export class Connectors {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "cohere-ai",
"X-Fern-SDK-Version": "7.6.0",
"X-Fern-SDK-Version": "7.6.1",
},
contentType: "application/json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
Expand Down
1 change: 1 addition & 0 deletions src/core/fetcher/APIResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type APIResponse<Success, Failure> = SuccessfulResponse<Success> | Failed
export interface SuccessfulResponse<T> {
ok: true;
body: T;
headers?: Record<string, any>;
}

export interface FailedResponse<T> {
Expand Down
Loading

0 comments on commit 4f2d9b1

Please sign in to comment.