
Building the input prompt
TurboSeekβs core interaction is a text field where the user can enter a question:
<input>
and control it using some new React state:
JSX
- Use the Bing API to fetch sources from the web, and
- Pass the text from the sources to an LLM to summarize and generate an answer
/getSources
:
JSX
/getSources
:

Getting web sources with Bing
To create our API route, weβll make a newapp/api/getSources/route.js
file:
JSX
JSX
.env.local
:
JSX
JSX

JSX
Fetching the content from each source
Now that our React app has the sources, we can send them to a second endpoint where weβll use Together to scrape and summarize them into our final answer. Letβs add that second request to a new endpoint weβll call/api/getAnswer
, passing along the question and sources in the request body:
JSX
/api/getAnswer
. Letβs create the second route!
Make a newapp/api/getAnswer/route.js
file:
JSX
- Get the text from the URL of each source
- Pass all text to Together and ask for a summary
JSX
jsdom
and @mozilla/readability
libraries:
JSX
JSX
getTextFromURL
function:
JSX
Promise.all
to kick off our functions in parallel:
JSX

Summarizing the sources
Now that we have the text content from each source, we can pass it along with a prompt to Together to get a final answer. Letβs install Togetherβs node SDK:JSX
JSX
Displaying the answer in the UI
Back in our page, letβs create some new React state calledanswer
to store the text from our LLM:
JSX
ChatCompletionStream
helper from Togetherβs SDK to read the stream and update our answer
state with each new chunk:
JSX
JSX
getAnswer
endpoint responds with the first chunk, weβll see the answer text start streaming into our UI!
The core features of our app are working great.