diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 85df4711..6fef4e56 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.31.1" + ".": "0.31.2" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be647a9..20d0ddab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 0.31.2 (2025-12-01) + +Full Changelog: [v0.31.1...v0.31.2](https://github.com/togethercomputer/together-typescript/compare/v0.31.1...v0.31.2) + +### Bug Fixes + +* allow build to function in browser environments ([89cf3bf](https://github.com/togethercomputer/together-typescript/commit/89cf3bfc5e6b97cb31d941f8a60e338dd79cc4ab)) + + +### Chores + +* fix internal bad type reference ([1c646b3](https://github.com/togethercomputer/together-typescript/commit/1c646b3b58be268d3554baf6054c0dea8efac481)) +* fix tests ([4fcedb5](https://github.com/togethercomputer/together-typescript/commit/4fcedb5d5a5b81847245e065618a195cd7d93be4)) + ## 0.31.1 (2025-12-01) Full Changelog: [v0.31.0...v0.31.1](https://github.com/togethercomputer/together-typescript/compare/v0.31.0...v0.31.1) diff --git a/package.json b/package.json index c4581e0b..679f19a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "together-ai", - "version": "0.31.1", + "version": "0.31.2", "description": "The official TypeScript library for the Together API", "author": "Together ", "types": "dist/index.d.ts", diff --git a/src/lib/check-file.ts b/src/lib/check-file.ts index 99f2a925..c843b2cf 100644 --- a/src/lib/check-file.ts +++ b/src/lib/check-file.ts @@ -1,9 +1,5 @@ -import fs from 'fs/promises'; -import * as path from 'path'; -import readline from 'readline'; import { FilePurpose } from '../resources'; -import { createReadStream } from 'fs'; -import { isUtf8 } from 'buffer'; +import { createReadStream, readline, isUtf8, resolve, stat, extname, readFile } from './node-unsafe-imports'; // Constants const MIN_SAMPLES = 1; @@ -63,7 +59,7 @@ export async function checkFile( file: string, purpose: FilePurpose | string = 'fine-tune', ): Promise { - const filePath = path.resolve(file); + const filePath = resolve(file); const report_dict: CheckFileReport = { is_check_passed: true, @@ -81,7 +77,7 @@ export async function checkFile( }; try { - const stats = await fs.stat(filePath); + const stats = await stat(filePath); if (!stats.isFile()) { report_dict.found = false; report_dict.is_check_passed = false; @@ -112,7 +108,7 @@ export async function checkFile( } let data_report_dict: Partial = {}; - const ext = path.extname(filePath); + const ext = extname(filePath); try { if (ext === '.jsonl') { @@ -378,7 +374,7 @@ export function validate_preference_openai(example: Record, idx: nu async function _check_utf8(file: string): Promise> { const report_dict: Partial = {}; - const content = await fs.readFile(file); + const content = await readFile(file); report_dict.utf8 = isUtf8(content); if (!report_dict.utf8) { diff --git a/src/lib/node-unsafe-imports.ts b/src/lib/node-unsafe-imports.ts new file mode 100644 index 00000000..79535b0e --- /dev/null +++ b/src/lib/node-unsafe-imports.ts @@ -0,0 +1,39 @@ +/* + * Importing node APIs breaks the SDK in the browser. + * The ideal scenario is that we do not use nodejs exclusive APIs in this codebase + * + * In the interim, this file provides a way to import the APIs in a way that will not break the SDK in the browser. + */ + +import { type stat, type readFile } from 'fs/promises'; +import { type createReadStream } from 'fs'; +import { type extname, type resolve } from 'path'; +import type readline from 'readline'; +import { type isUtf8 } from 'buffer'; + +let statMethod: typeof stat; +let resolveMethod: typeof resolve; +let createReadStreamMethod: typeof createReadStream; +let extnameMethod: typeof extname; +let readlineMethod: typeof readline; +let isUtf8Method: typeof isUtf8; +let readFileMethod: typeof readFile; +try { + statMethod = require('fs/promises').stat; + createReadStreamMethod = require('fs').createReadStream; + extnameMethod = require('path').extname; + readlineMethod = require('readline'); + isUtf8Method = require('buffer').isUtf8; + resolveMethod = require('path').resolve; + readFileMethod = require('fs/promises').readFile; +} catch {} + +export { + statMethod as stat, + createReadStreamMethod as createReadStream, + extnameMethod as extname, + readlineMethod as readline, + isUtf8Method as isUtf8, + resolveMethod as resolve, + readFileMethod as readFile, +}; diff --git a/src/lib/upload.ts b/src/lib/upload.ts index 9d4141de..d9e05653 100644 --- a/src/lib/upload.ts +++ b/src/lib/upload.ts @@ -1,11 +1,9 @@ // Upload file to server using /files API import { readEnv } from '../internal/utils/env'; -import fs from 'fs/promises'; -import { createReadStream } from 'fs'; -import * as path from 'path'; import { FilePurpose, FileResponse } from '../resources'; import { checkFile } from './check-file'; +import { createReadStream, stat, extname } from './node-unsafe-imports'; import { Together } from '../client'; import { APIPromise } from '../core/api-promise'; @@ -31,13 +29,13 @@ export function upload( let fileSize = 0; try { - const stat = await fs.stat(fileName); - fileSize = stat.size; + const stats = await stat(fileName); + fileSize = stats.size; } catch { reject(new Error('File does not exists')); } - const fileType = path.extname(fileName).replace('.', ''); + const fileType = extname(fileName).replace('.', ''); if (fileType !== 'jsonl' && fileType !== 'parquet' && fileType !== 'csv') { return { message: 'File type must be either .jsonl, .parquet, or .csv', diff --git a/src/version.ts b/src/version.ts index c71c0da2..a942d18d 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.31.1'; // x-release-please-version +export const VERSION = '0.31.2'; // x-release-please-version