Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 18
configured_endpoints: 21
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-1cc5cdee043b0cdaf8a02e3f4e2799f17a4b88dd843cf31eea423843f5bbd4b8.yml
30 changes: 30 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,33 @@ Methods:
- <code title="get /v1/files/{file_id}/download">client.files.<a href="./src/resources/files.ts">download</a>(fileId) -> Response</code>
- <code title="post /v1/files/retry">client.files.<a href="./src/resources/files.ts">retry</a>({ ...params }) -> FileRetryResponse</code>
- <code title="post /v1/files">client.files.<a href="./src/resources/files.ts">upload</a>({ ...params }) -> File</code>

# Tools

Types:

- <code><a href="./src/resources/tools/tools.ts">ToolContextAwareSplittingResponse</a></code>

Methods:

- <code title="post /v1/tools/context-aware-splitting">client.tools.<a href="./src/resources/tools/tools.ts">contextAwareSplitting</a>({ ...params }) -> ToolContextAwareSplittingResponse</code>

## Medical

Types:

- <code><a href="./src/resources/tools/medical.ts">MedicalCreateResponse</a></code>

Methods:

- <code title="post /v1/tools/comprehend/medical">client.tools.medical.<a href="./src/resources/tools/medical.ts">create</a>({ ...params }) -> MedicalCreateResponse</code>

## PdfParser

Types:

- <code><a href="./src/resources/tools/pdf-parser.ts">PdfParserParseResponse</a></code>

Methods:

