0.2.0 • Published 9 months ago

@tsailab/xai v0.2.0

Weekly downloads
-
License
LICENSE
Repository
github
Last release
9 months ago

Installation

$ npm install -g @tsailab/xai

Usage

browser front SSE fetch

  // abort request
  let controller = new AbortController()

  // SSE request body data
  const sseBody: XaiStreamableRequestData = {
    controller,
    chatid: 'xai-chatid-001', // required string ,your front app chat id
    provider: 'deepseek', // which provide api service 
    model, // model id 
    uuid, // required number 
    // text: prompt.value, front user input text or handler messages 
    messages: [ // see openai message
      {
        role: 'user',
        content: 'who are you?', 
      },
    ],
  }

  // the SSE streamable response chunk appending text
  let fullResult:string = ''

  const sseClient = new XaiSseFetch(
    apiPath:'http://127.0.0.1:8964/v1',
    { 
      apiBasePrefix:'chat/completions',
      eventDataParsed:true, // control return chunk parsed to JSON Object OR string
      debug: true, // if true will print some log
      // handle streamable chunk content,add update chat result text typed.
      onmessage:(chunk:any) => {
        console.log(chunk, `onMessage>>>>>>>>>>>${typeof chunk}`)
        // if eventDataParsed=false chunk is string
        try{
          const {content} = JSON.parse(chunk)

          fullResult = fullResult + content
        }catch(_){

        }

        // if eventDataParsed=true chunk is object
        fullResult = fullResult + chunk.content

      },
      onerror: (err: any) => {
        console.log(err, '<<<<<>>>>Error>>>>')
      },
      oncancel: () => {
        console.log('>>>>>>>>>>>>>Cancel>>>>>>')
      },
      onclose: () => {
        console.log('>>>>>>>Closed>>>>>')
      },
    }
  )

  // launch SSE fetch
  await cli.connect(sseBody, (cache: any) => {
      // first connect handle ssebody merge remote model options 
      console.log('>>>>>>> preconnect>> cache>>>', cache)
  })

front localstore helper

newChatbotAgent(...)
createNewUserMessage(...)
createInitAssistantMessage(...)
updateSomeChatbotMessage(...)

Contribution

the Code submission specifications follow angular standards

you can visit rules link,see more infomation.


Stay in touch

:revolving_hearts::revolving_hearts::revolving_hearts: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand::raising_hand::raising_hand::revolving_hearts::revolving_hearts::revolving_hearts:

Sincerely invite experts to improve the project functions together !

:revolving_hearts::revolving_hearts::revolving_hearts: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand: :raising_hand::raising_hand::raising_hand::revolving_hearts: :revolving_hearts::revolving_hearts:

License

The @Tsailab/xai packages is MIT licensed.

Give me a cup of coffee? Thanks much.

0.2.0

9 months ago

0.1.0

10 months ago

0.1.1

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago