Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openai-api

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openai-api - npm Package Compare versions

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 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc