dify-chat
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

dify-chat

yarn add dify-chat -D
import { ChatClient } from 'dify-chat'

const client = new ChatClient({
  baseURL: '/dify/v1',
  apiKey: 'app-xxxxx'
})

client.sendChatMessage({
  query: 'hi dify',
  user: 'github'
}, {
  onData: (res) => {
    console.log('onData-> ', res)
  },
  onMessageEnd: (res) => {
    console.log('onMessageEnd-> ', res)
  },
  onMessageReplace: (res) => {
    console.log('onMessageReplace-> ', res)
  },
  onNodeStarted: (res) => {
    console.log('onNodeStarted-> ', res)
  },
  onNodeFinished: (res) => {
    console.log('onNodeFinished-> ', res)
  },
  onWorkflowStarted: (res) => {
    console.log('onWorkflowStarted-> ', res)
  },
  onWorkflowFinished: (res) => {
    console.log('onWorkflowFinished-> ', res)
  },
  onCompleted: (res) => {
    console.log('onCompleted-> ', res)
  },
  onError: (res) => {
    console.log('onError-> ', res)
  }
})

API

import { ChatClient } from 'dify-chat'

const client = new ChatClient({
  baseURL: '/dify/v1',
  apiKey: 'app-xxxxx'
})

client.tts({
  text: 'hello hello' 
}).then((blob) => {
  const audioUrl = URL.createObjectURL(blob);
  const audio = new Audio(audioUrl);
  audio.play();
})

References

https://github.com/langgenius/webapp-conversation

Readme

Keywords

Package Sidebar

Install

npm i dify-chat

Weekly Downloads

8

Version

0.1.2

License

ISC

Unpacked Size

22.5 kB

Total Files

5

Last publish

Collaborators

  • liulundang