You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have seen "nostream" used in an example code using .stream method. How do you apply that in streamEvent method?
here is my grapgh:
const graphBuilder = new StateGraph(GraphStateWithToken)
// Main nodes
.addNode("analyzeQuery", handleInitialQuery)
.addNode("fetchTicketHistory", getTicketHistory)
.addNode("generateSupportResponse", createResponse)
.addNode("escalationHandler", handleEscalation)
.addNode("knowledgeSearch", searchKnowledge)
.addNode("priorityCheck", assessPriority)
// Start flow
.addEdge("__start__", "analyzeQuery")
// Route based on query analysis
.addConditionalEdges("analyzeQuery", queryTypeCondition, {
__end__: "__end__",
needsHistory: "fetchTicketHistory",
})
// Check ticket history
.addEdge("fetchTicketHistory", "priorityCheck")
`import { RunnableLambda } from "@langchain/core/runnables";
const unstreamed = async (_: typeof StateAnnotation.State) => {
const model = new ChatOpenAI({
model: "gpt-4o-mini",
temperature: 0,
});
const res = await model.invoke("How are you?");
console.log("LOGGED UNSTREAMED MESSAGE", res.content);
// Don't update the state, this is just to show a call that won't be streamed
return {};
}
const agentWithNoStream = new StateGraph(StateAnnotation)
.addNode("unstreamed",
// Add a "nostream" tag to the entire node
RunnableLambda.from(unstreamed).withConfig({
tags: ["nostream"]
})
)
.addNode("agent", callModel)
.addNode("tools", toolNode)
// Run the unstreamed node before the agent
.addEdge("start", "unstreamed")
.addEdge("unstreamed", "agent")
.addConditionalEdges("agent", routeMessage)
.addEdge("tools", "agent")
.compile();
const stream = await agentWithNoStream.stream(
{ messages: [{ role: "user", content: "What's the current weather in Nepal?" }] },
{ streamMode: "messages" },
);
for await (const [message, _metadata] of stream) {
if (isAIMessageChunk(message) && message.tool_call_chunks?.length) {
console.log(${message.getType()} MESSAGE TOOL CALL CHUNK: ${message.tool_call_chunks[0].args});
} else {
console.log(${message.getType()} MESSAGE CONTENT: ${message.content});
}
}`
The text was updated successfully, but these errors were encountered:
I have seen "nostream" used in an example code using .stream method. How do you apply that in streamEvent method?
here is my grapgh:
const graphBuilder = new StateGraph(GraphStateWithToken)
// Main nodes
.addNode("analyzeQuery", handleInitialQuery)
.addNode("fetchTicketHistory", getTicketHistory)
.addNode("generateSupportResponse", createResponse)
.addNode("escalationHandler", handleEscalation)
.addNode("knowledgeSearch", searchKnowledge)
.addNode("priorityCheck", assessPriority)
here is the example code found on https://langchain-ai.github.io/langgraphjs/how-tos/stream-tokens/#the-stream-method
`import { RunnableLambda } from "@langchain/core/runnables";
const unstreamed = async (_: typeof StateAnnotation.State) => {
const model = new ChatOpenAI({
model: "gpt-4o-mini",
temperature: 0,
});
const res = await model.invoke("How are you?");
console.log("LOGGED UNSTREAMED MESSAGE", res.content);
// Don't update the state, this is just to show a call that won't be streamed
return {};
}
const agentWithNoStream = new StateGraph(StateAnnotation)
.addNode("unstreamed",
// Add a "nostream" tag to the entire node
RunnableLambda.from(unstreamed).withConfig({
tags: ["nostream"]
})
)
.addNode("agent", callModel)
.addNode("tools", toolNode)
// Run the unstreamed node before the agent
.addEdge("start", "unstreamed")
.addEdge("unstreamed", "agent")
.addConditionalEdges("agent", routeMessage)
.addEdge("tools", "agent")
.compile();
const stream = await agentWithNoStream.stream(
{ messages: [{ role: "user", content: "What's the current weather in Nepal?" }] },
{ streamMode: "messages" },
);
for await (const [message, _metadata] of stream) {
if (isAIMessageChunk(message) && message.tool_call_chunks?.length) {
console.log(
${message.getType()} MESSAGE TOOL CALL CHUNK: ${message.tool_call_chunks[0].args}
);} else {
console.log(
${message.getType()} MESSAGE CONTENT: ${message.content}
);}
}`
The text was updated successfully, but these errors were encountered: