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:
|
|
25
|
+
auth: process.env.TOGETHER_API_KEY,
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
const
|
|
29
|
-
|
|
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
|
```
|
|
@@ -39,8 +39,13 @@ class Together {
|
|
|
39
39
|
},
|
|
40
40
|
body: JSON.stringify(Object.assign({ model }, inputs)),
|
|
41
41
|
});
|
|
42
|
-
|
|
43
|
-
|
|
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
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|