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

gpt4js

Package Overview
Dependencies
Maintainers
0
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gpt4js

Using ChatGPT4/3.5-turbo/Gemini-Pro/BlackBox and etc. unlimited and free.

  • 1.7.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.4K
increased by51.78%
Maintainers
0
Weekly downloads
 
Created
Source

GPT4js 🔮

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.

Static Badge GitHub top language GitHub Repo stars GitHub issues NPM Downloads

📚 Table of Contents

🛠️ Installation

Using NPM

npm install gpt4js

Using Yarn

yarn add gpt4js

Using Bun

bun add gpt4js

🧩 Examples

📤 Chat Completion

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.

⚙️ Basic Usage

Simple Fetch

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.

Give Your Instructions

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);
  }
})();

Conversation Roles
RoleDescription
systemUsed for providing instructions and context prior to the conversation.
userUsed to identify user messages
assistantUsed to identify AI messages

🔩 Configurable Options

OptionTypeDescription
providerstringChoose the provider to use for chat completions. Possible values include Nextway, BlackBox, etc. This determines which service will handle the request.
modelstringChoose 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.
streambooleanDetermine 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.
temperaturenumberSet 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.
webSearchbooleanEnable 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.
codeModelModebooleanEnable 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.
isChromeExtbooleanSpecify whether the system is being used as a Chrome extension. If true, it indicates integration with Chrome, possibly affecting certain functionalities and permissions.

🚀 Chat Completion Providers

WebsiteProviderGPT-3.5GPT-4StreamStatus
AryahcrAryahcr✔️✔️✔️Active
BlackBoxBlackBoxActive
NextwayNextway✔️✔️✔️Active
ChromeChrome✔️Active
OllamaOllama✔️Active
AlibabaAlibaba✔️✔️Active
ChatBotRuChatBotRu✔️✔️Inactive

📚 Chat Completion Models

ModelProviders that support it
gpt-4Aryahcr, Nextway, ChatBotRu
gpt-4-0613Aryahcr
gpt-4-32kAryahcr
gpt-4-0314Aryahcr
gpt-4o-freeNextway
gpt-4oChatBotRu
gpt-4-32k-0314Aryahcr
gpt-4-turboChatBotRu
gpt-3.5-turboAryahcr, Nextway, Alibaba
gpt-3.5-turbo-16kAryahcr
gpt-3.5-turbo-0613Aryahcr
gpt-3.5-turbo-16k-0613Aryahcr
gpt-3.5-turbo-0301Aryahcr
text-davinci-003Aryahcr
text-davinci-002Aryahcr
code-davinci-002Aryahcr
gpt-3Aryahcr
text-curie-001Aryahcr
text-babbage-001Aryahcr
text-ada-001Aryahcr
davinciAryahcr
curieAryahcr
babbageAryahcr
adaAryahcr
babbage-002Aryahcr
davinci-002Aryahcr
gemini-proNextway
gemini-nanoChrome
All Ollama modelsOllama
SparkDesk-v1.1Alibaba
deepseek-coderAlibaba
deepseek-chatAlibaba
Qwen2-7B-InstructAlibaba
glm4-9B-chatAlibaba
chatglm3-6BAlibaba
Yi-1.5-9B-ChatAlibaba
llama-3.1-405b-instruct-freeNextway

📷 Image Generation

📹 Example usage

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.

🌐 Image Generation Provider Options

OptionTypeDescription
negativePromptstringIndicates the direction not to take in production.
heightnumberSpecifies the image height.
widthnumberSpecifies the image width.
samplingStepsnumberSpecifies the number of iterations. A higher number results in higher quality.
samplingMethodstringSelects a sampling method to control the diversity, quality, and coherence of images.
cfgScalenumberSpecifies the Classifier-Free Guidance to control how closely the generated image adheres to the given text prompt.

🧮 Number Type Options

ProviderSupported 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

🖼️ Image Generation Providers

ProviderStatusDefault Style
Dalle2ActiveSemi-realistic, detailed with vivid colors and natural lighting.
StableDiffusionActivePhotorealistic, capturing fine details and textures to simulate real-life scenes.

🧠 Google Chrome AI

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

Setting Browser

  1. chrome://flags/#prompt-api-for-gemini-nano Select 'Enabled'

  2. chrome://flags/#optimization-guide-on-device-model Select 'Enabled BypassPrefRequirement'

  3. 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.

Simple Usage
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);
  }
})();

🧪 Testing

Running: npm test

🚧 Building

Webpack

  • npm run build - Build using Webpack.
  • npm run dev - Live development build with Webpack.

Bun

  • npm run build:bun - Build using Bun.
  • npm run dev:bun - Live development build with Bun.

🤝 Contribute

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!


logo

Keywords

FAQs

Package last updated on 29 Sep 2024

Did you know?

Socket

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.

Install

Related posts

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