Skip to content
Draft
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
105 changes: 105 additions & 0 deletions src/api/resources/facts/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,111 @@ export class Facts {
}
}

/**
* Extract facts from provided text, without storing them.
*
* @param {Corti.FactsExtractRequest} request
* @param {Facts.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Corti.GatewayTimeoutError}
*
* @example
* await client.facts.extract({
* context: [{
* type: "text",
* text: "text"
* }],
* outputLanguage: "outputLanguage"
* })
*/
public extract(
request: Corti.FactsExtractRequest,
requestOptions?: Facts.RequestOptions,
): core.HttpResponsePromise<Corti.FactsExtractResponse> {
return core.HttpResponsePromise.fromPromise(this.__extract(request, requestOptions));
}

private async __extract(
request: Corti.FactsExtractRequest,
requestOptions?: Facts.RequestOptions,
): Promise<core.WithRawResponse<Corti.FactsExtractResponse>> {
const _response = await core.fetcher({
url: core.url.join(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)).base,
"tools/extract-facts",
),
method: "POST",
headers: mergeHeaders(
this._options?.headers,
mergeOnlyDefinedHeaders({
Authorization: await this._getAuthorizationHeader(),
"Tenant-Name": requestOptions?.tenantName,
}),
requestOptions?.headers,
),
contentType: "application/json",
requestType: "json",
body: serializers.FactsExtractRequest.jsonOrThrow(request, {
unrecognizedObjectKeys: "strip",
omitUndefined: true,
}),
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return {
data: serializers.FactsExtractResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
rawResponse: _response.rawResponse,
};
}

if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 504:
throw new Corti.GatewayTimeoutError(
serializers.ErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
default:
throw new errors.CortiError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}

switch (_response.error.reason) {
case "non-json":
throw new errors.CortiError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
rawResponse: _response.rawResponse,
});
case "timeout":
throw new errors.CortiTimeoutError("Timeout exceeded when calling POST /tools/extract-facts.");
case "unknown":
throw new errors.CortiError({
message: _response.error.errorMessage,
rawResponse: _response.rawResponse,
});
}
}

