From a94617deb649119992468394a1bc795f502507f5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 21 Mar 2025 21:03:04 +0000 Subject: [PATCH] feat(api): Add Vision endpoint. --- .stats.yml | 2 +- api.md | 11 +++ src/client.ts | 10 +++ src/resources/index.ts | 1 + src/resources/vision.ts | 109 +++++++++++++++++++++++++++++ tests/api-resources/vision.test.ts | 39 +++++++++++ 6 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 src/resources/vision.ts create mode 100644 tests/api-resources/vision.test.ts diff --git a/.stats.yml b/.stats.yml index c7093cc2..c99a6c86 100644 --- a/.stats.yml +++ b/.stats.yml @@ -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 diff --git a/api.md b/api.md index 3e177f64..00ba37c6 100644 --- a/api.md +++ b/api.md @@ -156,3 +156,14 @@ Types: Methods: - client.tools.comprehend.medical({ ...params }) -> ComprehendMedicalResponse + +# Vision + +Types: + +- VisionRequest +- VisionResponse + +Methods: + +- client.vision.analyzeImages({ ...params }) -> VisionResponse diff --git a/src/client.ts b/src/client.ts index 8935ec7c..304afc7a 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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'; @@ -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; @@ -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; @@ -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; diff --git a/src/resources/index.ts b/src/resources/index.ts index 1bf37117..0868bb14 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -71,3 +71,4 @@ export { type ToolContextAwareSplittingParams, type ToolParsePdfParams, } from './tools/tools'; +export { Vision, type VisionRequest, type VisionResponse, type VisionAnalyzeImagesParams } from './vision'; diff --git a/src/resources/vision.ts b/src/resources/vision.ts new file mode 100644 index 00000000..0e7fb25a --- /dev/null +++ b/src/resources/vision.ts @@ -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 { + 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; +} + +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; +} + +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, + }; +} diff --git a/tests/api-resources/vision.test.ts b/tests/api-resources/vision.test.ts new file mode 100644 index 00000000..460d874c --- /dev/null +++ b/tests/api-resources/vision.test.ts @@ -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' }, + ], + }); + }); +});