Socket
Socket
Sign inDemoInstall

@musaid.qa/openai-socket

Package Overview
Dependencies
46
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @musaid.qa/openai-socket

A wrapper for the OpenAI API using sockets


Version published
Weekly downloads
3
decreased by-70%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

OpenAI Socket

A wrapper for the OpenAI API using sockets.

npm version License

Installation

Install the package using npm:

npm install @musaid.qa/openai-socket

Usage

Example

Server

import { Server } from "socket.io";
import { OpenAISocket } from "@musaid.qa/openai-socket";


const server = new Server();
const port = 2030;
const openai = new OpenAISocket(server, {
  verbose: true,
  client: {
    apiKey: process.env.OPENAI_API_KEY
  },
  chat: {
    model: 'gpt-3.5-turbo'
  },
  initMessages: [
    {
      role: 'system',
      content: 'You are a nodejs compiler'
    }
  ]
});

server.listen(port);
console.log(`Listening on port ${port}`);

Client

import { Socket, io } from "socket.io-client"
import { EmitEvents } from "@musaid.qa/openai-socket";

const client: Socket<EmitEvents> = io('http://localhost:2030');

client.on('connect', () => {

  client.on('content', (content) => {
    console.log(content)
  });

  client.on('end', () => {
    console.log('end')
  });

 client.emit('new-message', 'Hello from earth!');

});

For more see basic example or Docs

License

This project is licensed under the MIT License.

Keywords

FAQs

Last updated on 28 Nov 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc