New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

chatnio-node

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chatnio-node

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

latest
Source
npmnpm
Version
1.1.9
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

Chat Nio Javascript Library

NPM VersionNPM DownloadsGitHub last commit (branch)GitHub License

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

English · 简体中文

Quick Start · Report Bug · Propose Feature

Official Web APP · Documentation

Stat

  • 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

[↑ back to top]

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
}

[↑ back to top]

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

[↑ back to top]

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
}

[↑ back to top]

Build

Use tsc to build

npm run build

# or
yarn run build

[↑ back to top]

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.

[↑ back to top]

See also

Official repository:Deeptrain-Community/chatnio

Other SDK:

[↑ back to top]

Keywords

chatnio

FAQs

Package last updated on 18 Feb 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