Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 0.11.0 #100

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.10.0"
".": "0.11.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 16
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai%2FTogetherAI-692e6d7ba3069e890bfe0fcb77a92f52bd5991cc571acaae6e679e4190a936e1.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai%2FTogetherAI-890ae6b21096103dfc5905cbb90612ca33f46c8a6712b3620d4f44173626f8e5.yml
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Changelog

## 0.11.0 (2025-01-02)

Full Changelog: [v0.10.0...v0.11.0](https://github.com/togethercomputer/together-typescript/compare/v0.10.0...v0.11.0)

### Features

* added messages format check ([d2fa4db](https://github.com/togethercomputer/together-typescript/commit/d2fa4dbdb977bea56053cd148f3b0406c9081682))
* **api:** add models for chat completion structured message types ([#107](https://github.com/togethercomputer/together-typescript/issues/107)) ([d32c311](https://github.com/togethercomputer/together-typescript/commit/d32c3110fd50470cbb563bfa5213fb6bf831ecc6))
* **api:** api update ([#99](https://github.com/togethercomputer/together-typescript/issues/99)) ([dea8e5c](https://github.com/togethercomputer/together-typescript/commit/dea8e5cc8411e74082da8ef722a05ae5053cd67e))
* **internal:** make git install file structure match npm ([#101](https://github.com/togethercomputer/together-typescript/issues/101)) ([28e49f0](https://github.com/togethercomputer/together-typescript/commit/28e49f0a30df60c7bf22b5b93bf613a335a39bf6))


### Bug Fixes

* **client:** normalize method ([#112](https://github.com/togethercomputer/together-typescript/issues/112)) ([fa1095f](https://github.com/togethercomputer/together-typescript/commit/fa1095fc1486808bd6e1755bdb38cd90c33b9ad1))


### Chores

* **internal:** bump cross-spawn to v7.0.6 ([#106](https://github.com/togethercomputer/together-typescript/issues/106)) ([0ef9509](https://github.com/togethercomputer/together-typescript/commit/0ef95095c9fad01f6c2f234256577e62bf9ce4b3))
* **internal:** codegen related update ([#114](https://github.com/togethercomputer/together-typescript/issues/114)) ([4f49cd8](https://github.com/togethercomputer/together-typescript/commit/4f49cd827e78be83c7e2a2aeabd7b8cdb876158f))
* **internal:** fix some typos ([#111](https://github.com/togethercomputer/together-typescript/issues/111)) ([792be82](https://github.com/togethercomputer/together-typescript/commit/792be82a89bdcf7756fb3d76581b1280476f679c))
* **internal:** remove unnecessary getRequestClient function ([#103](https://github.com/togethercomputer/together-typescript/issues/103)) ([3acec90](https://github.com/togethercomputer/together-typescript/commit/3acec909ed2b726b202d7545815dc1c82c4f2f1d))
* **internal:** update isAbsoluteURL ([#110](https://github.com/togethercomputer/together-typescript/issues/110)) ([140ecda](https://github.com/togethercomputer/together-typescript/commit/140ecdaf09b29e2985842908e48fcd59a65fb35b))
* **types:** nicer error class types + jsdocs ([#109](https://github.com/togethercomputer/together-typescript/issues/109)) ([5517ee0](https://github.com/togethercomputer/together-typescript/commit/5517ee060871b4f98dce6c7b396efb948329dfae))


### Documentation

* minor formatting changes ([#113](https://github.com/togethercomputer/together-typescript/issues/113)) ([18f6773](https://github.com/togethercomputer/together-typescript/commit/18f67732cdb061925e4fbfd2fe1f0a7d53c5c446))

## 0.10.0 (2024-11-27)

Full Changelog: [v0.9.0...v0.10.0](https://github.com/togethercomputer/together-typescript/compare/v0.9.0...v0.10.0)
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Setting up the environment

This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable).
This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install).
Other package managers may work but are not officially supported for development.

To set up the repository, run:
Expand Down Expand Up @@ -29,10 +29,10 @@ All files in the `examples/` directory are not modified by the generator and can
```

```
chmod +x examples/<your-example>.ts
```sh
$ chmod +x examples/<your-example>.ts
# run the example against your api
yarn tsn -T examples/<your-example>.ts
$ yarn tsn -T examples/<your-example>.ts
```

## Using the repository from source
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2024 Together
Copyright 2025 Together

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 2 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Types:
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionSystemMessageParam</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionTool</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionToolMessageParam</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionStructuredMessageImageURL</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionStructuredMessageText</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionUsage</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionUserMessageParam</a></code>

Expand Down
100 changes: 100 additions & 0 deletions examples/sample_messages_format.jsonl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/uploading-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { upload } from 'together-ai/lib/upload';

async function main() {
// Upload a file
const file = await upload('./examples/sample_finetuning.jsonl');
const file = await upload('./examples/sample_messages_format.jsonl');
console.log('Uploaded file');
console.log(file);
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "together-ai",
"version": "0.10.0",
"version": "0.11.0",
"description": "The official TypeScript library for the Together API",
"author": "Together <[email protected]>",
"types": "dist/index.d.ts",
Expand All @@ -18,7 +18,7 @@
"build": "./scripts/build",
"prepublishOnly": "echo 'to publish, run yarn build && (cd dist; yarn publish)' && exit 1",
"format": "prettier --write --cache --cache-strategy metadata . !dist",
"prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build; fi",
"prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build && ./scripts/utils/git-swap.sh; fi",
"tsn": "ts-node -r tsconfig-paths/register",
"lint": "./scripts/lint",
"fix": "./scripts/format"
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils/check-is-in-git-install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Check if you happen to call prepare for a repository that's already in node_modules.
[ "$(basename "$(dirname "$PWD")")" = 'node_modules' ] ||
# The name of the containing directory that 'npm` uses, which looks like
Expand Down
13 changes: 13 additions & 0 deletions scripts/utils/git-swap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -exuo pipefail
# the package is published to NPM from ./dist
# we want the final file structure for git installs to match the npm installs, so we

# delete everything except ./dist and ./node_modules
find . -maxdepth 1 -mindepth 1 ! -name 'dist' ! -name 'node_modules' -exec rm -rf '{}' +

# move everything from ./dist to .
mv dist/* .

# delete the now-empty ./dist
rmdir dist
32 changes: 18 additions & 14 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export abstract class APIClient {
maxRetries = 5,
timeout = 60000, // 1 minute
httpAgent,
fetch: overridenFetch,
fetch: overriddenFetch,
}: {
baseURL: string;
maxRetries?: number | undefined;
Expand All @@ -190,7 +190,7 @@ export abstract class APIClient {
this.timeout = validatePositiveInteger('timeout', timeout);
this.httpAgent = httpAgent;

this.fetch = overridenFetch ?? fetch;
this.fetch = overriddenFetch ?? fetch;
}

protected authHeaders(opts: FinalRequestOptions): Headers {
Expand Down Expand Up @@ -536,20 +536,24 @@ export abstract class APIClient {

const timeout = setTimeout(() => controller.abort(), ms);

const fetchOptions = {
signal: controller.signal as any,
...options,
};
if (fetchOptions.method) {
// Custom methods like 'patch' need to be uppercased
// See https://github.com/nodejs/undici/issues/2294
fetchOptions.method = fetchOptions.method.toUpperCase();
}

return (
this.getRequestClient()
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
.fetch.call(undefined, url, { signal: controller.signal as any, ...options })
.finally(() => {
clearTimeout(timeout);
})
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
this.fetch.call(undefined, url, fetchOptions).finally(() => {
clearTimeout(timeout);
})
);
}

protected getRequestClient(): RequestClient {
return { fetch: this.fetch };
}

private shouldRetry(response: Response): boolean {
// Note this is not a standard header.
const shouldRetryHeader = response.headers.get('x-should-retry');
Expand Down Expand Up @@ -992,8 +996,8 @@ export const safeJSON = (text: string) => {
}
};

// https://stackoverflow.com/a/19709846
const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
// https://url.spec.whatwg.org/#url-scheme-string
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
const isAbsoluteURL = (url: string): boolean => {
return startsWithSchemeRegexp.test(url);
};
Expand Down
64 changes: 24 additions & 40 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import { castToError, Headers } from './core';

export class TogetherError extends Error {}

export class APIError extends TogetherError {
readonly status: number | undefined;
readonly headers: Headers | undefined;
readonly error: Object | undefined;

constructor(
status: number | undefined,
error: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
export class APIError<
TStatus extends number | undefined = number | undefined,
THeaders extends Headers | undefined = Headers | undefined,
TError extends Object | undefined = Object | undefined,
> extends TogetherError {
/** HTTP status for the response that caused the error */
readonly status: TStatus;
/** HTTP headers for the response that caused the error */
readonly headers: THeaders;
/** JSON body of the response that caused the error */
readonly error: TError;

constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
super(`${APIError.makeMessage(status, error, message)}`);
this.status = status;
this.headers = headers;
Expand Down Expand Up @@ -48,7 +50,7 @@ export class APIError extends TogetherError {
message: string | undefined,
headers: Headers | undefined,
): APIError {
if (!status) {
if (!status || !headers) {
return new APIConnectionError({ message, cause: castToError(errorResponse) });
}

Expand Down Expand Up @@ -90,17 +92,13 @@ export class APIError extends TogetherError {
}
}

export class APIUserAbortError extends APIError {
override readonly status: undefined = undefined;

export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
constructor({ message }: { message?: string } = {}) {
super(undefined, undefined, message || 'Request was aborted.', undefined);
}
}

export class APIConnectionError extends APIError {
override readonly status: undefined = undefined;

export class APIConnectionError extends APIError<undefined, undefined, undefined> {
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
super(undefined, undefined, message || 'Connection error.', undefined);
// in some environments the 'cause' property is already declared
Expand All @@ -115,32 +113,18 @@ export class APIConnectionTimeoutError extends APIConnectionError {
}
}

export class BadRequestError extends APIError {
override readonly status: 400 = 400;
}
export class BadRequestError extends APIError<400, Headers> {}

export class AuthenticationError extends APIError {
override readonly status: 401 = 401;
}
export class AuthenticationError extends APIError<401, Headers> {}

export class PermissionDeniedError extends APIError {
override readonly status: 403 = 403;
}
export class PermissionDeniedError extends APIError<403, Headers> {}

export class NotFoundError extends APIError {
override readonly status: 404 = 404;
}
export class NotFoundError extends APIError<404, Headers> {}

export class ConflictError extends APIError {
override readonly status: 409 = 409;
}
export class ConflictError extends APIError<409, Headers> {}

export class UnprocessableEntityError extends APIError {
override readonly status: 422 = 422;
}
export class UnprocessableEntityError extends APIError<422, Headers> {}

export class RateLimitError extends APIError {
override readonly status: 429 = 429;
}
export class RateLimitError extends APIError<429, Headers> {}

export class InternalServerError extends APIError {}
export class InternalServerError extends APIError<number, Headers> {}
22 changes: 19 additions & 3 deletions src/lib/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,33 @@ export async function check_jsonl(fileName: string): Promise<string | undefined>
continue;
}

if (!('text' in parsedLine)) {
const isTextFormat = 'text' in parsedLine;
const isMessagesFormat = 'messages' in parsedLine;

if (!isTextFormat && !isMessagesFormat) {
errors.push(
`Missing 'text' field was found on line ${lineNumber} of the the input file. Expected format: {'text': 'my sample string'}.`,
`Invalid format found on line ${lineNumber} of the the input file. Expected format: {'text': 'my sample string'} or {'messages': [{role: 'role', content: 'content'}]}.`,
);
continue;
}

if (typeof parsedLine['text'] !== 'string') {
if (isTextFormat && typeof parsedLine['text'] !== 'string') {
errors.push(`'Invalid value type for "text" key on line ${lineNumber}. Expected string`);
continue;
}

if (isMessagesFormat) {
const firstMessage = parsedLine['messages'][0];
// console.log({ firstMessage });
const firstLineHasRole = typeof firstMessage['role'] === 'string';
const firstLineHasContent = typeof firstMessage['content'] === 'string';
if (!firstLineHasRole || !firstLineHasContent) {
errors.push(
`Invalid format found on line ${lineNumber} of the the input file. Expected format: {'messages': [{role: 'role', content: 'content'}]}.`,
);
continue;
}
}
} catch (error) {
errors.push(`Error parsing line number ${lineNumber}`);
}
Expand Down
4 changes: 4 additions & 0 deletions src/resources/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
ChatCompletionSystemMessageParam,
ChatCompletionTool,
ChatCompletionToolMessageParam,
ChatCompletionStructuredMessageImageURL,
ChatCompletionStructuredMessageText,
ChatCompletionUsage,
ChatCompletionUserMessageParam,
CompletionCreateParams,
Expand All @@ -38,6 +40,8 @@ export declare namespace Chat {
type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
type ChatCompletionTool as ChatCompletionTool,
type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
type ChatCompletionStructuredMessageImageURL as ChatCompletionStructuredMessageImageURL,
type ChatCompletionStructuredMessageText as ChatCompletionStructuredMessageText,
type ChatCompletionUsage as ChatCompletionUsage,
type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
type CompletionCreateParams as CompletionCreateParams,
Expand Down
Loading
Loading