together-ai 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ <div align="center">
2
+ <div>
3
+ <h1 align="center">Together.ai Node SDK</h1>
4
+ </div>
5
+ <p>An npm library to run open source LLMs through <a href="https://www.together.ai/">Together.ai</a>.
6
+
7
+ <a href="https://www.npmjs.com/package/together-ai"><img src="https://img.shields.io/npm/v/together-ai" alt="Current version"></a>
8
+
9
+ </div>
10
+
11
+ ---
12
+
13
+ ## Installation
14
+
15
+ `npm i together-ai`
16
+
17
+ ## Usage
18
+
19
+ Add open source LLMs to your apps in a few lines of code. Simply create a new Together.ai client, specify your preferred AI model with inputs, and get back a result.
20
+
21
+ ```js
22
+ import Together from 'together-ai';
23
+
24
+ const together = new Together({
25
+ auth: `api token`,
26
+ });
27
+
28
+ const result = await together.inference('mistralai/Mistral-7B-Instruct-v0.1', {
29
+ prompt: 'tell me about the history of the United States',
30
+ max_tokens: 300,
31
+ });
32
+ ```
33
+
34
+ ## Popular Supported Models
35
+
36
+ This is a list of popular models that are supported.
37
+
38
+ - Mistral-7B (`mistralai/Mistral-7B-Instruct-v0.1`)
39
+ - Llama-2 70B (`togethercomputer/llama-2-70b-chat`)
40
+ - Llama-2 13B (`togethercomputer/llama-2-13b-chat`)
41
+ - RedPajama 7B (`togethercomputer/RedPajama-INCITE-7B-Chat`)
42
+ - OpenOrca Mistral (`Open-Orca/Mistral-7B-OpenOrca`)
43
+ - Alpaca 7B (`togethercomputer/alpaca-7b`)
44
+
45
+ ## How it works
46
+
47
+ This library uses the [Together Inference Engine](https://www.together.ai/blog/together-inference-engine-v1), the world's fastest inference stack for open source LLMs. It calls the [Together.ai](<[together.ai](https://www.together.ai/)>) Inference API under the hood to enable you to use OSS LLMs quickly.
package/demo/test.ts ADDED
@@ -0,0 +1,25 @@
1
+ import Together from '../src';
2
+
3
+ const together = new Together({
4
+ auth: 'dd706fe7edbe3a935c46a939fa62a02443666e8b3959caeef70458da5d6cff7c',
5
+ });
6
+
7
+ async function main() {
8
+ const result = await together.inference(
9
+ 'mistralai/Mistral-7B-Instruct-v0.1',
10
+ {
11
+ prompt: 'tell me about the history of the United States of America',
12
+ max_tokens: 300,
13
+ }
14
+ );
15
+
16
+ // console.log({ output });
17
+ console.log({ choices: result.output.choices[0].text });
18
+ }
19
+
20
+ main();
21
+
22
+ // Together feedback
23
+
24
+ // language model was confusing, specify it better in dashboard
25
+ // Better defaults like max tokens
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "together-ai",
3
+ "version": "0.1.0",
4
+ "description": "A Node SDK for Together.ai.",
5
+ "author": "Hassan El Mghari (@nutlope)",
6
+ "repository": "Nutlope/together-js",
7
+ "license": "MIT",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "scripts": {
11
+ "build": "tsc"
12
+ },
13
+ "devDependencies": {
14
+ "@types/node": "^20.6.3",
15
+ "typescript": "^5.2.2"
16
+ },
17
+ "dependencies": {},
18
+ "keywords": [
19
+ "together ai",
20
+ "LLMs",
21
+ "open source",
22
+ "AI models",
23
+ "mistral",
24
+ "Llama"
25
+ ]
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,55 @@
1
+ type ApiResponse = {
2
+ status: string;
3
+ prompt: string[];
4
+ model: string;
5
+ model_owner: string;
6
+ tags: Record<string, unknown>;
7
+ num_returns: number;
8
+ args: {
9
+ model: string;
10
+ prompt: string;
11
+ max_tokens: number;
12
+ stop: string;
13
+ temperature: number;
14
+ top_p: number;
15
+ top_k: number;
16
+ repetition_penalty: number;
17
+ };
18
+ subjobs: any[];
19
+ output: {
20
+ choices: {
21
+ text: string;
22
+ }[];
23
+ request_id: string;
24
+ };
25
+ };
26
+
27
+ class Together {
28
+ authApiKey: string | null = null;
29
+ constructor({ auth }: { auth: string }) {
30
+ this.authApiKey = auth;
31
+ }
32
+
33
+ async inference(model: string, { ...inputs }) {
34
+ if (!this.authApiKey) {
35
+ throw new Error('Auth key is not set!');
36
+ }
37
+ const res = await fetch('https://api.together.xyz/inference', {
38
+ method: 'POST',
39
+ headers: {
40
+ 'Content-Type': 'application/json',
41
+ Authorization: 'Bearer ' + this.authApiKey,
42
+ },
43
+ body: JSON.stringify({
44
+ model,
45
+ ...inputs,
46
+ }),
47
+ });
48
+
49
+ const data: ApiResponse = await res.json();
50
+
51
+ return data;
52
+ }
53
+ }
54
+
55
+ export default Together;
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2016",
4
+ "module": "commonjs",
5
+ "outDir": "./dist",
6
+ "declaration": true,
7
+ "esModuleInterop": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "skipLibCheck": true
10
+ }
11
+ }