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: 29
configured_endpoints: 30
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-57a138ff1e8940e627dd0108eb14c25bbeacd70e5f1106f8abd796cba6c51882.yml
11 changes: 11 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,14 @@ Types:
Methods:

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

# Vision

Types:

- <code><a href="./src/resources/vision.ts">VisionRequest</a></code>
- <code><a href="./src/resources/vision.ts">VisionResponse</a></code>

Methods:

- <code title="post /v1/vision">client.vision.<a href="./src/resources/vision.ts">analyzeImages</a>({ ...params }) -> VisionResponse</code>
10 changes: 10 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
QuestionResponseChunk,
} from './resources/graphs';
import { ModelListResponse, Models } from './resources/models';
import { Vision, VisionAnalyzeImagesParams, VisionRequest, VisionResponse } from './resources/vision';
import { readEnv } from './internal/utils/env';
import { formatRequestDetails, loggerFor } from './internal/utils/log';
import { isEmptyObj } from './internal/utils/values';
Expand Down Expand Up @@ -777,6 +778,7 @@ export class Writer {
graphs: API.Graphs = new API.Graphs(this);
files: API.Files = new API.Files(this);
tools: API.Tools = new API.Tools(this);
vision: API.Vision = new API.Vision(this);
}
Writer.Applications = Applications;
Writer.Chat = Chat;
Expand All @@ -785,6 +787,7 @@ Writer.Models = Models;
Writer.Graphs = Graphs;
Writer.Files = Files;
Writer.Tools = Tools;
Writer.Vision = Vision;
export declare namespace Writer {
export type RequestOptions = Opts.RequestOptions;

Expand Down Expand Up @@ -874,6 +877,13 @@ export declare namespace Writer {
type ToolParsePdfParams as ToolParsePdfParams,
};

export {
Vision as Vision,
type VisionRequest as VisionRequest,
type VisionResponse as VisionResponse,
type VisionAnalyzeImagesParams as VisionAnalyzeImagesParams,
};

export type ErrorMessage = API.ErrorMessage;
export type ErrorObject = API.ErrorObject;
export type FunctionDefinition = API.FunctionDefinition;
Expand Down
1 change: 1 addition & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ export {
type ToolContextAwareSplittingParams,
type ToolParsePdfParams,
} from './tools/tools';
export { Vision, type VisionRequest, type VisionResponse, type VisionAnalyzeImagesParams } from './vision';
109 changes: 109 additions & 0 deletions src/resources/vision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../resource';
import { APIPromise } from '../api-promise';
import { RequestOptions } from '../internal/request-options';

export class Vision extends APIResource {
/**
* Submit images and a prompt to generate an analysis of the images.
*/
analyzeImages(body: VisionAnalyzeImagesParams, options?: RequestOptions): APIPromise<VisionResponse> {
return this._client.post('/v1/vision', { body, ...options });
}
}

export interface VisionRequest {
/**
* The model to be used for image analysis. Currently only supports
* `palmyra-vision`.
*/
model: string;

/**
* The prompt to use for the image analysis. The prompt must include the name of
* each image variable, surrounded by double curly braces (`{{}}`). For example,
* `Describe the difference between the image {{image_1}} and the image {{image_2}}`.
*/
prompt: string;

variables: Array<VisionRequest.Variable>;
}

export namespace VisionRequest {
/**
* An array of file variables required for the analysis. The image files must be
* uploaded to the Writer platform before they can be used in a vision request.
* Learn how to upload files using the
* [Files API](/api-guides/api-reference/file-api/upload-files).
*/
export interface Variable {
/**
* The File ID of the image to be analyzed. The file must be uploaded to the Writer
* platform before it can be used in a vision request.
*/
file_id: string;

/**
* The name of the file variable. You must reference this name in the prompt with
* double curly braces (`{{}}`). For example,
* `Describe the difference between the image {{image_1}} and the image {{image_2}}`.
*/
name: string;
}
}

export interface VisionResponse {
/**
* The result of the image analysis.
*/
data: string;
}

export interface VisionAnalyzeImagesParams {
/**
* The model to be used for image analysis. Currently only supports
* `palmyra-vision`.
*/
model: string;

/**
* The prompt to use for the image analysis. The prompt must include the name of
* each image variable, surrounded by double curly braces (`{{}}`). For example,
* `Describe the difference between the image {{image_1}} and the image {{image_2}}`.
*/
prompt: string;

variables: Array<VisionAnalyzeImagesParams.Variable>;
}

export namespace VisionAnalyzeImagesParams {
/**
* An array of file variables required for the analysis. The image files must be
* uploaded to the Writer platform before they can be used in a vision request.
* Learn how to upload files using the
* [Files API](/api-guides/api-reference/file-api/upload-files).
*/
export interface Variable {
/**
* The File ID of the image to be analyzed. The file must be uploaded to the Writer
* platform before it can be used in a vision request.
*/
file_id: string;

/**
* The name of the file variable. You must reference this name in the prompt with
* double curly braces (`{{}}`). For example,
* `Describe the difference between the image {{image_1}} and the image {{image_2}}`.
*/
name: string;
}
}

export declare namespace Vision {
export {
type VisionRequest as VisionRequest,
type VisionResponse as VisionResponse,
type VisionAnalyzeImagesParams as VisionAnalyzeImagesParams,
};
}
39 changes: 39 additions & 0 deletions tests/api-resources/vision.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Writer from 'writer-sdk';

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

describe('resource vision', () => {
test('analyzeImages: only required params', async () => {
const responsePromise = client.vision.analyzeImages({
model: 'palmyra-vision',
prompt: 'Describe the difference between the image {{image_1}} and the image {{image_2}}.',
variables: [
{ file_id: 'f1234', name: 'image_1' },
{ file_id: 'f9876', name: 'image_2' },
],
});
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('analyzeImages: required and optional params', async () => {
const response = await client.vision.analyzeImages({
model: 'palmyra-vision',
prompt: 'Describe the difference between the image {{image_1}} and the image {{image_2}}.',
variables: [
{ file_id: 'f1234', name: 'image_1' },
{ file_id: 'f9876', name: 'image_2' },
],
});
});
});