protected async _getAuthorizationHeader(): Promise<string | undefined> {
const bearer = await core.Supplier.get(this._options.token);
if (bearer != null) {
Expand Down
21 changes: 21 additions & 0 deletions src/api/resources/facts/client/requests/FactsExtractRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as Corti from "../../../../index.js";

/**
* @example
* {
* context: [{
* type: "text",
* text: "text"
* }],
* outputLanguage: "outputLanguage"
* }
*/
export interface FactsExtractRequest {
context: Corti.CommonTextContext[];
/** The desired output language code for extracted facts. Check [languages page](/about/languages) for more. */
outputLanguage: string;
}
1 change: 1 addition & 0 deletions src/api/resources/facts/client/requests/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { type FactsCreateRequest } from "./FactsCreateRequest.js";
export { type FactsBatchUpdateRequest } from "./FactsBatchUpdateRequest.js";
export { type FactsUpdateRequest } from "./FactsUpdateRequest.js";
export { type FactsExtractRequest } from "./FactsExtractRequest.js";
2 changes: 1 addition & 1 deletion src/api/resources/transcripts/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class Transcripts {
}

/**
* Create a transcript from audio files uploaded, via `/recordings` endpoint, to the interaction.<br/><Note>If the asynchronous transcript processing does not complete before the request times out, a location header will be included in the response.<br/><br/>The client can poll the Get Transcript endpoint (`GET /interactions/{id}/transcripts/{transcriptId}`) to receive the final transcript.</Note>
* Create a transcript from an audio file attached, via `/recordings` endpoint, to the interaction.<br/><Note>Each interaction may have more than one audio file and transcript associated with it. While audio files up to 60min in total duration, or 150MB in total size, may be attached to an interaction, synchronous processing is only supported for audio files less than ~2min in duration.<br/><br/>If an audio file takes longer to transcribe than the 25sec synchronous processing timeout, then it will continue to process asynchronously. In this scenario, an empty transcript will be returned with a location header that can be used to retrieve the final transcript.<br/><br/>The client can poll the Get Transcript endpoint (`GET /interactions/{id}/transcripts/{transcriptId}/status`) for transcript status changes:<br/>- `200 OK` with the status `processing` or `complete` as the payload<br/>- `404 Not Found` if the `interactionId` or `transcriptId` are invalid<br/><br/>The completed transcript can be retrieved via the Get Transcript endpoint (`GET /interactions/{id}/transcripts/{transcriptId}/`.</Note>
*
* @param {Corti.Uuid} id - The unique identifier of the interaction. Must be a valid UUID.
* @param {Corti.TranscriptsCreateRequest} request
Expand Down
10 changes: 10 additions & 0 deletions src/api/types/CommonTextContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

export interface CommonTextContext {
/** The type of context, always "text" in this context. */
type: "text";
/** A text string to be used as input to the model. */
text: string;
}
10 changes: 10 additions & 0 deletions src/api/types/CommonUsage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

/**
* Credits consumed for this request.
*/
export interface CommonUsage {
credits: number;
}
7 changes: 0 additions & 7 deletions src/api/types/CommonUsageInfo.ts

This file was deleted.

20 changes: 3 additions & 17 deletions src/api/types/DocumentsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@
import * as Corti from "../index.js";

export type DocumentsContext =
| Corti.DocumentsContext.Facts
| Corti.DocumentsContext.Transcript
| Corti.DocumentsContext.String;

export namespace DocumentsContext {
export interface Facts extends Corti.DocumentsContextWithFacts {
type: "facts";
}

export interface Transcript extends Corti.DocumentsContextWithTranscript {
type: "transcript";
}

export interface String extends Corti.DocumentsContextWithString {
type: "string";
}
}
| Corti.DocumentsContextWithFacts
| Corti.DocumentsContextWithTranscript
| Corti.DocumentsContextWithString;
2 changes: 2 additions & 0 deletions src/api/types/DocumentsContextWithFacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import * as Corti from "../index.js";

export interface DocumentsContextWithFacts {
/** The type of context data that will be used in the request: `Facts`, `Transcript`, or `String`. */
type: "facts";
/** An array of facts. */
data: Corti.FactsContext[];
}
2 changes: 2 additions & 0 deletions src/api/types/DocumentsContextWithString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/

export interface DocumentsContextWithString {
/** The type of context data that will be used in the request: `Facts`, `Transcript`, or `String`. */
type: "string";
/** String data can include any text to be reasoned over for document generation: Transcript text, facts, or other narrative information. */
data: string;
}
2 changes: 2 additions & 0 deletions src/api/types/DocumentsContextWithTranscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import * as Corti from "../index.js";

export interface DocumentsContextWithTranscript {
/** The type of context data that will be used in the request: `Facts`, `Transcript`, or `String`. */
type: "transcript";
/** Transcript object can accept the full transcript in one string, or individual transcript segments. */
data: Corti.CommonTranscriptRequest;
}
2 changes: 1 addition & 1 deletion src/api/types/DocumentsGetResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export interface DocumentsGetResponse {
updatedAt: Date;
/** The language in which the document will be generated. Check https://docs.corti.ai/about/languages for more. */
outputLanguage: string;
usageInfo: Corti.CommonUsageInfo;
usage?: Corti.CommonUsage;
}
13 changes: 13 additions & 0 deletions src/api/types/FactsExtractResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as Corti from "../index.js";

export interface FactsExtractResponse {
/** List of extracted facts based on the provided input context. */
facts: Corti.FactsExtractResponseFactsItem[];
/** The language locale of the output. */
outputLanguage: string;
usage?: Corti.CommonUsage;
}
10 changes: 10 additions & 0 deletions src/api/types/FactsExtractResponseFactsItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

export interface FactsExtractResponseFactsItem {
/** The fact group key the fact belongs to. */
group: string;
/** An individual, atomic fact. */
value: string;
}
2 changes: 1 addition & 1 deletion src/api/types/TranscriptsResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export interface TranscriptsResponse {
metadata: Corti.TranscriptsMetadata;
/** An array of transcripts. */
transcripts?: Corti.CommonTranscriptResponse[] | null;
usageInfo: Corti.CommonUsageInfo;
usage?: Corti.CommonUsage;
}
5 changes: 4 additions & 1 deletion src/api/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from "./DocumentsCreateRequest.js";
export * from "./DocumentsCreateRequestWithTemplateKey.js";
export * from "./DocumentsCreateRequestWithTemplate.js";
export * from "./DocumentsSectionInput.js";
export * from "./CommonTextContext.js";
export * from "./FactsCreateInput.js";
export * from "./FactsBatchUpdateInput.js";
export * from "./TranscriptsParticipant.js";
Expand All @@ -34,6 +35,8 @@ export * from "./FactsCreateResponse.js";
export * from "./FactsListResponse.js";
export * from "./FactsBatchUpdateResponse.js";
export * from "./FactsBatchUpdateItem.js";
export * from "./FactsExtractResponseFactsItem.js";
export * from "./FactsExtractResponse.js";
export * from "./InteractionsGetResponse.js";
export * from "./InteractionsCreateResponse.js";
export * from "./InteractionsListResponse.js";
Expand All @@ -51,7 +54,7 @@ export * from "./TemplatesSectionSorted.js";
export * from "./CommonTranscriptRequest.js";
export * from "./CommonTranscriptResponse.js";
export * from "./Uuid.js";
export * from "./CommonUsageInfo.js";
export * from "./CommonUsage.js";
export * from "./InteractionsEncounterStatusEnum.js";
export * from "./InteractionsEncounterTypeEnum.js";
export * from "./InteractionsGenderEnum.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as serializers from "../../../../index.js";
import * as Corti from "../../../../../api/index.js";
import * as core from "../../../../../core/index.js";
import { CommonTextContext } from "../../../../types/CommonTextContext.js";

export const FactsExtractRequest: core.serialization.Schema<
serializers.FactsExtractRequest.Raw,
Corti.FactsExtractRequest
> = core.serialization.object({
context: core.serialization.list(CommonTextContext),
outputLanguage: core.serialization.string(),
});

export declare namespace FactsExtractRequest {
export interface Raw {
context: CommonTextContext.Raw[];
outputLanguage: string;
}
}
1 change: 1 addition & 0 deletions src/serialization/resources/facts/client/requests/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { FactsCreateRequest } from "./FactsCreateRequest.js";
export { FactsBatchUpdateRequest } from "./FactsBatchUpdateRequest.js";
export { FactsUpdateRequest } from "./FactsUpdateRequest.js";
export { FactsExtractRequest } from "./FactsExtractRequest.js";
22 changes: 22 additions & 0 deletions src/serialization/types/CommonTextContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as serializers from "../index.js";
import * as Corti from "../../api/index.js";
import * as core from "../../core/index.js";

export const CommonTextContext: core.serialization.ObjectSchema<
serializers.CommonTextContext.Raw,
Corti.CommonTextContext
> = core.serialization.object({
type: core.serialization.stringLiteral("text"),
text: core.serialization.string(),
});

export declare namespace CommonTextContext {
export interface Raw {
type: "text";
text: string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import * as serializers from "../index.js";
import * as Corti from "../../api/index.js";
import * as core from "../../core/index.js";

export const CommonUsageInfo: core.serialization.ObjectSchema<serializers.CommonUsageInfo.Raw, Corti.CommonUsageInfo> =
export const CommonUsage: core.serialization.ObjectSchema<serializers.CommonUsage.Raw, Corti.CommonUsage> =
core.serialization.object({
creditsConsumed: core.serialization.number(),
credits: core.serialization.number(),
});

export declare namespace CommonUsageInfo {
export declare namespace CommonUsage {
export interface Raw {
creditsConsumed: number;
credits: number;
}
}
Loading
Loading