Skip to content

Commit

Permalink
Release 0.0.2-1
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Dec 9, 2024
1 parent 75d7e86 commit 6622f88
Show file tree
Hide file tree
Showing 32 changed files with 1,467 additions and 443 deletions.
284 changes: 284 additions & 0 deletions .mock/definition/endpoints.yml

Large diffs are not rendered by default.

263 changes: 263 additions & 0 deletions .mock/openapi/openapi.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Voyage TypeScript Library

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern)
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fvoyage-ai%2Ftypescript-sdk)
[![npm shield](https://img.shields.io/npm/v/voyageai)](https://www.npmjs.com/package/voyageai)

The Voyage TypeScript library provides convenient access to the Voyage API from TypeScript.
Expand Down Expand Up @@ -51,7 +51,7 @@ following namespace:
```typescript
import { VoyageAI } from "voyageai";

const request: VoyageAI.EmbedRequest = {
const request: VoyageAI.MultimodalembeddingsApiRequest = {
...
};
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "voyageai",
"version": "0.0.1-5",
"version": "0.0.2-1",
"private": false,
"repository": "https://github.com/voyage-ai/typescript-sdk",
"main": "./index.js",
Expand Down
68 changes: 68 additions & 0 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,71 @@ await client.rerank({
</details>

##

## Endpoints

<details><summary><code>client.endpoints.<a href="/src/api/resources/endpoints/client/Client.ts">multimodalembeddingsApi</a>({ ...params }) -> VoyageAI.MultimodalembeddingsApiResponse</code></summary>
<dl>
<dd>

#### 📝 Description

<dl>
<dd>

<dl>
<dd>

The Voyage multimodal embedding endpoint returns vector representations for a given list of multimodal inputs consisting of text, images, or an interleaving of both modalities.

</dd>
</dl>
</dd>
</dl>

#### 🔌 Usage

<dl>
<dd>

<dl>
<dd>

```typescript
await client.endpoints.multimodalembeddingsApi({
inputs: [{}],
model: "model",
});
```

</dd>
</dl>
</dd>
</dl>

#### ⚙️ Parameters

<dl>
<dd>

<dl>
<dd>

**request:** `VoyageAI.MultimodalembeddingsApiRequest`

</dd>
</dl>

<dl>
<dd>

**requestOptions:** `Endpoints.RequestOptions`

</dd>
</dl>
</dd>
</dl>

</dd>
</dl>
</details>
15 changes: 11 additions & 4 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as VoyageAI from "./api/index";
import * as serializers from "./serialization/index";
import urlJoin from "url-join";
import * as errors from "./errors/index";
import { Endpoints } from "./api/resources/endpoints/client/Client";

export declare namespace VoyageAIClient {
interface Options {
Expand Down Expand Up @@ -55,8 +56,8 @@ export class VoyageAIClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "voyageai",
"X-Fern-SDK-Version": "0.0.1-5",
"User-Agent": "voyageai/0.0.1-5",
"X-Fern-SDK-Version": "0.0.2-1",
"User-Agent": "voyageai/0.0.2-1",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
Expand Down Expand Up @@ -126,8 +127,8 @@ export class VoyageAIClient {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "voyageai",
"X-Fern-SDK-Version": "0.0.1-5",
"User-Agent": "voyageai/0.0.1-5",
"X-Fern-SDK-Version": "0.0.2-1",
"User-Agent": "voyageai/0.0.2-1",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
Expand Down Expand Up @@ -170,6 +171,12 @@ export class VoyageAIClient {
}
}

protected _endpoints: Endpoints | undefined;

public get endpoints(): Endpoints {
return (this._endpoints ??= new Endpoints(this._options));
}

protected async _getAuthorizationHeader(): Promise<string> {
const bearer = (await core.Supplier.get(this._options.apiKey)) ?? process?.env["VOYAGE_API_KEY"];
if (bearer == null) {
Expand Down
1 change: 1 addition & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./resources";
export * from "./types";
export * from "./client";
112 changes: 112 additions & 0 deletions src/api/resources/endpoints/client/Client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as environments from "../../../../environments";
import * as core from "../../../../core";
import * as VoyageAI from "../../../index";
import * as serializers from "../../../../serialization/index";
import urlJoin from "url-join";
import * as errors from "../../../../errors/index";

export declare namespace Endpoints {
interface Options {
environment?: core.Supplier<environments.VoyageAIEnvironment | string>;
apiKey?: core.Supplier<core.BearerToken | undefined>;
fetcher?: core.FetchFunction;
}

interface RequestOptions {
/** The maximum time to wait for a response in seconds. */
timeoutInSeconds?: number;
/** The number of times to retry the request. Defaults to 2. */
maxRetries?: number;
/** A hook to abort the request. */
abortSignal?: AbortSignal;
}
}

export class Endpoints {
constructor(protected readonly _options: Endpoints.Options = {}) {}

/**
* The Voyage multimodal embedding endpoint returns vector representations for a given list of multimodal inputs consisting of text, images, or an interleaving of both modalities.
*
* @param {VoyageAI.MultimodalembeddingsApiRequest} request
* @param {Endpoints.RequestOptions} requestOptions - Request-specific configuration.
*
* @example
* await client.endpoints.multimodalembeddingsApi({
* inputs: [{}],
* model: "model"
* })
*/
public async multimodalembeddingsApi(
request: VoyageAI.MultimodalembeddingsApiRequest,
requestOptions?: Endpoints.RequestOptions
): Promise<VoyageAI.MultimodalembeddingsApiResponse> {
const _response = await (this._options.fetcher ?? core.fetcher)({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.VoyageAIEnvironment.Default,
"multimodalembeddings"
),
method: "POST",
headers: {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "voyageai",
"X-Fern-SDK-Version": "0.0.2-1",
"User-Agent": "voyageai/0.0.2-1",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
requestType: "json",
body: serializers.MultimodalembeddingsApiRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return serializers.MultimodalembeddingsApiResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
});
}

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

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

protected async _getAuthorizationHeader(): Promise<string> {
const bearer = (await core.Supplier.get(this._options.apiKey)) ?? process?.env["VOYAGE_API_KEY"];
if (bearer == null) {
throw new errors.VoyageAIError({
message: "Please specify VOYAGE_API_KEY when instantiating the client.",
});
}

return `Bearer ${bearer}`;
}
}
1 change: 1 addition & 0 deletions src/api/resources/endpoints/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./requests";
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as VoyageAI from "../../../../index";

/**
* @example
* {
* inputs: [{}],
* model: "model"
* }
*/
export interface MultimodalembeddingsApiRequest {
/**
* A list of multimodal inputs to be vectorized.
* A single input in the list is a dictionary containing a single key "content", whose value represents a sequence of text and images.
* <ul><p></p>
* <li> The value of&nbsp;<code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">"content"</span></code>&nbsp;is a list of dictionaries, each representing a single piece of text or image. The dictionaries have four possible keys:
* <ol class="nested-ordered-list">
* <li> <b>type</b>: Specifies the type of the piece of the content. Allowed values are <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">text</span></code>, <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image_url</span></code>, or <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image_base64</span></code>.</li>
* <li> <b>text</b>: Only present when <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">type</span></code> is <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">text</span></code>. The value should be a text string.</li>
* <li> <b>image_base64</b>: Only present when <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">type</span></code> is <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image_base64</span></code>. The value should be a Base64-encoded image in the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data">data URL</a> format <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">data:[&lt;mediatype&gt;];base64,&lt;data&gt;</span></code>. Currently supported <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">mediatypes</span></code> are: <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image/png</span></code>, <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image/jpeg</span></code>, <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image/webp</span></code>, and <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image/gif</span></code>.</li>
* <li> <b>image_url</b>: Only present when <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">type</span></code> is <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image_url</span></code>. The value should be a URL linking to the image. We support PNG, JPEG, WEBP, and GIF images.</li>
* </ol>
* </li>
* <li> <b>Note</b>: Only one of the keys, <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image_base64</span></code> or <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image_url</span></code>, should be present in each dictionary for image data. Consistency is required within a request, meaning each request should use either <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image_base64</span></code> or <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">image_url</span></code> exclusively for images, not both.<br>
* <br>
* <details> <summary> Example payload where <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">inputs</span></code>&nbsp;contains an image as a URL </summary>
* <br>
* The <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">inputs</span></code> list contains a single input, which consists of a piece of text and an image (which is provided via a URL).
* <pre><code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">
* {
* "inputs": [
* {
* "content": [
* {
* "type": "text",
* "text": "This is a banana."
* },
* {
* "type": "image_url",
* "image_url": "https://raw.githubusercontent.com/voyage-ai/voyage-multimodal-3/refs/heads/main/images/banana.jpg"
* }
* ]
* }
* ],
* "model": "voyage-multimodal-3"
* }
* </span></code></pre>
* </details>
* <details> <summary> Example payload where <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">inputs</span></code>&nbsp;contains a Base64 image </summary>
* <br>
* Below is an equivalent example to the one above where the image content is a Base64 image instead of a URL. (Base64 images can be lengthy, so the example only shows a shortened version.)
* <pre><code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">
* {
* "inputs": [
* {
* "content": [
* {
* "type": "text",
* "text": "This is a banana."
* },
* {
* "type": "image_base64",
* "image_base64": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA..."
* }
* ]
* }
* ],
* "model": "voyage-multimodal-3"
* }
* </span></code></pre>
* </details>
* </li>
* </ul>
*
*/
inputs: VoyageAI.MultimodalembeddingsApiRequestInputsItem[];
/**
* Name of the model. Currently, the only supported model is `voyage-multimodal-3`.
*
*/
model: string;
/**
* Type of the input text. Defaults to `null`. Other options: `query`, `document`.
* <ul> <li> When <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">input_type</span></code> is <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">null</span></code>, the embedding model directly converts your input data into numerical vectors. For retrieval/search purposes—where an input (called a "query") is used to search for relevant pieces of information (referred to as "documents")—we recommend specifying whether your inputs are intended as queries or documents by setting <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">input_type</span></code> to <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">query</span></code> or <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">document</span></code>, respectively. In these cases, Voyage prepends a prompt to your input before vectorizing it, helping the model create more effective vectors tailored for retrieval/search tasks. Since inputs can be multimodal, queries and documents can be text, images, or an interleaving of both modalities. Embeddings generated with and without the <code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">input_type</span></code> argument are compatible. </li> <li> For transparency, the following prompts are prepended to your input. </li><p></p>
* <ul>
* <li> For&nbsp;<code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">query</span></code>, the prompt is <i>"Represent the query for retrieving supporting documents:&nbsp;".</i> </li>
* <li> For&nbsp;<code class="rdmd-code lang- theme-light" data-lang="" name="" tabindex="0"><span class="cm-s-neo" data-testid="SyntaxHighlighter">document</span></code>, the prompt is <i>"Represent the query for retrieving supporting documents:&nbsp;".</i> </li>
* </ul>
* <ul></ul></ul>
*
*/
inputType?: VoyageAI.MultimodalembeddingsApiRequestInputType;
/**
* Whether to truncate the input texts to fit within the context length. Defaults to `true`. <ul> <li> If `true`, over-length input texts will be truncated to fit within the context length, before vectorized by the embedding model. </li> <li> If `false`, an error will be raised if any given text exceeds the context length. </li> </ul>
*
*/
truncation?: boolean;
/**
* Format in which the embeddings are encoded. We support two options: <ul> <li> If not specified (defaults to `null`): the embeddings are represented as lists of floating-point numbers; </li> <li> `base64`: the embeddings are compressed to [base64](https://docs.python.org/3/library/base64.html) encodings. </li> </ul>
*
*/
encodingFormat?: "base64";
}
1 change: 1 addition & 0 deletions src/api/resources/endpoints/client/requests/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { type MultimodalembeddingsApiRequest } from "./MultimodalembeddingsApiRequest";
2 changes: 2 additions & 0 deletions src/api/resources/endpoints/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./types";
export * from "./client";
Loading

0 comments on commit 6622f88

Please sign in to comment.