dify-chat-client
v1.0.0
Published
A simple browser end API client for dify AI chat
Downloads
8
Readme
dify-chat-client
forked from Adangs/dify-chat
yarn add dify-chat-client -Dimport { ChatClient } from 'dify-chat-client'
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-client'
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
