Comments (4)
Yes this is something related to Suspense
and render()
. Thanks for reporting!
from ai.
Hi! Thanks for the clarification! I just wanted to point out that I am not using the render()
. This is also happening using the primitives createStreamableUI and createStreamableValue
from ai.
In the posted example you can work around the mentioned suspense issue (i.e. the whole promise chain is replayed when the fallback is replaced with the children) by skipping the ui.update()
step:
(async () => {
await sleep(50);
const textNode = createStreamableValue("");
- ui.update(<AssistantMessageWithStreamableValue content={textNode.value} />);
+ ui.done(<AssistantMessageWithStreamableValue content={textNode.value} />);
for await (const token of generateTokens(text)) {
textNode.update(token);
}
textNode.done();
- ui.done();
})();
from ai.
I'm currently having a hard time working around this issue. I'm currently developing a shopping assistant for a work project. I want to provide some feedback in the UI when some products are added to the cart. Here I post an example of the code:
completion.onEvent("add_products_to_cart", async (data) => {
let streamableCart:
| ReturnType<typeof createStreamableValue<Product>>
| undefined;
if (data.state === "START" || !streamableCart) {
streamableCart = createStreamableValue<Product>();
} else {
const { products } = data;
const product = products[Object.keys(products)[0]][0];
if (product) {
ui.update(
<>
<EventMessage>
{Object.keys(products).length} prodotti aggiunti al carrello
</EventMessage>
<AddToCart products={streamableCart.value} />
</>,
);
streamableCart.done(product);
}
}
});
And for the AddToCart
component:
export function AddToCart({
products,
}: {
products: StreamableValue<Product>;
}) {
const { addToCart } = useShoppingCartActions();
useEffect(() => {
(async () => {
let productsToAdd: Product[] = [];
for await (const product of readStreamableValue(products)) {
if (product) {
productsToAdd.push(product);
}
}
if (productsToAdd.length > 0) {
console.log({ productsToAdd });
addToCart(productsToAdd);
}
})();
}, [products]);
return null;
}
The problem I have is that products are added multiple times because the component is mounted multiple times. I haven't found a way to get around this and it's kinda blocking us
from ai.
Related Issues (20)
- Append for useAssistant HOT 7
- handleSubmit not being called conditionally
- TypeScript errors with Node HOT 4
- Feature Request: Support for Multiple Completions in OpenAI API Integration
- Using OpenAI SDK with Ollama HOT 2
- Using Antropic with the new Generative UI HOT 3
- Option to still disable data streaming if I just need the text HOT 1
- Annotations array empty with OpenAI and AssistantResponse and useAssistant HOT 3
- Expose a `OpenAIAssistantStream` function
- Super weird bug (not updating) only on Vercel / deployed code HOT 2
- [AI Core] Abort signal causes `BodyStreamBuffer was aborted` HOT 1
- Pages Router AI SDK 404 error HOT 2
- Error in Gemini Chat Template HOT 5
- JSON parsing error - possible fixes HOT 1
- useAIState with key not correctly inferring type
- [AsistantResponse] - to save streaming data to external database HOT 8
- Router cache issue with NextJS and Vercel AI SDK
- Omit/Modify Conversation History When Triggering Request in useChat
- Importing from "langchain/llms/openai" is deprecated. HOT 2
- Better documentation for `streamObject`
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.