openai-api
Advanced tools
Comparing version 1.1.1 to 1.1.2
11
index.js
@@ -5,4 +5,3 @@ "use strict"; | ||
axios = require('axios'); | ||
const { ByteLevelBPETokenizer } = require('tokenizers'); | ||
class OpenAI { | ||
@@ -51,8 +50,4 @@ constructor(api_key) { | ||
encode(str) { | ||
return ByteLevelBPETokenizer.fromOptions({ | ||
vocabFile: './data/gpt2_vocab_file.json', | ||
mergesFile: './data/gpt2_merges_file.txt', | ||
}).then((tokenizer) => { | ||
return tokenizer.encode(str) | ||
}) | ||
// This method is no longer supported in Node>=v14. See | ||
return Promise.resolve(new Array(2047).fill("")); | ||
} | ||
@@ -59,0 +54,0 @@ |
{ | ||
"name": "openai-api", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A tiny client module for the openAI API", | ||
@@ -25,4 +25,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"axios": "^0.21.1", | ||
"tokenizers": "^0.7.0" | ||
"axios": "^0.21.1" | ||
}, | ||
@@ -29,0 +28,0 @@ "devDependencies": { |
@@ -69,12 +69,2 @@ # openai-api | ||
### Get number of tokens for string | ||
The token limit is 2048 for completions using the OpenAI API. This method allows you to get the number of tokens in your prompt. This is done offline (no API call is made). | ||
```js | ||
openai.encode('This is an encoding test. Number of tokens is not necessarily the same as word count.').then((result) => { | ||
console.log("Number of tokens for string:" + result.length); | ||
}); | ||
``` | ||
### Search API call | ||
@@ -92,10 +82,13 @@ | ||
})(); | ||
``` | ||
(async () => { | ||
await const encoded = openai.encode(str); | ||
// to get the number of tokens of this string | ||
console.log(encoded.length); | ||
})(); | ||
### Get number of tokens for string | ||
#### Not supported as of 4/21. See issue #20 | ||
The token limit is 2048 for completions using the OpenAI API. This method allows you to get the number of tokens in your prompt. This is done offline (no API call is made). | ||
```js | ||
openai.encode('This is an encoding test. Number of tokens is not necessarily the same as word count.').then((result) => { | ||
console.log("Number of tokens for string:" + result.length); | ||
}); | ||
``` | ||
@@ -11,7 +11,9 @@ const api_key = process.env.OPENAI_TEST_API_KEY; | ||
describe('basic openai api methods', function () { | ||
this.timeout(4000); | ||
const openai = new OpenAI(api_key); | ||
it ('handle simple completion', function (done) { | ||
it ('should handle simple completion', function (done) { | ||
openai.complete({ | ||
engine: 'ada', | ||
prompt: "this is a test", | ||
@@ -33,4 +35,5 @@ maxTokens: 5, | ||
it ('handle search', function (done) { | ||
it ('should handle search', function (done) { | ||
openai.search({ | ||
engine: 'ada', | ||
documents: ["White House", "hospital", "school"], | ||
@@ -48,6 +51,6 @@ query: "the president" | ||
it ('handle encoding', function (done) { | ||
openai.encode('This is an encoding test. Number of tokens is not necessarily the same as word count.').then((result) => { | ||
expect(result.length).to.be.ok; | ||
expect(result.length).to.be.eql(18); | ||
it ('should return a default value from the encode function', function (done) { | ||
openai.encode('this is a string').then((result) => { | ||
expect(result).to.be.ok; | ||
expect(result.length).to.be.eql(2047); | ||
done(); | ||
@@ -54,0 +57,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
7319
5
128
93
- Removedtokenizers@^0.7.0
- Removed@types/node@13.13.52(transitive)
- Removedabbrev@1.1.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedaproba@1.2.0(transitive)
- Removedare-we-there-yet@1.1.7(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedchownr@1.1.4(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconsole-control-strings@1.1.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddebug@3.2.7(transitive)
- Removeddeep-extend@0.6.0(transitive)
- Removeddelegates@1.0.0(transitive)
- Removeddetect-libc@1.0.3(transitive)
- Removedfs-minipass@1.2.7(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedgauge@2.7.4(transitive)
- Removedglob@7.2.3(transitive)
- Removedhas-unicode@2.0.1(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedignore-walk@3.0.4(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedini@1.3.8(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedisarray@1.0.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedminipass@2.9.0(transitive)
- Removedminizlib@1.3.3(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedms@2.1.3(transitive)
- Removedneedle@2.9.1(transitive)
- Removednode-pre-gyp@0.14.0(transitive)
- Removednopt@4.0.3(transitive)
- Removednpm-bundled@1.1.2(transitive)
- Removednpm-normalize-package-bin@1.0.1(transitive)
- Removednpm-packlist@1.4.8(transitive)
- Removednpmlog@4.1.2(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedosenv@0.1.5(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedrc@1.2.8(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedsafe-buffer@5.1.25.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsax@1.4.1(transitive)
- Removedsemver@5.7.2(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedtar@4.4.19(transitive)
- Removedtokenizers@0.7.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwide-align@1.1.5(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedyallist@3.1.1(transitive)