UNPKG

@nlux/langchain-react

Version:

The LangServe adapters for nlux React, the React JS library for building conversational AI interfaces.

2 lines (1 loc) 944 B
import{createChatAdapter as r}from"@nlux/langchain";export{createChatAdapter}from"@nlux/langchain";import{useDeepCompareEffect as e}from"@nlux/react";import{useState as t}from"react";const o=e=>{const{url:t,dataTransferMode:o,headers:a,config:n,inputPreProcessor:s,outputPreProcessor:u,useInputSchema:i}=e||{};if(o&&"stream"!==o&&"batch"!==o)throw new Error("Data transfer mode not supported");if(!t)throw new Error("Runnable URL is required");let c=r().withUrl(t);return o&&(c=c.withDataTransferMode(o)),a&&(c=c.withHeaders(a)),n&&(c=c.withConfig(n)),s&&(c=c.withInputPreProcessor(s)),u&&(c=c.withOutputPreProcessor(u)),void 0!==i&&(c=c.withInputSchema(i)),c},a=r=>{const[a,n]=t(!1),[s,u]=t(o(r).create()),{url:i,dataTransferMode:c,headers:h,config:p,inputPreProcessor:d,outputPreProcessor:f,useInputSchema:m}=r||{};return e((()=>{if(!a)return void n(!0);const e=o(r).create();u(e)}),[a,i,c,h||{},p||{},d,f,m]),s};export{a as useChatAdapter};