@musaid.qa/openai-socket

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.

Generated using TypeDoc