Comments (10)
Did anyone get this to work?
For example
const result = await agent.stream({ input: currentMessageContent, outputKey: "output", chat_history: memory.chatHistory.getMessages() });
returns an
IterableReadableStream<ChainValues>
which isn't an accepted input forLangChainAdapter
, even after the #2340Trying what ivanvanderbyl did, didn't work for me either. Though it seems to be going in the right direction. Is this what we are expected to do? As the documentation hasn't been updated to state that.
For the most part I have been able to make this work with:
const agentStream = await agentExecutor.streamEvents( { messages, input: lastMessage.content }, { version: "v2" }, ); const stream = new ReadableStream({ async pull(controller) { for await (const { event, data } of agentStream) { if (event === "on_chat_model_stream") { const msg = data?.chunk as AIMessageChunk; if ((msg.tool_call_chunks?.length ?? 0) > 0) { // console.log("Tool calls", msg.tool_calls); } else if (msg.content) { controller.enqueue(msg.content as string); } } } controller.close(); }, }); const aiStream = LangChainAdapter.toAIStream(stream); return new StreamingTextResponse(aiStream);
You need to use streamEvents()
:
const agentStream = await agentExecutor.streamEvents(
{ messages, input: lastMessage?.content ?? "" },
{ version: "v2" },
);
const aiStream = LangChainAdapter.toAIStream(agentStream);
return new StreamingTextResponse(aiStream);
from ai.
👍 🙏
from ai.
+1 would be very helpful
from ai.
👍 🙏
from ai.
For the most part I have been able to make this work with:
const agentStream = await agentExecutor.streamEvents(
{ messages, input: lastMessage.content },
{ version: "v2" },
);
const stream = new ReadableStream({
async pull(controller) {
for await (const { event, data } of agentStream) {
if (event === "on_chat_model_stream") {
const msg = data?.chunk as AIMessageChunk;
if ((msg.tool_call_chunks?.length ?? 0) > 0) {
// console.log("Tool calls", msg.tool_calls);
} else if (msg.content) {
controller.enqueue(msg.content as string);
}
}
}
controller.close();
},
});
const aiStream = LangChainAdapter.toAIStream(stream);
return new StreamingTextResponse(aiStream);
from ai.
from ai.
fixed in main
from ai.
Did anyone get this to work?
For example
const result = await agent.stream({
input: currentMessageContent,
outputKey: "output",
chat_history: memory.chatHistory.getMessages()
});
returns an IterableReadableStream<ChainValues>
which isn't an accepted input for LangChainAdapter
, even after the #2340
Trying what ivanvanderbyl did, didn't work for me either. Though it seems to be going in the right direction. Is this what we are expected to do? As the documentation hasn't been updated to state that.
For the most part I have been able to make this work with:
const agentStream = await agentExecutor.streamEvents( { messages, input: lastMessage.content }, { version: "v2" }, ); const stream = new ReadableStream({ async pull(controller) { for await (const { event, data } of agentStream) { if (event === "on_chat_model_stream") { const msg = data?.chunk as AIMessageChunk; if ((msg.tool_call_chunks?.length ?? 0) > 0) { // console.log("Tool calls", msg.tool_calls); } else if (msg.content) { controller.enqueue(msg.content as string); } } } controller.close(); }, }); const aiStream = LangChainAdapter.toAIStream(stream); return new StreamingTextResponse(aiStream);
from ai.
@hiddengearz can you point me to the ChainValues source code / docs for the latest langchain? I can take a look add adding the relevant support.
from ai.
Yikes, I updated the @ai-sdk/svelte
package but forgot to update ai
. I won't get a chance to test it until the weekend but that fixed the build errors.
Thanks for the quick responses and great job!
from ai.
Related Issues (20)
- Extend messages type HOT 1
- createStreamableUI causes multiple rerenders / UI flickering HOT 8
- Azure OpenAI On Your Data HOT 1
- ai/core: support reason + "array" HOT 1
- Receiving the error "Error: Cannot read properties of undefined (reading 'workers')" after upgrading to v3.3.30 using Next.js v14.2.9 HOT 7
- React: mutating stream data unnecessarily causes other functions being recreated even though they are enclosed by useCallback
- Add Support for Custom AI Model in StreamUI HOT 1
- Flush/Reset StreamData when calling data.close() or have a seperate function for it
- Token transfer to client should be optional HOT 2
- TypeError: Inter-TransformStream ReadableStream.pipeTo() is not implemented HOT 8
- Streaming breaks when using await in tool execution on express HOT 3
- Gemini not working with structured output and union HOT 2
- ai-sdk/ui: Provide a way to customise the user message in useChat
- Callback for each message when calling tools with streamText() e.g. `onMessage` HOT 16
- topK option is not passed from provider HOT 7
- Support for Additional Inference Providers (DeepInfra, Hyperbolic) and Voyage AI for Embeddings
- StreamUI unhandledRejection: Error: .update(): UI stream is already closed. HOT 6
- Cannot destructure property 'sendMessage' of 'useActions(...)' as it is null. HOT 1
- useAssistant hook createMessage method
- AWS Bedrock provider doesn't work unless using `bedrockOptions` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ai.