npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chatnio-node

v1.1.9

Published

A forked Javascript/Typescript library for the Chat Nio API on Node.

Downloads

7

Readme

Chat Nio Javascript Library

NPM VersionNPM DownloadsGitHub last commit (branch)GitHub License

  • Authors: Deeptrain Team
  • Free software: MIT license
  • Documentation: https://docs.chatnio.net

Table of Contents

Features

Check official documentation website

  • Chat
  • Conversation
  • Quota
  • Subscription and Package

Dependencies

Installation

npm install chatnio-node
# or using yarn, pnpm
yarn add chatnio-node

Quick Start

  • Sign up and sign in official Chatnio website
  • Click the avatar at the top right corner
  • Select 'API Settings'
  • Copy your private API Key
  • Install chatnio-node and write the source file test.js
// test.mjs
import {setKey, Chat} from "chatnio-node"

// Place your API Key here. Don't do this in code that will be published to public
setKey("{{ API Key }}")
const chat = new Chat()
const res = await chat.ask({
    message: "hello! What's your name?"
})
console.log(res)
process.exit(0)

:warning: For security, you should not place your API Key directly in your source code, but use envrionment variables or .env file in your app.

  • Execute the program
node test.mjs
  • The output result may look like the following:
{
  message: "Hello! I am OpenAI's language model, known as GPT-3. I don't have a specific name, but you can call me GPT-3 or AI. How can I assist you today?",
  keyword: '',
  quota: 0.000255
}

Usage

  • Import
import { Chat } from 'chatnio-node';
// or
const { Chat } = require("chatnio-node")

API

  • Authentication API:Set your own API Key before chatting
import { setKey, setEndpoint } from 'chatnio-node';

// set your API Key
setKey("sk-...");

// set custom api endpoint (default: https://api.chatnio.net)
// setEndpoint("https://example.com/api");
  • Chat API:Chat with multiple available models
import { Chat } from 'chatnio-node';

const chat = new Chat(-1); // id -1 (default): create new conversation

// using stream
chat.askStream({ 
    message: "hello world", 
    model: "gpt-3.5-turbo-0613", // default gpt-3
    web: false 
}, (res) => {
  console.log(res);
});

// don't use stream
chat.ask({ message: "hi" })
  .then(res => {
    console.log(res);
  })
  .catch(err => {
    console.log(err);
  });
import { getConversations, getConversation, deleteConversation } from 'chatnio-node';

// get all conversations of current user
const conversations = await getConversations();

// load conversation by id
const conversation = await getConversation(1);

// delete conversation by id
const state = await deleteConversation(1);
import { getQuota, buyQuota } from 'chatnio-node';

// get quota
const quota = await getQuota();

// buy quota
const state = await buyQuota(100);
import { getPackage, getSubscription, buySubscription } from 'chatnio-node';

// get package
const pkg = await getPackage();

// get subscription
const subscription = await getSubscription();

// buy subscription
const state = await buySubscription(1, 1);

Example

Get Conversation Content

:bulb: For each new conversation, the first message received will be used as the conversation's name.

:warning:Although the getConversations() interface returns a data type of Conversation[], the message field of each Conversation is null . To obtain the complete history of a conversation, load the conversation by getConversation(id) interface.

import {Chat, getConversation, getConversations, setKey} from 'chatnio-node'

setKey("")

const msg1 = "Hello! My name is chat-nio."
const msg2 = "What's my name?"
// Create a new conversation. The first message received will be used as the conversation's name.
const chat = new Chat(-1)
let res = await chat.ask({
    message: msg1
})
console.log(res);
res = await chat.ask({
    message: msg2
})
console.log(res);

// Get the list of recent conversations, use the name to filter out conversation, and find the ID
const conversations = await getConversations();
const id = conversations.find(conv => conv.name === msg1).id

// Retrieve detailed conversation information by id
const conversation = await getConversation(id)
console.log(conversation);

// exit the program
process.exit(0)

Output may look like:

{
  message: 'Hello chat-nio! How can I assist you today?',
  keyword: '',
  quota: 0.00156
}
{ message: 'Your name is chat-nio.', keyword: '', quota: 0.002385 }
{
  auth: false,
  user_id: 4470,
  id: 45,
  name: 'Hello! My name is chat-nio.',
  message: [
    { srole: 'user', content: 'Hello! My name is chat-nio.' },
    { role: 'assistant', content: 'Hello chat-nio! How can I assist you today?' },
    { role: 'user', content: "What's my name?" },
    { role: 'assistant', content: 'Your name is chat-nio.' }
  ],
  model: 'gpt-3.5-turbo',
  enable_web: false,
  shared: false,
  context: 0
}

Build

Use tsc to build

npm run build
# or
yarn run build

FAQs

Where to find API Key

  • Sign in official Chatnio website
  • Click the avatar at the top right corner
  • Select 'API Settings' .
  • Copy your private API Key

Check API 快速入门 - Chat Nio for detailed

Where to find available models

Default is gpt-3.5-turbo if you don’t specified.

Check api.chatnio.net/v1/models for all available models.

See also

Official repository:Deeptrain-Community/chatnio

Other SDK: