RemoteRunnable within React Error #6520
-
Checked other resources
Commit to Help
Example Codeimport { RemoteRunnable } from "langchain/runnables/remote";
useEffect(() => {
remoteChain.current = new RemoteRunnable({
url: "/api/product",
});
}, []);
const makeQuery = async (product) => {
let response = await remoteChain.current.invoke({
product: JSON.stringify(product),
});
return response;
};DescriptionWhenever I try to execute the RemoteRunnable within my React app I'm getting the following error: ERROR System Info"@material-tailwind/react": "^2.1.8", |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
To resolve the "Failed to execute 'fetch' on 'Window': Illegal invocation" error when trying to execute In your code, you need to bind the import { RemoteRunnable } from "langchain/runnables/remote";
import { useEffect, useRef } from "react";
const MyComponent = () => {
const remoteChain = useRef(null);
useEffect(() => {
// Ensure fetch is bound correctly
const fetchBound = fetch.bind(window);
remoteChain.current = new RemoteRunnable({
url: "/api/product",
fetch: fetchBound, // Use the bound fetch function
});
}, []);
const makeQuery = async (product) => {
let response = await remoteChain.current.invoke({
product: JSON.stringify(product),
});
return response;
};
// Rest of your component code
};
export default MyComponent;By binding |
Beta Was this translation helpful? Give feedback.
To resolve the "Failed to execute 'fetch' on 'Window': Illegal invocation" error when trying to execute
RemoteRunnablewithin your React application, ensure that thefetchImplementationis correctly bound to theRemoteRunnableclass. The error typically occurs when thefetchfunction loses its context.In your code, you need to bind the
fetchfunction to thewindowobject. Here is an example of how you can instantiateRemoteRunnablewith a properly boundfetchfunction: