A large language model (LLM) is an AI model trained on vast amounts of text to understand and generate human language. It produces a response by predicting likely next words or sequences in context. In a web app, that capability can turn a user’s prompt into an answer, summary, conversation, or draft of marketing copy. section 1.2.1 section 1.1.2
Figure 1.2 How an AI web app works: the user inputs data, and then the app processes it, selects a model, generates content, delivers it, and, optionally, collects feedback.
Follow the request from user input through backend processing and model selection to content generation, delivery, and optional feedback. section 1.2.2
Treat the model as one component of the application:
- Choose a model suited to the task and consider whether its training data is relevant. Pretrained models accessed through OpenAI or Gemini APIs avoid the resources and expertise needed to host an LLM yourself. section 1.4 section 1.4.2
- Send the user’s request and relevant context from the backend; process and verify the returned response before displaying it. Preserve conversation messages so users can ask follow-up questions. section 2.2.1
- Stream generated text when a complete response would leave users waiting. Incremental delivery improves perceived responsiveness without making the model itself faster. section 3.2
- Validate consequential output: a fluent answer can still be inaccurate or biased. Constrain context, test diverse inputs, and plan for privacy, latency, and cost in deployment. section 1.6.3 section 9.6
Document-grounded answers
For questions about private documents, retrieval-augmented generation (RAG) supplies relevant document chunks alongside the question. A LangChain.js chain can retrieve and format those chunks, prompt the LLM to answer only from that context, and return both the answer and source documents. For a long document summary, a separate MapReduce workflow summarizes chunks before combining them. section 7.2.4 section 7.1.2
Listing 7.9 Performing augmentation of the response
async performRAG(query) {
const prompt = ChatPromptTemplate
.fromTemplate(` #1
Answer the question based only on the context provided.
Context: {context}
Question: {question}`);
const chain = RunnableSequence.from([ #2
{
context: this.retriever.pipe(formatDocs),
question: new RunnablePassthrough(),
},
prompt,
this.llm,AQ:
new StringOutputParser(),
]);
const response = await chain.invoke(query); #3
const sourceDocuments =
await this.retriever.invoke(query); #4
return {
answer: response,
sourceDocuments,
};
}
Inspect the JavaScript RAG chain’s prompt, retriever, model invocation, and returned source documents as an implementation pattern. section 7.2.4
Interview practice
An LLM-powered interviewer can sustain a question-and-answer conversation and analyze the completed interview for strengths and areas to improve. The user, rather than the model, controls when the session closes. section 10.1 section 10.1.1


































































