New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.0.18 to 1.1.0

data/gpt2_merges_file.txt

44

index.js

@@ -5,2 +5,3 @@ "use strict";

axios = require('axios');
const { ByteLevelBPETokenizer } = require('tokenizers');

@@ -45,22 +46,31 @@ class OpenAI {

complete(opts) {
return this._send_request(opts);
}
complete(opts) {
return this._send_request(opts);
}
search(opts) {
const url = config.searchURL(opts.engine);
const reqOpts = {
headers: {
'Authorization': `Bearer ${this._api_key}`,
'Content-Type': 'application/json'
}
};
const data = {
documents: opts.documents,
query: opts.query
};
return axios.post(url, data, reqOpts);
encode(str) {
return ByteLevelBPETokenizer.fromOptions({
vocabFile: './data/gpt2_vocab_file.json',
mergesFile: './data/gpt2_merges_file.txt',
}).then((tokenizer) => {
return tokenizer.encode(str)
})
}
search(opts) {
const url = config.searchURL(opts.engine);
const reqOpts = {
headers: {
'Authorization': `Bearer ${this._api_key}`,
'Content-Type': 'application/json'
}
};
const data = {
documents: opts.documents,
query: opts.query
};
return axios.post(url, data, reqOpts);
}
}
}
module.exports = OpenAI;
{
"name": "openai-api",
"version": "1.0.18",
"version": "1.1.0",
"description": "A tiny client module for the openAI API",

@@ -25,7 +25,9 @@ "main": "index.js",

"dependencies": {
"axios": "^0.21.1"
"axios": "^0.21.1",
"tokenizers": "^0.7.0"
},
"devDependencies": {
"mocha": "^8.1.1"
"chai": "^4.3.4",
"mocha": "^8.3.2"
}
}

@@ -69,3 +69,14 @@ # 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).
```json
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
```js

@@ -81,4 +92,10 @@ (async () => {

})();
(async () => {
await const encoded = openai.encode(str);
// to get the number of tokens of this string
console.log(encoded.length);
})();
```
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