Skip to content

A wrapper for the OpenAI API using sockets

Notifications You must be signed in to change notification settings

paulpham157/openai-socket

 
 

Repository files navigation

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.

About

A wrapper for the OpenAI API using sockets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 59.0%
  • TypeScript 41.0%