Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.31.1"
".": "0.31.2"
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
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": "together-ai",
"version": "0.31.1",
"version": "0.31.2",
"description": "The official TypeScript library for the Together API",
"author": "Together <dev-feedback@TogetherAI.com>",
"types": "dist/index.d.ts",
Expand Down
14 changes: 5 additions & 9 deletions src/lib/check-file.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -63,7 +59,7 @@ export async function checkFile(
file: string,
purpose: FilePurpose | string = 'fine-tune',
): Promise<CheckFileReport> {
const filePath = path.resolve(file);
const filePath = resolve(file);

const report_dict: CheckFileReport = {
is_check_passed: true,
Expand All @@ -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;
Expand Down Expand Up @@ -112,7 +108,7 @@ export async function checkFile(
}

let data_report_dict: Partial<CheckFileReport> = {};
const ext = path.extname(filePath);
const ext = extname(filePath);

try {
if (ext === '.jsonl') {
Expand Down Expand Up @@ -378,7 +374,7 @@ export function validate_preference_openai(example: Record<string, any>, idx: nu

async function _check_utf8(file: string): Promise<Partial<CheckFileReport>> {
const report_dict: Partial<CheckFileReport> = {};
const content = await fs.readFile(file);
const content = await readFile(file);
report_dict.utf8 = isUtf8(content);

if (!report_dict.utf8) {
Expand Down
39 changes: 39 additions & 0 deletions src/lib/node-unsafe-imports.ts
Original file line number Diff line number Diff line change
@@ -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,
};
10 changes: 4 additions & 6 deletions src/lib/upload.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '0.31.1'; // x-release-please-version
export const VERSION = '0.31.2'; // x-release-please-version