Build An Audio AI App Transcripts
Chapter: Feature 4: Chat Q and A
Lecture: Processing the Question

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw we have the UI completely working, but we don't have any way for this to be processed on the server. So let's go ahead and borrow that again.
0:11 And I'm gonna put the URL right here like that, that I copied from the form. So it's hx-question. You can put whatever you want for the URL,
0:21 but I decide, all right, for, just kind of be consistent. When you see hx, this means it's an htmx partial type of thing, most likely,
0:29 and that you're not going to call it directly. There's a lot of flexibility there. The other thing is, let's look over in our views
0:36 in the partial section, we have a chat response. Now the chat response is pretty basic. It just says, is there an answer? Show them the answer.
0:46 Otherwise, if there's an error, and by the way, there's not also an error and an answer at any time,
0:52 but I guess we could check not error and error, whatever. If there's an error, we just show the error. Otherwise, we'll put a little style
1:00 like we have on other parts of our assembly AI response sections. But other than that, we're just going to say, here's the answer.
1:07 And remember the JavaScript that said, delete the prior answer, we're going to put the ID there.
1:12 Okay, so most importantly, just know there's a chat response HTML that we're going to set. And so that goes right here. And there we have it.
1:28 Now, in fact, it's quite similar to what we had before. The thing we just need to do is we need to check if there's an error.
1:36 So our load data is checking things like, are you logged in? Are you allowed to do this? Did you actually specify a question, et cetera?
1:43 Does the podcast exist? So we'll say if VM.error, we're just going to return VM.toDictionary. So that will set the error message.
1:53 We don't want to go and even try to generate the answer if for some reason they're not allowed to. So that will do that section there.
2:00 Maybe we could even test it and see what we get back. And well, before we do that, let's go down here and just say, VM.answer,
2:11 just to make sure this round tripping works. There's no AI magic happening here. Is AI magic? Let me ask. Bing. Well, that sure wasn't magic.
2:23 Oh, this is post and where I copied it before was a get. So I don't think we've done a post together. There are some other parts of the app.
2:33 Is AI magic? One more thing. This is slash partials. Yikes, sorry, folks. Is AI magic? You've asked, is AI magic?
2:51 We don't know. Woo, amazing. Look at that. I think it might be like advanced tech. Right? So you can see, we can just ask that question
3:04 and let's show the timer thing real quick as well. Let's do a time. Let's sleep. Let's suppose it takes three seconds for this to run.
3:19 Now I'll put a question mark here. Look, it's thinking, thinking. Hmm, yes. Is it like advanced techs? Perhaps.
3:29 Very deep question you have asked of me, Michael. Awesome. So that's the workflow. We've got it basically from a web functionality perspective,
3:38 100% done. What we do need to do though is actually come up with a answer to that question using Lemur, which we'll do in just a minute.
3:47 But what do you think? Pretty cool? I love it. There's so much to love about this. Like I love the way HTMX makes this so clean and nice.
3:57 Let's just keep flowing without writing a ton of JavaScript. Yeah, I think this is really neat.
4:02 Now we just need to make it work from a Q&A perspective.


Talk Python's Mastodon Michael Kennedy's Mastodon