{"id":332,"date":"2025-05-23T10:46:13","date_gmt":"2025-05-23T10:46:13","guid":{"rendered":"https:\/\/felixaugenstein.com\/blog\/?p=332"},"modified":"2025-05-23T10:46:13","modified_gmt":"2025-05-23T10:46:13","slug":"building-genai-apps-with-langchain-fastapi-streamlit","status":"publish","type":"post","link":"https:\/\/felixaugenstein.com\/blog\/building-genai-apps-with-langchain-fastapi-streamlit\/","title":{"rendered":"Building GenAI Apps with LangChain, FastAPI &amp; Streamlit"},"content":{"rendered":"\n<p>The rapid evolution of generative AI has unlocked endless possibilities\u2014from chatbots and email generators to advanced research assistants. But creating full-stack GenAI apps can feel daunting without the right tools.<\/p>\n\n\n\n<p>Therefore I tried to build some GenAI apps myself with the <strong><a href=\"https:\/\/github.com\/FelixAugenstein\/langchain-genai-apps\">LangChain GenAI Apps<\/a><\/strong> repository: a hands-on template for building practical AI applications using <strong>LangChain<\/strong>, <strong>FastAPI<\/strong>, and <strong>Streamlit<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>The project is organized into two main folders:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udce6 <code>fastapi-app\/<\/code>: The Backend<\/h3>\n\n\n\n<p>This is where the brain of your application lives. It uses <strong>FastAPI<\/strong>, a modern, high-performance Python web framework, to expose multiple endpoints for text generation tasks.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u2728 Key Use Cases Included:<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>General Text Generation<\/strong>: Using either OpenAI or a local Ollama model.<\/li>\n\n\n\n<li><strong>Custom Prompt Generators<\/strong>:\n<ul class=\"wp-block-list\">\n<li>\ud83c\udf7d\ufe0f Recipe Generator<\/li>\n\n\n\n<li>\ud83d\udce7 Marketing Email Generator<\/li>\n\n\n\n<li>\ud83e\udde0 Therapy Advice Generator<\/li>\n\n\n\n<li>\u270d\ufe0f Blog Post Generator<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>RAG (Retrieval-Augmented Generation)<\/strong>: Generate responses grounded in external data.<\/li>\n\n\n\n<li><strong>AI Agent with Web Search<\/strong>: A LangChain agent that uses web search to answer user queries.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83c\udfa8 <code>streamlit-app\/<\/code>: The Frontend<\/h3>\n\n\n\n<p>Each backend use case is paired with a simple UI built in <strong>Streamlit<\/strong>\u2014a Python library that turns scripts into interactive apps in minutes.<\/p>\n\n\n\n<p>These apps let users input data, tweak prompts, and interact with the AI in real-time.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>In the following section you will get an overview of the tech stack.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">LangChain<\/h3>\n\n\n\n<p><strong>LangChain<\/strong> is a powerful framework designed to simplify the development of applications using large language models (LLMs). It provides modular building blocks that make it easier to create both simple and advanced AI workflows. Some of the key components include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\ud83d\udd17 Chains<\/strong>: Sequences of calls (to LLMs, tools, or other functions) that are composed together to perform complex tasks. Chains allow you to combine prompts, model outputs, and logic into coherent workflows.<\/li>\n\n\n\n<li><strong>\ud83e\udde0 Memory<\/strong>: Keeps track of previous interactions or context within a session. This is crucial for creating stateful agents or chatbots that &#8220;remember&#8221; past messages.<\/li>\n\n\n\n<li><strong>\ud83d\udee0\ufe0f Tools<\/strong>: External utilities that the LLM can call during execution, such as web search APIs, calculators, or custom functions.<\/li>\n\n\n\n<li><strong>\ud83e\udd16 Agents<\/strong>: Dynamic decision-making entities that use LLMs to choose which tools or actions to invoke based on user input. Agents are ideal for tasks where the flow can&#8217;t be predetermined.<\/li>\n\n\n\n<li><strong>\ud83d\udcc4 PromptTemplates<\/strong>: Templates used to generate consistent, structured prompts from user input and context variables, ensuring better LLM responses.<\/li>\n\n\n\n<li><strong>\ud83d\udcda Document Loaders &amp; Text Splitters<\/strong>: Utilities to load and chunk documents for use in Retrieval-Augmented Generation (RAG) scenarios.<\/li>\n\n\n\n<li><strong>\ud83d\udd0e Retrievers &amp; Vector Stores<\/strong>: Core components of RAG workflows. They retrieve relevant documents or data chunks based on semantic similarity to user queries.<\/li>\n<\/ul>\n\n\n\n<p>In this project, LangChain is used to implement everything from basic text generation to more advanced workflows like RAG pipelines and web-search-enabled agents.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">FastAPI<\/h3>\n\n\n\n<p><strong>FastAPI<\/strong> is one of the fastest web frameworks for building APIs in Python. It\u2019s intuitive, comes with built-in data validation, and is ideal for deploying LangChain workflows as production-ready endpoints. For an overview to get started with FastAPI and uv, check out this <a href=\"https:\/\/felixaugenstein.com\/blog\/getting-started-with-fastapi-and-uv-a-lightweight-python-web-framework-stack\/\">blog post<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Streamlit<\/h3>\n\n\n\n<p><strong>Streamlit<\/strong> is a favorite among data scientists and AI engineers for building frontends fast. It\u2019s Python-native, super quick to prototype with, and integrates seamlessly with FastAPI backends.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">How to the repository<\/h3>\n\n\n\n<p>You can explore and clone the full project here:<br>\ud83d\udc49 <a href=\"https:\/\/github.com\/FelixAugenstein\/langchain-genai-apps\">LangChain GenAI Apps GitHub Repository<\/a><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Clone the repo<\/strong>: <code>git clone https:\/\/github.com\/your-username\/langchain-genai-apps <\/code><\/li>\n\n\n\n<li><strong>Run the FastAPI backend<\/strong> from the <code>fastapi-app<\/code> folder.<\/li>\n\n\n\n<li><strong>Run the Streamlit frontend<\/strong> from the <code>streamlit-app<\/code> folder.<\/li>\n<\/ol>\n\n\n\n<p>Each folder contains a <code>README.md<\/code> with full instructions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The rapid evolution of generative AI has unlocked endless possibilities\u2014from chatbots and email generators to advanced research assistants. But creating full-stack GenAI apps can feel daunting without the right tools. Therefore I tried to build some GenAI apps myself with the LangChain GenAI Apps repository: a hands-on template for building [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":334,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,58,55,59,54,27,19,60],"tags":[],"class_list":["post-332","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application","category-fastapi","category-generative-ai","category-langchain","category-large-language-models","category-python","category-rest-apis","category-streamlit"],"_links":{"self":[{"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/posts\/332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/comments?post=332"}],"version-history":[{"count":1,"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/posts\/332\/revisions"}],"predecessor-version":[{"id":335,"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/posts\/332\/revisions\/335"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/media\/334"}],"wp:attachment":[{"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/media?parent=332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/categories?post=332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/felixaugenstein.com\/blog\/wp-json\/wp\/v2\/tags?post=332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}