diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d1c8fe9..0e140f8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,12 +55,12 @@ cd together-typescript # With yarn yarn link cd ../my-package -yarn link together +yarn link together-ai # With pnpm pnpm link --global cd ../my-package -pnpm link -—global together +pnpm link -—global together-ai ``` ## Running tests diff --git a/README.md b/README.md index 4209242..8d4901d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Together Node API Library -[![NPM version](https://img.shields.io/npm/v/together.svg)](https://npmjs.org/package/together) +[![NPM version](https://img.shields.io/npm/v/together-ai.svg)](https://npmjs.org/package/together-ai) This library provides convenient access to the Together REST API from server-side TypeScript or JavaScript. @@ -11,7 +11,7 @@ It is generated with [Stainless](https://www.stainlessapi.com/). ## Installation ```sh -npm install together +npm install together-ai ``` ## Usage @@ -20,7 +20,7 @@ The full API of this library can be found in [api.md](api.md). ```js -import Together from 'together'; +import Together from 'together-ai'; const together = new Together({ accessToken: process.env['TOGETHER_API_KEY'], // This is the default and can be omitted @@ -43,7 +43,7 @@ main(); We provide support for streaming responses using Server Sent Events (SSE). ```ts -import Together from 'together'; +import Together from 'together-ai'; const together = new Together(); @@ -66,7 +66,7 @@ This library includes TypeScript definitions for all request params and response ```ts -import Together from 'together'; +import Together from 'together-ai'; const together = new Together({ accessToken: process.env['TOGETHER_API_KEY'], // This is the default and can be omitted @@ -254,11 +254,11 @@ add the following import before your first import `from "Together"`: ```ts // Tell TypeScript and the package to use the global web fetch instead of node-fetch. // Note, despite the name, this does not add any polyfills, but expects them to be provided if needed. -import 'together/shims/web'; -import Together from 'together'; +import 'together-ai/shims/web'; +import Together from 'together-ai'; ``` -To do the inverse, add `import "together/shims/node"` (which does import polyfills). +To do the inverse, add `import "together-ai/shims/node"` (which does import polyfills). This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/togethercomputer/together-typescript/tree/main/src/_shims#readme)). ### Logging and middleware @@ -268,7 +268,7 @@ which can be used to inspect or alter the `Request` or `Response` before/after e ```ts import { fetch } from 'undici'; // as one example -import Together from 'together'; +import Together from 'together-ai'; const client = new Together({ fetch: async (url: RequestInfo, init?: RequestInit): Promise => { @@ -330,7 +330,7 @@ TypeScript >= 4.5 is supported. The following runtimes are supported: - Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions. -- Deno v1.28.0 or higher, using `import Together from "npm:together"`. +- Deno v1.28.0 or higher, using `import Together from "npm:together-ai"`. - Bun 1.0 or later. - Cloudflare Workers. - Vercel Edge Runtime. diff --git a/jest.config.ts b/jest.config.ts index 15da945..e08341f 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -7,9 +7,9 @@ const config: JestConfigWithTsJest = { '^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }], }, moduleNameMapper: { - '^together$': '/src/index.ts', - '^together/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', - '^together/(.*)$': '/src/$1', + '^together-ai$': '/src/index.ts', + '^together-ai/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', + '^together-ai/(.*)$': '/src/$1', }, modulePathIgnorePatterns: [ '/ecosystem-tests/', diff --git a/package.json b/package.json index 98c2753..5d98a4c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "together", + "name": "together-ai", "version": "0.1.0-alpha.1", "description": "The official TypeScript library for the Together API", "author": "Together ", @@ -61,8 +61,8 @@ "./shims/web.mjs" ], "imports": { - "together": ".", - "together/*": "./src/*" + "together-ai": ".", + "together-ai/*": "./src/*" }, "exports": { "./_shims/auto/*": { diff --git a/scripts/build b/scripts/build index 5fa823e..6d5dd97 100755 --- a/scripts/build +++ b/scripts/build @@ -8,7 +8,7 @@ node scripts/utils/check-version.cjs # Build into dist and will publish the package from there, # so that src/resources/foo.ts becomes /resources/foo.js -# This way importing from `"together/resources/foo"` works +# This way importing from `"together-ai/resources/foo"` works # even with `"moduleResolution": "node"` rm -rf dist; mkdir dist @@ -47,8 +47,8 @@ node scripts/utils/postprocess-files.cjs # make sure that nothing crashes when we require the output CJS or # import the output ESM -(cd dist && node -e 'require("together")') -(cd dist && node -e 'import("together")' --input-type=module) +(cd dist && node -e 'require("together-ai")') +(cd dist && node -e 'import("together-ai")' --input-type=module) if command -v deno &> /dev/null && [ -e ./scripts/build-deno ] then diff --git a/scripts/utils/postprocess-files.cjs b/scripts/utils/postprocess-files.cjs index fa66877..4f833e7 100644 --- a/scripts/utils/postprocess-files.cjs +++ b/scripts/utils/postprocess-files.cjs @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); const { parse } = require('@typescript-eslint/parser'); -const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'together/'; +const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'together-ai/'; const distDir = process.env['DIST_PATH'] ? @@ -142,7 +142,7 @@ async function postprocess() { if (file.endsWith('.d.ts')) { // work around bad tsc behavior - // if we have `import { type Readable } from 'together/_shims/index'`, + // if we have `import { type Readable } from 'together-ai/_shims/index'`, // tsc sometimes replaces `Readable` with `import("stream").Readable` inline // in the output .d.ts transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable'); diff --git a/src/_shims/README.md b/src/_shims/README.md index 42b7802..e7ffa10 100644 --- a/src/_shims/README.md +++ b/src/_shims/README.md @@ -1,9 +1,9 @@ # 👋 Wondering what everything in here does? -`together` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various +`together-ai` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM). -To do this, `together` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node. +To do this, `together-ai` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node. It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to automatically select the correct shims for each environment. However, conditional exports are a fairly new @@ -15,32 +15,32 @@ getting the wrong raw `Response` type from `.asResponse()`, for example. The user can work around these issues by manually importing one of: -- `import 'together/shims/node'` -- `import 'together/shims/web'` +- `import 'together-ai/shims/node'` +- `import 'together-ai/shims/web'` All of the code here in `_shims` handles selecting the automatic default shims or manual overrides. ### How it works - Runtime -Runtime shims get installed by calling `setShims` exported by `together/_shims/registry`. +Runtime shims get installed by calling `setShims` exported by `together-ai/_shims/registry`. -Manually importing `together/shims/node` or `together/shims/web`, calls `setShims` with the respective runtime shims. +Manually importing `together-ai/shims/node` or `together-ai/shims/web`, calls `setShims` with the respective runtime shims. -All client code imports shims from `together/_shims/index`, which: +All client code imports shims from `together-ai/_shims/index`, which: - checks if shims have been set manually -- if not, calls `setShims` with the shims from `together/_shims/auto/runtime` -- re-exports the installed shims from `together/_shims/registry`. +- if not, calls `setShims` with the shims from `together-ai/_shims/auto/runtime` +- re-exports the installed shims from `together-ai/_shims/registry`. -`together/_shims/auto/runtime` exports web runtime shims. -If the `node` export condition is set, the export map replaces it with `together/_shims/auto/runtime-node`. +`together-ai/_shims/auto/runtime` exports web runtime shims. +If the `node` export condition is set, the export map replaces it with `together-ai/_shims/auto/runtime-node`. ### How it works - Type time -All client code imports shim types from `together/_shims/index`, which selects the manual types from `together/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `together/_shims/auto/types`. +All client code imports shim types from `together-ai/_shims/index`, which selects the manual types from `together-ai/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `together-ai/_shims/auto/types`. -`together/_shims/manual-types` exports an empty namespace. -Manually importing `together/shims/node` or `together/shims/web` merges declarations into this empty namespace, so they get picked up by `together/_shims/index`. +`together-ai/_shims/manual-types` exports an empty namespace. +Manually importing `together-ai/shims/node` or `together-ai/shims/web` merges declarations into this empty namespace, so they get picked up by `together-ai/_shims/index`. -`together/_shims/auto/types` exports web type definitions. -If the `node` export condition is set, the export map replaces it with `together/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. +`together-ai/_shims/auto/types` exports web type definitions. +If the `node` export condition is set, the export map replaces it with `together-ai/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. diff --git a/src/_shims/index.d.ts b/src/_shims/index.d.ts index 90450b2..0cc3bf4 100644 --- a/src/_shims/index.d.ts +++ b/src/_shims/index.d.ts @@ -2,7 +2,7 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ import { manual } from './manual-types'; -import * as auto from 'together/_shims/auto/types'; +import * as auto from 'together-ai/_shims/auto/types'; import { type RequestOptions } from '../core'; type SelectType = unknown extends Manual ? Auto : Manual; diff --git a/src/_shims/index.js b/src/_shims/index.js index b244b52..1c2303f 100644 --- a/src/_shims/index.js +++ b/src/_shims/index.js @@ -2,7 +2,7 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ const shims = require('./registry'); -const auto = require('together/_shims/auto/runtime'); +const auto = require('together-ai/_shims/auto/runtime'); if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); for (const property of Object.keys(shims)) { Object.defineProperty(exports, property, { diff --git a/src/_shims/index.mjs b/src/_shims/index.mjs index 63452b1..b174b1e 100644 --- a/src/_shims/index.mjs +++ b/src/_shims/index.mjs @@ -2,6 +2,6 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ import * as shims from './registry.mjs'; -import * as auto from 'together/_shims/auto/runtime'; +import * as auto from 'together-ai/_shims/auto/runtime'; if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); export * from './registry.mjs'; diff --git a/src/_shims/manual-types.d.ts b/src/_shims/manual-types.d.ts index d654354..8673fac 100644 --- a/src/_shims/manual-types.d.ts +++ b/src/_shims/manual-types.d.ts @@ -4,8 +4,8 @@ /** * Types will get added to this namespace when you import one of the following: * - * import 'together/shims/node' - * import 'together/shims/web' + * import 'together-ai/shims/node' + * import 'together-ai/shims/web' * * Importing more than one will cause type and runtime errors. */ diff --git a/src/_shims/registry.ts b/src/_shims/registry.ts index 0c3f2a7..e9dbbd5 100644 --- a/src/_shims/registry.ts +++ b/src/_shims/registry.ts @@ -42,12 +42,12 @@ export let isFsReadStream: Shims['isFsReadStream'] | undefined = undefined; export function setShims(shims: Shims, options: { auto: boolean } = { auto: false }) { if (auto) { throw new Error( - `you must \`import 'together/shims/${shims.kind}'\` before importing anything else from together`, + `you must \`import 'together-ai/shims/${shims.kind}'\` before importing anything else from together-ai`, ); } if (kind) { throw new Error( - `can't \`import 'together/shims/${shims.kind}'\` after \`import 'together/shims/${kind}'\``, + `can't \`import 'together-ai/shims/${shims.kind}'\` after \`import 'together-ai/shims/${kind}'\``, ); } auto = options.auto; diff --git a/src/_shims/web-runtime.ts b/src/_shims/web-runtime.ts index 304e034..88327a4 100644 --- a/src/_shims/web-runtime.ts +++ b/src/_shims/web-runtime.ts @@ -9,9 +9,9 @@ export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } const recommendation = manuallyImported ? `You may need to use polyfills` - : `Add one of these imports before your first \`import … from 'together'\`: -- \`import 'together/shims/node'\` (if you're running on Node) -- \`import 'together/shims/web'\` (otherwise) + : `Add one of these imports before your first \`import … from 'together-ai'\`: +- \`import 'together-ai/shims/node'\` (if you're running on Node) +- \`import 'together-ai/shims/web'\` (otherwise) `; let _fetch, _Request, _Response, _Headers; diff --git a/src/core.ts b/src/core.ts index bd08849..b26e2b3 100644 --- a/src/core.ts +++ b/src/core.ts @@ -111,9 +111,9 @@ export class APIPromise extends Promise { * * 👋 Getting the wrong TypeScript type for `Response`? * Try setting `"moduleResolution": "NodeNext"` if you can, - * or add one of these imports before your first `import … from 'together'`: - * - `import 'together/shims/node'` (if you're running on Node) - * - `import 'together/shims/web'` (otherwise) + * or add one of these imports before your first `import … from 'together-ai'`: + * - `import 'together-ai/shims/node'` (if you're running on Node) + * - `import 'together-ai/shims/web'` (otherwise) */ asResponse(): Promise { return this.responsePromise.then((p) => p.response); @@ -127,9 +127,9 @@ export class APIPromise extends Promise { * * 👋 Getting the wrong TypeScript type for `Response`? * Try setting `"moduleResolution": "NodeNext"` if you can, - * or add one of these imports before your first `import … from 'together'`: - * - `import 'together/shims/node'` (if you're running on Node) - * - `import 'together/shims/web'` (otherwise) + * or add one of these imports before your first `import … from 'together-ai'`: + * - `import 'together-ai/shims/node'` (if you're running on Node) + * - `import 'together-ai/shims/web'` (otherwise) */ async withResponse(): Promise<{ data: T; response: Response }> { const [data, response] = await Promise.all([this.parse(), this.asResponse()]); diff --git a/src/streaming.ts b/src/streaming.ts index a9f4bd2..619f616 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -1,7 +1,7 @@ import { ReadableStream, type Response } from './_shims/index'; import { TogetherError } from './error'; -import { APIError } from 'together/error'; +import { APIError } from 'together-ai/error'; type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined; diff --git a/tests/api-resources/chat/completions.test.ts b/tests/api-resources/chat/completions.test.ts index 3e07928..80afa5e 100644 --- a/tests/api-resources/chat/completions.test.ts +++ b/tests/api-resources/chat/completions.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Together from 'together'; +import Together from 'together-ai'; import { Response } from 'node-fetch'; const together = new Together({ diff --git a/tests/api-resources/completions.test.ts b/tests/api-resources/completions.test.ts index c3ebb37..3542bb3 100644 --- a/tests/api-resources/completions.test.ts +++ b/tests/api-resources/completions.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Together from 'together'; +import Together from 'together-ai'; import { Response } from 'node-fetch'; const together = new Together({ diff --git a/tests/api-resources/embeddings.test.ts b/tests/api-resources/embeddings.test.ts index dffe3ff..ade6660 100644 --- a/tests/api-resources/embeddings.test.ts +++ b/tests/api-resources/embeddings.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Together from 'together'; +import Together from 'together-ai'; import { Response } from 'node-fetch'; const together = new Together({ diff --git a/tests/api-resources/files.test.ts b/tests/api-resources/files.test.ts index 3df0e14..181ddf6 100644 --- a/tests/api-resources/files.test.ts +++ b/tests/api-resources/files.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Together from 'together'; +import Together from 'together-ai'; import { Response } from 'node-fetch'; const together = new Together({ diff --git a/tests/api-resources/fine-tune.test.ts b/tests/api-resources/fine-tune.test.ts index 9b6b133..2eb1a81 100644 --- a/tests/api-resources/fine-tune.test.ts +++ b/tests/api-resources/fine-tune.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Together from 'together'; +import Together from 'together-ai'; import { Response } from 'node-fetch'; const together = new Together({ diff --git a/tests/api-resources/images.test.ts b/tests/api-resources/images.test.ts index 904b813..2ce65d8 100644 --- a/tests/api-resources/images.test.ts +++ b/tests/api-resources/images.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Together from 'together'; +import Together from 'together-ai'; import { Response } from 'node-fetch'; const together = new Together({ diff --git a/tests/api-resources/models.test.ts b/tests/api-resources/models.test.ts index 4360639..a1b7194 100644 --- a/tests/api-resources/models.test.ts +++ b/tests/api-resources/models.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Together from 'together'; +import Together from 'together-ai'; import { Response } from 'node-fetch'; const together = new Together({ diff --git a/tests/form.test.ts b/tests/form.test.ts index 159b22d..fb93999 100644 --- a/tests/form.test.ts +++ b/tests/form.test.ts @@ -1,6 +1,6 @@ -import { multipartFormRequestOptions, createForm } from 'together/core'; -import { Blob } from 'together/_shims/index'; -import { toFile } from 'together'; +import { multipartFormRequestOptions, createForm } from 'together-ai/core'; +import { Blob } from 'together-ai/_shims/index'; +import { toFile } from 'together-ai'; describe('form data validation', () => { test('valid values do not error', async () => { diff --git a/tests/index.test.ts b/tests/index.test.ts index f5b3696..a3c59a1 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Together from 'together'; -import { APIUserAbortError } from 'together'; -import { Headers } from 'together/core'; +import Together from 'together-ai'; +import { APIUserAbortError } from 'together-ai'; +import { Headers } from 'together-ai/core'; import defaultFetch, { Response, type RequestInit, type RequestInfo } from 'node-fetch'; describe('instantiate client', () => { diff --git a/tests/responses.test.ts b/tests/responses.test.ts index f159dbe..dff917b 100644 --- a/tests/responses.test.ts +++ b/tests/responses.test.ts @@ -1,5 +1,5 @@ -import { createResponseHeaders } from 'together/core'; -import { Headers } from 'together/_shims/index'; +import { createResponseHeaders } from 'together-ai/core'; +import { Headers } from 'together-ai/_shims/index'; describe('response parsing', () => { // TODO: test unicode characters diff --git a/tests/streaming.test.ts b/tests/streaming.test.ts index 438d97e..39372ff 100644 --- a/tests/streaming.test.ts +++ b/tests/streaming.test.ts @@ -1,7 +1,7 @@ import { Response } from 'node-fetch'; import { PassThrough } from 'stream'; import assert from 'assert'; -import { _iterSSEMessages, _decodeChunks as decodeChunks } from 'together/streaming'; +import { _iterSSEMessages, _decodeChunks as decodeChunks } from 'together-ai/streaming'; describe('line decoder', () => { test('basic', () => { diff --git a/tests/stringifyQuery.test.ts b/tests/stringifyQuery.test.ts index f4cbc79..07123ca 100644 --- a/tests/stringifyQuery.test.ts +++ b/tests/stringifyQuery.test.ts @@ -1,4 +1,4 @@ -import { APIClient } from 'together/core'; +import { APIClient } from 'together-ai/core'; const { stringifyQuery } = APIClient.prototype as any; diff --git a/tests/uploads.test.ts b/tests/uploads.test.ts index 6da7514..80f56df 100644 --- a/tests/uploads.test.ts +++ b/tests/uploads.test.ts @@ -1,6 +1,6 @@ import fs from 'fs'; -import { toFile, type ResponseLike } from 'together/uploads'; -import { File } from 'together/_shims/index'; +import { toFile, type ResponseLike } from 'together-ai/uploads'; +import { File } from 'together-ai/_shims/index'; class MyClass { name: string = 'foo'; diff --git a/tsconfig.build.json b/tsconfig.build.json index 9ea51f0..7925201 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -5,8 +5,8 @@ "compilerOptions": { "rootDir": "./dist/src", "paths": { - "together/*": ["dist/src/*"], - "together": ["dist/src/index.ts"], + "together-ai/*": ["dist/src/*"], + "together-ai": ["dist/src/index.ts"], }, "noEmit": false, "declaration": true, diff --git a/tsconfig.deno.json b/tsconfig.deno.json index e020bd8..debfa6c 100644 --- a/tsconfig.deno.json +++ b/tsconfig.deno.json @@ -6,9 +6,9 @@ "rootDir": "./deno", "lib": ["es2020", "DOM"], "paths": { - "together/_shims/auto/*": ["deno/_shims/auto/*-deno"], - "together/*": ["deno/*"], - "together": ["deno/index.ts"], + "together-ai/_shims/auto/*": ["deno/_shims/auto/*-deno"], + "together-ai/*": ["deno/*"], + "together-ai": ["deno/index.ts"], }, "noEmit": true, "declaration": true, diff --git a/tsconfig.json b/tsconfig.json index 1116e42..eef5c17 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,9 +9,9 @@ "esModuleInterop": true, "baseUrl": "./", "paths": { - "together/_shims/auto/*": ["src/_shims/auto/*-node"], - "together/*": ["src/*"], - "together": ["src/index.ts"], + "together-ai/_shims/auto/*": ["src/_shims/auto/*-node"], + "together-ai/*": ["src/*"], + "together-ai": ["src/index.ts"], }, "noEmit": true,