together-ai 0.2.0 → 0.4.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
@@ -22,11 +22,13 @@ Add open source LLMs to your apps in a few lines of code. Simply create a new To
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
  ```
@@ -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;
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "together-ai",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "A Node SDK for Together.ai.",
5
5
  "author": "Hassan El Mghari (@nutlope)",
6
6
  "repository": "Nutlope/together-js",
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