Giter Site home page Giter Site logo

openai-sdk's Introduction

npm version Actions status | kunl/openai-sdk

快速开始

1. 安装openai-sdk

  npm i openai-sdk
  import openai-sdk from 'openai-sdk'

2. 引入并初始化相关参数

  import openai from 'openai-sdk'
  let {
      init,
      chat,
      nlp
  } = openai
  init({
    TOKEN: "",
    EncodingAESKey: ""
  })

3. 聊天接口

  chat({
    username: "uid",
    msg: "你好吗"
  }).then(res => {
      console.log('机器人返回:', res)
  }, res => {
      console.log('reject res:', res)
  }).catch(e => {
      console.log('error', e)
  })

4.nlp相关接口

4.1 分词

    // 分词
    nlp.tokenize({
        uid: "uid",
        data: {
            q: "我的家乡叫**。"
        }
    }).then(res => {
        console.log('词法分析返回:', res)
    }, res => {
        console.log('reject res:', res)
    }).catch(e => {
        console.log('error', e)
    })

   // 分词接口返回值
   {
      words: ['我', '的', '家乡', '叫', '**', '。'],
      POSs: [27, 30, 16, 31, 20, 34],
      words_mix: ['我的家乡', '叫', '**', '。'],
      POSs_mix: [16, 31, 20, 34],
      entities: ['我的家乡', '我的', '**'],
      entity_types: [0, 0, 100000012]
  }

4.2 数字日期时间识别

    // 数字日期时间识别
    nlp.ner({
        uid: "uid",
        data: {
            q: "帮我订两张后天上午的火车票"
        }
    }).then(res => {
        console.log('数字日期时间识别返回:', res)
    }, res => {
        console.log('reject res:', res)
    }).catch(e => {
        console.log('error', e)
    })

   // 数字日期时间识别接口返回值
   [
      {
          type: 'number',
          span: [3, 4],
          text: '两',
          norm: '2'
      },
      {
          type: 'datetime_interval',
          span: [5, 9],
          text: '后天上午',
          norm: '2019-11-23 08:00:00~2019-11-23 11:59:59'
      }
    ]

4.3 情感分析

    // 情感分析
    nlp.sentiment({
        uid: "uid",
        data: {
            q: "恭喜小张脱单成功",
            mode: "6class"
        }
    }).then(res => {
        console.log('情感分析返回:', res)
    }, res => {
        console.log('reject res:', res)
    })
    .catch(e => {
        console.log('error', e)
    })

   // 情感分析接口返回值
   {
      error: null,
      result: [
          ['高兴', 0.9011998772621155],
          ['无情感', 0.08493703603744507],
          ['喜欢', 0.011011340655386448],
          ['悲伤', 0.0015742022078484297],
          ['厌恶', 0.0006485909689217806],
          ['愤怒', 0.000628964276984334]
      ]
  }

4.4 敏感词识别

    // 敏感词识别
    nlp.sensitive({
        uid: "uid",
        data: {
            q: "楼主真垃圾,祝你早日死全家"
        }
    }).then(res => {
        console.log('敏感词识别返回:', res)
    }, res => {
        console.log('reject res:', res)
    }).catch(e => {
        console.log('error', e)
    })

   // 敏感词识别接口返回值
   {
      error: null,
      result: [
          ['dirty_curse', 0.9999999900000001],
          ['other', 9.9999999e-9],
          ['dirty_politics', 0],
          ['dirty_porno', 0]
      ]
  }

openai-sdk's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.