### Adding and Running TypeScript Examples Source: https://github.com/togethercomputer/together-typescript/blob/main/CONTRIBUTING.md Demonstrates how to add a new TypeScript example file and execute it using the 'tsn' command provided by Yarn. Requires making the script executable. ```ts // add an example to examples/.ts #!/usr/bin/env -S npm run tsn -T … ``` ```sh $ chmod +x examples/.ts # run the example against your api $ yarn tsn -T examples/.ts ``` -------------------------------- ### Installing Repository from Git Source: https://github.com/togethercomputer/together-typescript/blob/main/CONTRIBUTING.md Installs the together-typescript repository directly from a Git SSH URL using npm. ```sh $ npm install git+ssh://git@github.com:togethercomputer/together-typescript.git ``` -------------------------------- ### Create Fine-Tune Example Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Example of how to create a fine-tuning job using the TypeScript client. ```typescript import { TogetherAI } from '@togetherai/sdk'; const client = new TogetherAI('YOUR_API_KEY'); async function createFineTuneJob() { try { const response = await client.fineTune.create({ training_file: 'file-xxxx', model: 'base-model-name', // ... other parameters like hyperparameters, validation_file, etc. }); console.log('Fine-tune job created:', response); } catch (error) { console.error('Error creating fine-tune job:', error); } } createFineTuneJob(); ``` -------------------------------- ### Project Setup with Yarn Source: https://github.com/togethercomputer/together-typescript/blob/main/CONTRIBUTING.md Installs project dependencies and builds the project output files to the 'dist/' directory using Yarn. ```sh $ yarn $ yarn build ``` -------------------------------- ### Execute Code Interpreter Example Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Example of executing code using the Code Interpreter client. ```typescript import { TogetherAI } from '@togetherai/sdk'; const client = new TogetherAI('YOUR_API_KEY'); async function executeCode() { try { const response = await client.codeInterpreter.execute({ code: 'print("Hello, Code Interpreter!")', // ... other parameters if needed }); console.log('Code execution result:', response); } catch (error) { console.error('Error executing code:', error); } } executeCode(); ``` -------------------------------- ### Running Tests with Mock Server Source: https://github.com/togethercomputer/together-typescript/blob/main/CONTRIBUTING.md Sets up a mock server using Prism against an OpenAPI specification to run tests, followed by executing the test suite. ```sh $ npx prism mock path/to/your/openapi.yml ``` ```sh $ yarn run test ``` -------------------------------- ### Install Together Node API Library Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Installs the together-ai npm package using npm. This is the first step to using the library in your Node.js project. ```sh npm install together-ai ``` -------------------------------- ### Generate Image Example Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Example of generating an image using the Images API client. ```typescript import { TogetherAI } from '@togetherai/sdk'; const client = new TogetherAI('YOUR_API_KEY'); async function generateImage() { try { const response = await client.images.create({ prompt: 'A futuristic cityscape at sunset', model: 'image-model-name', // ... other parameters like n, size, etc. }); console.log('Image generation response:', response); } catch (error) { console.error('Error generating image:', error); } } generateImage(); ``` -------------------------------- ### Linking Local Repository with PNPM Source: https://github.com/togethercomputer/together-typescript/blob/main/CONTRIBUTING.md Clones the repository locally, links it globally using PNPM, and then links it to a local package for development. ```sh # With pnpm $ pnpm link --global $ cd ../my-package $ pnpm link -—global together-ai ``` -------------------------------- ### Linting and Formatting Commands Source: https://github.com/togethercomputer/together-typescript/blob/main/CONTRIBUTING.md Commands to check code style with ESLint and format code automatically using Prettier. ```sh $ yarn lint ``` ```sh $ yarn fix ``` -------------------------------- ### Publishing NPM Packages Source: https://github.com/togethercomputer/together-typescript/blob/main/CONTRIBUTING.md Details on how to publish packages to npm, either automatically via a GitHub workflow or manually by setting an NPM_TOKEN environment variable and running a script. ```sh # Publish with a GitHub workflow # You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/togethercomputer/together-typescript/actions/workflows/publish-npm.yml). # Publish manually # If you need to manually release a package, you can run the `bin/publish-npm` script with an `NPM_TOKEN` set on the environment. ``` -------------------------------- ### Speech Synthesis Example Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Example of synthesizing speech from text using the Audio API client. ```typescript import { TogetherAI } from '@togetherai/sdk'; const client = new TogetherAI('YOUR_API_KEY'); async function synthesizeSpeech() { try { const response = await client.audio.create({ model: 'tts-model-name', input: 'Hello, this is a text-to-speech test.', voice: 'echo', // ... other parameters }); // The response is typically a stream or blob, handle accordingly console.log('Speech synthesis response received.'); // Example: Save to a file (requires node-fetch or similar for stream handling) // const buffer = await response.arrayBuffer(); // fs.writeFileSync('output.mp3', Buffer.from(buffer)); } catch (error) { console.error('Error synthesizing speech:', error); } } synthesizeSpeech(); ``` -------------------------------- ### Linking Local Repository with Yarn Source: https://github.com/togethercomputer/together-typescript/blob/main/CONTRIBUTING.md Clones the repository locally, links it globally using Yarn, and then links it to a local package for development. ```sh # Clone $ git clone https://www.github.com/togethercomputer/together-typescript $ cd together-typescript # With yarn $ yarn link $ cd ../my-package $ yarn link together-ai ``` -------------------------------- ### Configure HTTP Agent for Proxies Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Demonstrates configuring an HTTP(S) Agent, such as HttpsProxyAgent, for the Together client to route requests through a proxy. This example shows both default client configuration and per-request overrides. ```typescript import http from 'http'; import { HttpsProxyAgent } from 'https-proxy-agent'; // Configure the default for all requests: const client = new Together({ httpAgent: new HttpsProxyAgent(process.env.PROXY_URL), }); // Override per-request: await client.chat.completions.create( { messages: [{ role: 'user', content: 'Say this is a test' }], model: 'mistralai/Mixtral-8x7B-Instruct-v0.1', }, { httpAgent: new http.Agent({ keepAlive: false }), }, ); ``` -------------------------------- ### Handling API Errors Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Explains how the library throws subclasses of `APIError` for connection issues or non-success HTTP status codes, and provides an example of catching and inspecting these errors. ```typescript const chatCompletion = await client.chat.completions .create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'mistralai/Mixtral-8x7B-Instruct-v0.1', }) .catch(async (err) => { if (err instanceof Together.APIError) { console.log(err.status); // e.g., 400 console.log(err.name); // e.g., BadRequestError console.log(err.headers); // e.g., {server: 'nginx', ...} } else { throw err; } }); /* Error codes and types: - 400: BadRequestError - 401: AuthenticationError - 403: PermissionDeniedError - 404: NotFoundError - 422: UnprocessableEntityError - 429: RateLimitError - >=500: InternalServerError - N/A: APIConnectionError */ ``` -------------------------------- ### Access Raw Response Data Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Access the raw `Response` object returned by `fetch()` using the `.asResponse()` method, or get both the parsed data and the raw `Response` using `.withResponse()`. ```ts const client = new Together(); const response = await client.chat.completions .create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'mistralai/Mixtral-8x7B-Instruct-v0.1', }) .asResponse(); console.log(response.headers.get('X-My-Header')); console.log(response.statusText); // access the underlying Response object ``` ```ts const { data: chatCompletion, response: raw } = await client.chat.completions .create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'mistralai/Mixtral-8x7B-Instruct-v0.1', }) .withResponse(); console.log(raw.headers.get('X-My-Header')); console.log(chatCompletion.choices); ``` -------------------------------- ### Hardware API Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Provides functionality to list available hardware resources. Includes response types for hardware listings. ```APIDOC Hardware API: Types: - HardwareListResponse Methods: GET /hardware client.hardware.list({ ...params }) -> HardwareListResponse - Lists available hardware resources. - Parameters: - params: Object for filtering or pagination. - Returns: - HardwareListResponse: A list of hardware resources. ``` -------------------------------- ### Fine-Tuning API Methods Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Manage and monitor fine-tuning jobs. Includes creating, retrieving, listing, canceling, and downloading fine-tuned models, as well as retrieving events and checkpoints. ```APIDOC client.fineTune.create({ ...params }) - Method: POST - Endpoint: /fine-tunes - Description: Creates a new fine-tuning job. - Parameters: Accepts parameters for model configuration, training data, and hyperparameters. - Returns: FineTuneCreateResponse client.fineTune.retrieve(id) - Method: GET - Endpoint: /fine-tunes/{id} - Description: Retrieves details of a specific fine-tuning job. - Parameters: - id (string): The unique identifier of the fine-tuning job. - Returns: FineTune client.fineTune.list() - Method: GET - Endpoint: /fine-tunes - Description: Lists all fine-tuning jobs. - Returns: FineTuneListResponse client.fineTune.cancel(id) - Method: POST - Endpoint: /fine-tunes/{id}/cancel - Description: Cancels a running fine-tuning job. - Parameters: - id (string): The unique identifier of the fine-tuning job to cancel. - Returns: FineTuneCancelResponse client.fineTune.download({ ...params }) - Method: GET - Endpoint: /finetune/download - Description: Downloads fine-tuned model files. - Parameters: Accepts parameters specifying the model to download. - Returns: FineTuneDownloadResponse client.fineTune.listEvents(id) - Method: GET - Endpoint: /fine-tunes/{id}/events - Description: Lists events associated with a specific fine-tuning job. - Parameters: - id (string): The unique identifier of the fine-tuning job. - Returns: FineTuneListEventsResponse client.fineTune.retrieveCheckpoints(id) - Method: GET - Endpoint: /fine-tunes/{id}/checkpoints - Description: Retrieves checkpoints for a specific fine-tuning job. - Parameters: - id (string): The unique identifier of the fine-tuning job. - Returns: FineTuneRetrieveCheckpointsResponse ``` -------------------------------- ### Basic Usage: Create Chat Completion Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Demonstrates how to initialize the Together client and create a chat completion request. It shows how to pass messages and specify a model. ```javascript import Together from 'together-ai'; const client = new Together({ apiKey: process.env['TOGETHER_API_KEY'], // This is the default and can be omitted }); const chatCompletion = await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test!' }], model: 'mistralai/Mixtral-8x7B-Instruct-v0.1', }); console.log(chatCompletion.choices); ``` -------------------------------- ### Customize Fetch Client Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Switch the underlying fetch implementation by importing shims. Use `together-ai/shims/web` to prefer global web fetch (e.g., `undici`) or `together-ai/shims/node` to use `node-fetch` with polyfills. ```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-ai/shims/web'; import Together from 'together-ai'; ``` ```ts import "together-ai/shims/node" ``` -------------------------------- ### File Uploads with Different Sources Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Demonstrates various ways to pass file data for uploads, including Node.js streams, Web File API, fetch Responses, and the library's `toFile` helper. ```typescript import fs from 'fs'; import fetch from 'node-fetch'; import Together, { toFile } from 'together-ai'; const client = new Together(); // Using Node fs.createReadStream(): await client.files.upload({ file: fs.createReadStream('/path/to/file'), file_name: 'dataset.csv', purpose: 'fine-tune', }); // Using Web File API: await client.files.upload({ file: new File(['my bytes'], 'file'), file_name: 'dataset.csv', purpose: 'fine-tune', }); // Using a fetch Response: await client.files.upload({ file: await fetch('https://somesite/file'), file_name: 'dataset.csv', purpose: 'fine-tune', }); // Using the toFile helper with Buffer: await client.files.upload({ file: await toFile(Buffer.from('my bytes'), 'file'), file_name: 'dataset.csv', purpose: 'fine-tune', }); // Using the toFile helper with Uint8Array: await client.files.upload({ file: await toFile(new Uint8Array([0, 1, 2]), 'file'), file_name: 'dataset.csv', purpose: 'fine-tune', }); ``` -------------------------------- ### Models API Methods Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Manage available AI models, including listing and uploading custom models. ```APIDOC client.models.list() - Method: GET - Endpoint: /models - Description: Lists available AI models. - Returns: ModelListResponse client.models.upload({ ...params }) - Method: POST - Endpoint: /models - Description: Uploads a custom AI model. - Parameters: Accepts model files and configuration. - Returns: ModelUploadResponse ``` -------------------------------- ### Using TypeScript Definitions for Params and Responses Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Illustrates how to leverage the library's TypeScript definitions for request parameters and response fields to ensure type safety. ```typescript import Together from 'together-ai'; const client = new Together({ apiKey: process.env['TOGETHER_API_KEY'], // This is the default and can be omitted }); const params: Together.Chat.CompletionCreateParams = { messages: [{ role: 'user', content: 'Say this is a test' }], model: 'mistralai/Mixtral-8x7B-Instruct-v0.1', }; const chatCompletion: Together.Chat.ChatCompletion = await client.chat.completions.create(params); ``` -------------------------------- ### Completions API Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Handles traditional text completion requests. It allows generating text based on a prompt. ```APIDOC client.completions.create({ ...params }) - Description: Creates a text completion request. - Parameters: - params: An object containing completion parameters, such as prompt, model, max_tokens, etc. - Returns: Completion - Related: No other completion-specific methods are listed. ``` -------------------------------- ### Jobs API Methods Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Retrieve and list job statuses. ```APIDOC client.jobs.retrieve(jobId) - Method: GET - Endpoint: /jobs/{jobId} - Description: Retrieves the status of a specific job. - Parameters: - jobId (string): The unique identifier of the job. - Returns: JobRetrieveResponse client.jobs.list() - Method: GET - Endpoint: /jobs - Description: Lists all jobs. - Returns: JobListResponse ``` -------------------------------- ### Audio API Methods Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Process audio, including speech synthesis, transcription, and translation. ```APIDOC client.audio.create({ ...params }) - Method: POST - Endpoint: /audio/speech - Description: Synthesizes speech from text. - Parameters: Accepts text, voice, and model configuration. - Returns: Response (audio stream) client.audio.transcriptions.create({ ...params }) - Method: POST - Endpoint: /audio/transcriptions - Description: Transcribes audio into text. - Parameters: Accepts audio file and model configuration. - Returns: TranscriptionCreateResponse client.audio.translations.create({ ...params }) - Method: POST - Endpoint: /audio/translations - Description: Translates audio from one language to another. - Parameters: Accepts audio file and target language. - Returns: TranslationCreateResponse ``` -------------------------------- ### Images API Methods Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Generate images using AI models. ```APIDOC client.images.create({ ...params }) - Method: POST - Endpoint: /images/generations - Description: Creates an image based on a text prompt. - Parameters: Accepts prompt, model, and other generation parameters. - Returns: ImageFile ``` -------------------------------- ### Code Interpreter API Methods Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Interact with the Code Interpreter service to execute code and manage sessions. ```APIDOC client.codeInterpreter.execute({ ...params }) - Method: POST - Endpoint: /tci/execute - Description: Executes code within the Code Interpreter environment. - Parameters: Accepts code and execution context. - Returns: ExecuteResponse client.codeInterpreter.sessions.list() - Method: GET - Endpoint: /tci/sessions - Description: Lists available Code Interpreter sessions. - Returns: SessionListResponse ``` -------------------------------- ### Chat Completions API Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Manages chat-based AI completions. This includes creating chat completions with various message types and parameters. ```APIDOC client.chat.completions.create({ ...params }) - Description: Creates a chat completion request. - Parameters: - params: An object containing chat completion parameters, such as messages, model, temperature, etc. - Returns: ChatCompletion - Related: This is the primary method for chat completions. Associated types define message formats and response structures. ``` -------------------------------- ### Batches API Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Manages batch operations, including creation, retrieval, and listing. Defines response types for batch operations. ```APIDOC Batches API: Types: - BatchCreateResponse - BatchRetrieveResponse - BatchListResponse Methods: POST /batches client.batches.create({ ...params }) -> BatchCreateResponse - Creates a new batch job. - Parameters: - params: Object containing batch job configuration. - Returns: - BatchCreateResponse: Details of the created batch job. GET /batches/{id} client.batches.retrieve(id) -> BatchRetrieveResponse - Retrieves a specific batch job by its ID. - Parameters: - id: The unique identifier of the batch job. - Returns: - BatchRetrieveResponse: Details of the requested batch job. GET /batches client.batches.list() -> BatchListResponse - Lists all batch jobs. - Parameters: - None - Returns: - BatchListResponse: A list of batch jobs. ``` -------------------------------- ### Files API Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Manages file operations, including uploading, retrieving, listing, and deleting files. Supports various file types and purposes. ```APIDOC client.files.retrieve(id) - Description: Retrieves a specific file by its ID. - Parameters: - id: The unique identifier of the file. - Returns: FileRetrieveResponse - Related: client.files.list(), client.files.content(id) ``` ```APIDOC client.files.list() - Description: Lists all files associated with the account. - Parameters: None. - Returns: FileListResponse - Related: client.files.retrieve(id) ``` ```APIDOC client.files.delete(id) - Description: Deletes a specific file by its ID. - Parameters: - id: The unique identifier of the file to delete. - Returns: FileDeleteResponse - Related: client.files.upload({ ...params }) ``` ```APIDOC client.files.content(id) - Description: Retrieves the content of a specific file by its ID. - Parameters: - id: The unique identifier of the file. - Returns: Response (typically the file data). - Related: client.files.retrieve(id) ``` ```APIDOC client.files.upload({ ...params }) - Description: Uploads a file to the service. - Parameters: - params: An object containing upload parameters, including the file data and purpose. - Returns: FileUploadResponse - Related: client.files.delete(id) ``` -------------------------------- ### Endpoints API Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Manages API endpoints, including creation, retrieval, update, listing, and deletion. Associated types define request and response structures. ```APIDOC Endpoints API: Types: - Autoscaling - EndpointCreateResponse - EndpointRetrieveResponse - EndpointUpdateResponse - EndpointListResponse Methods: POST /endpoints client.endpoints.create({ ...params }) -> EndpointCreateResponse - Creates a new endpoint. - Parameters: - params: Object containing endpoint configuration details. - Returns: - EndpointCreateResponse: Details of the created endpoint. GET /endpoints/{endpointId} client.endpoints.retrieve(endpointId) -> EndpointRetrieveResponse - Retrieves a specific endpoint by its ID. - Parameters: - endpointId: The unique identifier of the endpoint. - Returns: - EndpointRetrieveResponse: Details of the requested endpoint. PATCH /endpoints/{endpointId} client.endpoints.update(endpointId, { ...params }) -> EndpointUpdateResponse - Updates an existing endpoint. - Parameters: - endpointId: The unique identifier of the endpoint to update. - params: Object containing the fields to update. - Returns: - EndpointUpdateResponse: Details of the updated endpoint. GET /endpoints client.endpoints.list({ ...params }) -> EndpointListResponse - Lists all available endpoints, with optional filtering parameters. - Parameters: - params: Object for filtering or pagination. - Returns: - EndpointListResponse: A list of endpoints. DELETE /endpoints/{endpointId} client.endpoints.delete(endpointId) -> void - Deletes a specific endpoint by its ID. - Parameters: - endpointId: The unique identifier of the endpoint to delete. - Returns: - void: Indicates successful deletion. ``` -------------------------------- ### Streaming Responses with SSE Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Shows how to handle streaming responses from the API using Server-Sent Events (SSE). It iterates over chunks of the response as they arrive. ```typescript import Together from 'together-ai'; const client = new Together(); const stream = await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'mistralai/Mixtral-8x7B-Instruct-v0.1', stream: true, }); for await (const chatCompletionChunk of stream) { console.log(chatCompletionChunk.choices); } // To cancel a stream, you can break from the loop or call stream.controller.abort(). ``` -------------------------------- ### Rerank API Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Handles the reranking of documents. It takes parameters and returns a RerankResponse. ```APIDOC client.rerank({ ...params }) - Description: Reranks a list of documents based on a query. - Parameters: - params: An object containing the reranking parameters. - Returns: RerankResponse - Related: No other rerank-specific methods are listed. ``` -------------------------------- ### Configure Custom Fetch Function Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Provides a custom fetch function to the Together client for inspecting or altering requests and responses before/after each API call. This can be used for logging or middleware purposes. ```typescript import { fetch } from 'undici'; // as one example import Together from 'together-ai'; const client = new Together({ fetch: async (url: RequestInfo, init?: RequestInit): Promise => { console.log('About to make a request', url, init); const response = await fetch(url, init); console.log('Got response', response); return response; }, }); ``` -------------------------------- ### Make Undocumented API Requests Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Make requests to undocumented endpoints using `client.get`, `client.post`, etc., and pass undocumented parameters or access undocumented response properties using `// @ts-expect-error`. ```ts await client.post('/some/path', { body: { some_prop: 'foo' }, query: { some_query_arg: 'bar' }, }); ``` ```ts client.foo.create({ foo: 'my_param', bar: 12, // @ts-expect-error baz is not yet public baz: 'undocumented option', }); ``` -------------------------------- ### Configure API Timeouts Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Set the default request timeout to 1 minute or override it for individual requests. A timeout results in an APIConnectionTimeoutError being thrown. Timed-out requests are retried twice by default. ```ts // Configure the default for all requests: const client = new Together({ timeout: 20 * 1000, // 20 seconds (default is 1 minute) }); ``` ```ts // Override per-request: await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'mistralai/Mixtral-8x7B-Instruct-v0.1' }, { timeout: 5 * 1000, }); ``` -------------------------------- ### Configure API Retries Source: https://github.com/togethercomputer/together-typescript/blob/main/README.md Configure the default number of retries for API requests or set retries on a per-request basis. The default is 2 retries, and certain errors like connection issues, timeouts, conflicts, rate limits, and server errors trigger retries. ```js // Configure the default for all requests: const client = new Together({ maxRetries: 0, // default is 2 }); ``` ```ts // Or, configure per-request: await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'mistralai/Mixtral-8x7B-Instruct-v0.1' }, { maxRetries: 5, }); ``` -------------------------------- ### Runtime Shim Registry API Source: https://github.com/togethercomputer/together-typescript/blob/main/src/_shims/README.md The `together-ai/_shims/registry` module exports a `setShims` function, which is used internally to register runtime shims. Manually importing shim files also calls this function. ```APIDOC together-ai/_shims/registry: setShims(shims: RuntimeShims): void - Registers runtime shims for the environment. - shims: An object containing fetch and Response implementations. RuntimeShims: fetch: typeof fetch Response: typeof Response Usage: // Internal usage or manual override import { setShims } from 'together-ai/_shims/registry' import { nodeFetch, nodeResponse } from 'together-ai/_shims/auto/runtime-node' setShims({ fetch: nodeFetch, Response: nodeResponse }) ``` -------------------------------- ### Manual Shim Imports Source: https://github.com/togethercomputer/together-typescript/blob/main/src/_shims/README.md Users can manually import specific shims to override the default runtime behavior. This is useful for resolving issues related to module resolution settings in TypeScript. ```typescript import 'together-ai/shims/node' import 'together-ai/shims/web' ``` -------------------------------- ### Embeddings API Source: https://github.com/togethercomputer/together-typescript/blob/main/api.md Generates embeddings for text. This is useful for semantic search, clustering, and other NLP tasks. ```APIDOC client.embeddings.create({ ...params }) - Description: Creates an embedding for the given input text. - Parameters: - params: An object containing embedding parameters, such as input text and model. - Returns: Embedding - Related: No other embedding-specific methods are listed. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.