Building a Non-Streaming Chat App - Instruction

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Creating a Fact Checking App

A chat app, like ChatGPT, asks users for an input, responds, and allows users to send more messages in the same thread. This app takes in all the previous messages, from the user and from itself, as context for its next response. You’re going to make a similar app in this lesson.

Fetching URL Content

In the previous lesson, you mocked the response of getting the URL. Note that the starter code for this lesson already includes a real implementation of fetching the text from a webpage. Because this is not central to the lesson, you can try understanding how it’s done on your own.

Asking the User for Inputs

Because you’ll ask the user for inputs, the first thing to do is to remove the user’s initial message from the history of messages. Find the messages array and remove the message that has the role user. It should look like the code below:

Chat Loop

Now that you can ask the user for inputs, you’ll want to make the chat app ask the user again after it responds. You’ll implement this in a loop.

Error Handling

Giving your user the ability to send infinite responses to the app can lead to some currently unhandled problems. You might recall that you added error handling in an earlier lesson. You should remember to add these when performing calls to chat completion. If the user sent responses too quickly, you might receive a rate-limit error.

Tool Calls

The last part of this chat app is its ability to add content from the web to make its fact-checking more accurate.

See forum comments
Download course materials from Github
Previous: Building a Non-Streaming Chat App - Introduction Next: Building a Non-Streaming Chat App - Demo