@nlux/langchain-react
Version:
The LangServe adapters for nlux React, the React JS library for building conversational AI interfaces.
2 lines (1 loc) • 1.31 kB
JavaScript
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@nlux/langchain"),require("@nlux/react"),require("react")):"function"==typeof define&&define.amd?define(["exports","@nlux/langchain","@nlux/react","react"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self)["@nlux/langchain-react"]={},e.langchain,e.react$1,e.react)}(this,(function(e,r,t,a){"use strict";const n=e=>{const{url:t,dataTransferMode:a,headers:n,config:o,inputPreProcessor:u,outputPreProcessor:s,useInputSchema:c}=e||{};if(a&&"stream"!==a&&"batch"!==a)throw new Error("Data transfer mode not supported");if(!t)throw new Error("Runnable URL is required");let i=r.createChatAdapter().withUrl(t);return a&&(i=i.withDataTransferMode(a)),n&&(i=i.withHeaders(n)),o&&(i=i.withConfig(o)),u&&(i=i.withInputPreProcessor(u)),s&&(i=i.withOutputPreProcessor(s)),void 0!==c&&(i=i.withInputSchema(c)),i};Object.defineProperty(e,"createChatAdapter",{enumerable:!0,get:function(){return r.createChatAdapter}}),e.useChatAdapter=e=>{const[r,o]=a.useState(!1),[u,s]=a.useState(n(e).create()),{url:c,dataTransferMode:i,headers:d,config:f,inputPreProcessor:h,outputPreProcessor:p,useInputSchema:l}=e||{};return t.useDeepCompareEffect((()=>{if(!r)return void o(!0);const t=n(e).create();s(t)}),[r,c,i,d||{},f||{},h,p,l]),u}}));