Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
GPT4js is a package that simplifies interaction with various AI models, eliminating the need for an API Key or any other authorization method to access these chat completions and image generation models.
This package can be used in Node.js or Browser environments.
npm install gpt4js
yarn add gpt4js
bun add gpt4js
With the chatCompletion
function, you can obtain a textual response to a conversation with some context, using providers and models designed for this task. Additionally, you can manipulate the answer before converting it to a stream or force the AI to give you a certain answer by generating several retries.
It will capture the messages and the context, and any provider will respond with a string.
// CommonJS
const getGPT4js = require("gpt4js");
const GPT4js = await getGPT4js();
// ESM
import GPT4js from "gpt4js";
const messages = [{ role: "user", content: "hi!" }];
const options = {
provider: "Nextway",
model: "gpt-4o-free",
};
(async () => {
const provider = GPT4js.createProvider(options.provider);
try {
const text = await provider.chatCompletion(messages, options, (data) => {
console.log(data);
});
console.log(text);
} catch (error) {
console.error("Error:", error);
}
})();
Note: The conversation needs to include at least one message with the role user to provide a proper answer.
You can provide your own instructions for the conversation before it starts using the system role.
const messages = [
{ role: "system", content: "You're an expert bot in programming." },
{ role: "user", content: "Hi, write me something." },
];
const options = {
provider: "Nextway",
model: "gpt-4o-free",
};
(async () => {
const provider = GPT4js.createProvider(options.provider);
try {
const text = await provider.chatCompletion(messages, options, (data) => {
console.log(data);
});
console.log(text);
} catch (error) {
console.error("Error:", error);
}
})();
Role | Description |
---|---|
system | Used for providing instructions and context prior to the conversation. |
user | Used to identify user messages |
assistant | Used to identify AI messages |
Option | Type | Description |
---|---|---|
provider | string | Choose the provider to use for chat completions. Possible values include Nextway , BlackBox , etc. This determines which service will handle the request. |
model | string | Choose the model to use by a provider that supports it. For example, gpt-4 , gpt-3.5-turbo , etc. This specifies the particular language model for generating completions. |
stream | boolean | Determine if the data should be streamed in parts or not. If true , the response will be streamed in real-time as it's generated. If false , the response will be sent all at once. |
temperature | number | Set the temperature to control the randomness of the output. A value between 0 and 1 where higher values (closer to 1) make the output more random, and lower values (closer to 0) make it more deterministic. |
webSearch | boolean | Enable or disable web search functionality. If true , the system can perform web searches to gather real-time information. If false , it relies solely on pre-existing data. |
codeModelMode | boolean | Enable or disable the code model mode. If true , the system will use a model optimized for understanding and generating code. If false , it uses the general-purpose language model. |
isChromeExt | boolean | Specify whether the system is being used as a Chrome extension. If true , it indicates integration with Chrome, possibly affecting certain functionalities and permissions. |
Website | Provider | GPT-3.5 | GPT-4 | Stream | Status |
---|---|---|---|---|---|
Aryahcr | Aryahcr | ✔️ | ✔️ | ✔️ | |
BlackBox | BlackBox | ❌ | ❌ | ❌ | |
Nextway | Nextway | ✔️ | ✔️ | ✔️ | |
Chrome | Chrome | ❌ | ❌ | ✔️ | |
Ollama | Ollama | ❌ | ❌ | ✔️ | |
Alibaba | Alibaba | ✔️ | ❌ | ✔️ | |
ChatBotRu | ChatBotRu | ❌ | ✔️ | ✔️ |
Model | Providers that support it |
---|---|
gpt-4 | Aryahcr , Nextway , ChatBotRu |
gpt-4-0613 | Aryahcr |
gpt-4-32k | Aryahcr |
gpt-4-0314 | Aryahcr |
gpt-4o-free | Nextway |
gpt-4o | ChatBotRu |
gpt-4-32k-0314 | Aryahcr |
gpt-4-turbo | ChatBotRu |
gpt-3.5-turbo | Aryahcr , Nextway , Alibaba |
gpt-3.5-turbo-16k | Aryahcr |
gpt-3.5-turbo-0613 | Aryahcr |
gpt-3.5-turbo-16k-0613 | Aryahcr |
gpt-3.5-turbo-0301 | Aryahcr |
text-davinci-003 | Aryahcr |
text-davinci-002 | Aryahcr |
code-davinci-002 | Aryahcr |
gpt-3 | Aryahcr |
text-curie-001 | Aryahcr |
text-babbage-001 | Aryahcr |
text-ada-001 | Aryahcr |
davinci | Aryahcr |
curie | Aryahcr |
babbage | Aryahcr |
ada | Aryahcr |
babbage-002 | Aryahcr |
davinci-002 | Aryahcr |
gemini-pro | Nextway |
gemini-nano | Chrome |
All Ollama models | Ollama |
SparkDesk-v1.1 | Alibaba |
deepseek-coder | Alibaba |
deepseek-chat | Alibaba |
Qwen2-7B-Instruct | Alibaba |
glm4-9B-chat | Alibaba |
chatglm3-6B | Alibaba |
Yi-1.5-9B-Chat | Alibaba |
llama-3.1-405b-instruct-free | Nextway |
const options = {
provider: "DALLE2",
};
(async () => {
const provider = GPT4js.createProvider(options.provider);
try {
const base64 = await provider.imageGeneration("wood", options);
console.log(base64);
} catch (error) {
console.error("Error:", error);
}
})();
With the imageGeneration
function, you can generate images from textual input along with optional parameters to customize and stylize the images in various artistic styles.
Option | Type | Description |
---|---|---|
negativePrompt | string | Indicates the direction not to take in production. |
height | number | Specifies the image height. |
width | number | Specifies the image width. |
samplingSteps | number | Specifies the number of iterations. A higher number results in higher quality. |
samplingMethod | string | Selects a sampling method to control the diversity, quality, and coherence of images. |
cfgScale | number | Specifies the Classifier-Free Guidance to control how closely the generated image adheres to the given text prompt. |
Provider | Supported Number Type Options and Values |
---|---|
StableDiffusion | - height : Default 512, Min 50, Max 1024- width : Default 512, Min 50, Max 1024- samplingSteps : Default 25, Min 1, Max 30- cfgScale : Default 7, Min 1, Max 20 |
Provider | Status | Default Style |
---|---|---|
Dalle2 | Semi-realistic, detailed with vivid colors and natural lighting. | |
StableDiffusion | Photorealistic, capturing fine details and textures to simulate real-life scenes. |
Warning: This is an experimental feature and may not work correctly, it only works in Google Chrome 127 or higher (Chrome Dev). Also history is not supported
chrome://flags/#prompt-api-for-gemini-nano Select 'Enabled'
chrome://flags/#optimization-guide-on-device-model Select 'Enabled BypassPrefRequirement'
chrome://components Click 'Check for Update' on Optimization Guide On Device Model to download the model. If you don't see Optimization Guide, ensure you have set the flags correctly above, relaunch your browser, and refresh the page.
const messages = [{ role: "user", content: "hi!" }];
const options = {
provider: "Chrome",
};
(async () => {
const provider = GPT4js.createProvider(options.provider);
try {
const text = await provider.chatCompletion(messages, options, (data) => {
console.log(data);
});
console.log(text);
} catch (error) {
console.error("Error:", error);
}
})();
Running: npm test
npm run build
- Build using Webpack.npm run dev
- Live development build with Webpack.npm run build:bun
- Build using Bun.npm run dev:bun
- Live development build with Bun.If you'd like to contribute to this project, you can do so directly on GitHub. Additionally, if you encounter any errors that hinder your use of any project functionality, please report them here. Your feedback helps our community access AI tools freely!
FAQs
Using ChatGPT4/3.5-turbo/Gemini-Pro/BlackBox and etc. unlimited and free.
The npm package gpt4js receives a total of 2,013 weekly downloads. As such, gpt4js popularity was classified as popular.
We found that gpt4js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.