together-ai 0.3.0 → 0.5.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 CHANGED
@@ -16,21 +16,37 @@
16
16
 
17
17
  ## Usage
18
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.
19
+ Create an account at [together.ai](https://www.together.ai/) and add the API key in. Then simply run the code snippet below with your preferred AI model and inputs to get back a reply.
20
20
 
21
21
  ```js
22
22
  import Together from 'together-ai';
23
23
 
24
24
  const together = new Together({
25
- auth: `api token`,
25
+ auth: process.env.TOGETHER_API_KEY,
26
26
  });
27
27
 
28
- const result = await together.inference('mistralai/Mistral-7B-Instruct-v0.1', {
29
- prompt: 'tell me about the history of the United States',
28
+ const model = 'mistralai/Mistral-7B-Instruct-v0.1';
29
+
30
+ const result = await together.inference(model, {
31
+ prompt: 'Suggest some fun family activities for the new year',
30
32
  max_tokens: 300,
31
33
  });
32
34
  ```
33
35
 
36
+ ### Streaming with LLMs
37
+
38
+ If you want to stream, simply specify `stream-tokens: true`.
39
+
40
+ ```js
41
+ const model = 'togethercomputer/llama-2-70b-chat';
42
+
43
+ const result = await together.inference(model, {
44
+ prompt: 'Tell me about the history of the United States',
45
+ max_tokens: 1000,
46
+ stream_tokens: true,
47
+ });
48
+ ```
49
+
34
50
  ## Popular Supported Models
35
51
 
36
52
  This is a list of popular models that are supported.
package/dist/index.d.ts CHANGED
@@ -30,6 +30,6 @@ declare class Together {
30
30
  });
31
31
  inference(model: string, { ...inputs }: {
32
32
  [x: string]: any;
33
- }): Promise<ApiResponse>;
33
+ }): Promise<ApiResponse | ReadableStream<Uint8Array>>;
34
34
  }
35
35
  export default Together;
package/dist/index.js CHANGED
@@ -39,8 +39,13 @@ class Together {
39
39
  },
40
40
  body: JSON.stringify(Object.assign({ model }, inputs)),
41
41
  });
42
- const data = yield res.json();
43
- return data;
42
+ if (inputs.stream_tokens === true) {
43
+ return res.body;
44
+ }
45
+ else {
46
+ const data = yield res.json();
47
+ return data;
48
+ }
44
49
  });
45
50
  }
46
51
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "together-ai",
3
- "version": "0.3.0",
4
- "description": "A Node SDK for Together.ai.",
3
+ "version": "0.5.0",
4
+ "description": "Node.js SDK for Together.ai.",
5
5
  "author": "Hassan El Mghari (@nutlope)",
6
6
  "repository": "Nutlope/together-js",
7
7
  "license": "MIT",
package/src/index.ts CHANGED
@@ -34,6 +34,7 @@ class Together {
34
34
  if (!this.authApiKey) {
35
35
  throw new Error('Auth key is not set!');
36
36
  }
37
+
37
38
  const res = await fetch('https://api.together.xyz/inference', {
38
39
  method: 'POST',
39
40
  headers: {
@@ -46,9 +47,12 @@ class Together {
46
47
  }),
47
48
  });
48
49
 
49
- const data: ApiResponse = await res.json();
50
-
51
- return data;
50
+ if (inputs.stream_tokens === true) {
51
+ return res.body;
52
+ } else {
53
+ const data: ApiResponse = await res.json();
54
+ return data;
55
+ }
52
56
  }
53
57
  }
54
58