- <code title="post /v1/tools/pdf-parser/{file_id}">client.tools.pdfParser.<a href="./src/resources/tools/pdf-parser.ts">parse</a>(fileId, { ...params }) -> PdfParserParseResponse</code>
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class Writer extends Core.APIClient {
models: API.Models = new API.Models(this);
graphs: API.Graphs = new API.Graphs(this);
files: API.Files = new API.Files(this);
tools: API.Tools = new API.Tools(this);

protected override defaultQuery(): Core.DefaultQuery | undefined {
return this._options.defaultQuery;
Expand Down Expand Up @@ -232,6 +233,10 @@ export namespace Writer {
export import FileListParams = API.FileListParams;
export import FileRetryParams = API.FileRetryParams;
export import FileUploadParams = API.FileUploadParams;

export import Tools = API.Tools;
export import ToolContextAwareSplittingResponse = API.ToolContextAwareSplittingResponse;
export import ToolContextAwareSplittingParams = API.ToolContextAwareSplittingParams;
}

export default Writer;
1 change: 1 addition & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ export {
Graphs,
} from './graphs';
export { ModelListResponse, Models } from './models';
export { ToolContextAwareSplittingResponse, ToolContextAwareSplittingParams, Tools } from './tools/tools';
5 changes: 5 additions & 0 deletions src/resources/tools/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export { MedicalCreateResponse, MedicalCreateParams, Medical } from './medical';
export { PdfParserParseResponse, PdfParserParseParams, PdfParser } from './pdf-parser';
export { ToolContextAwareSplittingResponse, ToolContextAwareSplittingParams, Tools } from './tools';
116 changes: 116 additions & 0 deletions src/resources/tools/medical.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
import * as Core from '../../core';
import * as MedicalAPI from './medical';

export class Medical extends APIResource {
/**
* Create a completion using Palmyra medical model.
*/
create(body: MedicalCreateParams, options?: Core.RequestOptions): Core.APIPromise<MedicalCreateResponse> {
return this._client.post('/v1/tools/comprehend/medical', { body, ...options });
}
}

export interface MedicalCreateResponse {
/**
* An array of medical entities extracted from the input text.
*/
entities: Array<MedicalCreateResponse.Entity>;
}

export namespace MedicalCreateResponse {
export interface Entity {
attributes: Array<Entity.Attribute>;

begin_offset: number;

category: string;

concepts: Array<Entity.Concept>;

end_offset: number;

score: number;

text: string;

traits: Array<Entity.Trait>;

type: string;
}

export namespace Entity {
export interface Attribute {
begin_offset: number;

concepts: Array<Attribute.Concept>;

end_offset: number;

relationship_score: number;

score: number;

text: string;

traits: Array<Attribute.Trait>;

type: string;

category?: string;

relationship_type?: string;
}

export namespace Attribute {
export interface Concept {
code: string;

description: string;

score: number;
}

export interface Trait {
name: string;

score: number;
}
}

export interface Concept {
code: string;

description: string;

score: number;
}

export interface Trait {
name: string;

score: number;
}
}
}

export interface MedicalCreateParams {
/**
* The text to be analyzed.
*/
content: string;

/**
* The structure of the response to be returned. `Entities` returns medical
* entities, `RxNorm` returns medication information, `ICD-10-CM` returns diagnosis
* codes, and `SNOMED CT` returns medical concepts.
*/
response_type: 'Entities' | 'RxNorm' | 'ICD-10-CM' | 'SNOMED CT';
}

export namespace Medical {
export import MedicalCreateResponse = MedicalAPI.MedicalCreateResponse;
export import MedicalCreateParams = MedicalAPI.MedicalCreateParams;
}
37 changes: 37 additions & 0 deletions src/resources/tools/pdf-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
import * as Core from '../../core';
import * as PdfParserAPI from './pdf-parser';

export class PdfParser extends APIResource {
/**
* Parse PDF to other formats.
*/
parse(
fileId: string,
body: PdfParserParseParams,
options?: Core.RequestOptions,
): Core.APIPromise<PdfParserParseResponse> {
return this._client.post(`/v1/tools/pdf-parser/${fileId}`, { body, ...options });
}
}

export interface PdfParserParseResponse {
/**
* The extracted content from the PDF file, converted to the specified format.
*/
content: string;
}

export interface PdfParserParseParams {
/**
* The format into which the PDF content should be converted.
*/
format: 'text' | 'markdown';
}

export namespace PdfParser {
export import PdfParserParseResponse = PdfParserAPI.PdfParserParseResponse;
export import PdfParserParseParams = PdfParserAPI.PdfParserParseParams;
}
56 changes: 56 additions & 0 deletions src/resources/tools/tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
import * as Core from '../../core';
import * as ToolsAPI from './tools';
import * as MedicalAPI from './medical';
import * as PdfParserAPI from './pdf-parser';

export class Tools extends APIResource {
medical: MedicalAPI.Medical = new MedicalAPI.Medical(this._client);
pdfParser: PdfParserAPI.PdfParser = new PdfParserAPI.PdfParser(this._client);

/**
* Splits a long block of text (maximum 4000 words) into smaller chunks while
* preserving the semantic meaning of the text and context between the chunks.
*/
contextAwareSplitting(
body: ToolContextAwareSplittingParams,
options?: Core.RequestOptions,
): Core.APIPromise<ToolContextAwareSplittingResponse> {
return this._client.post('/v1/tools/context-aware-splitting', { body, ...options });
}
}

export interface ToolContextAwareSplittingResponse {
/**
* An array of text chunks generated by splitting the input text based on the
* specified strategy.
*/
chunks: Array<string>;
}

export interface ToolContextAwareSplittingParams {
/**
* The strategy to be used for splitting the text into chunks. `llm_split` uses the
* language model to split the text, `fast_split` uses a fast heuristic-based
* approach, and `hybrid_split` combines both strategies.
*/
strategy: 'llm_split' | 'fast_split' | 'hybrid_split';

/**
* The text to be split into chunks.
*/
text: string;
}

export namespace Tools {
export import ToolContextAwareSplittingResponse = ToolsAPI.ToolContextAwareSplittingResponse;
export import ToolContextAwareSplittingParams = ToolsAPI.ToolContextAwareSplittingParams;
export import Medical = MedicalAPI.Medical;
export import MedicalCreateResponse = MedicalAPI.MedicalCreateResponse;
export import MedicalCreateParams = MedicalAPI.MedicalCreateParams;
export import PdfParser = PdfParserAPI.PdfParser;
export import PdfParserParseResponse = PdfParserAPI.PdfParserParseResponse;
export import PdfParserParseParams = PdfParserAPI.PdfParserParseParams;
}
26 changes: 26 additions & 0 deletions tests/api-resources/tools/medical.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Writer from 'writer-sdk';
import { Response } from 'node-fetch';

const client = new Writer({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource medical', () => {
test('create: only required params', async () => {
const responsePromise = client.tools.medical.create({ content: 'content', response_type: 'Entities' });
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('create: required and optional params', async () => {
const response = await client.tools.medical.create({ content: 'content', response_type: 'Entities' });
});
});
26 changes: 26 additions & 0 deletions tests/api-resources/tools/pdf-parser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Writer from 'writer-sdk';
import { Response } from 'node-fetch';

const client = new Writer({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource pdfParser', () => {
test('parse: only required params', async () => {
const responsePromise = client.tools.pdfParser.parse('file_id', { format: 'text' });
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('parse: required and optional params', async () => {
const response = await client.tools.pdfParser.parse('file_id', { format: 'text' });
});
});
26 changes: 26 additions & 0 deletions tests/api-resources/tools/tools.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Writer from 'writer-sdk';
import { Response } from 'node-fetch';

const client = new Writer({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource tools', () => {
test('contextAwareSplitting: only required params', async () => {
const responsePromise = client.tools.contextAwareSplitting({ strategy: 'llm_split', text: 'text' });
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('contextAwareSplitting: required and optional params', async () => {
const response = await client.tools.contextAwareSplitting({ strategy: 'llm_split', text: 'text' });
});
});