Build an app that can ask a single question or chat with an LLM using Next.js and Together AI.
question
and returns a chat completion as a stream:
ChatCompletionStream
helper to read the stream and update some React state to display the answer:
isLoading
state to add additional styling, or a Reset button if you want to reset the page.
messages
array and returns a chat completion as a stream:
messages
for the session. In the form’s submit handler, send over the new array of messages, and use the ChatCompletionStream
helper to read the stream and update the last message with the LLM’s response.