<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Elinson on Medium]]></title>
        <description><![CDATA[Stories by Elinson on Medium]]></description>
        <link>https://medium.com/@elinson?source=rss-67fca2f3dd91------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*T2LVlt9AqxAXRBZKKE1kFw@2x.jpeg</url>
            <title>Stories by Elinson on Medium</title>
            <link>https://medium.com/@elinson?source=rss-67fca2f3dd91------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 08:08:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@elinson/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Lab #6: Chat with Cloud Diagram Agent (ChatGPT, Langchain & Streamlit)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://aiadvances.org/lab-6-chat-with-cloud-diagram-agent-chatgpt-langchain-streamlit-67ac3e211933?source=rss-67fca2f3dd91------2"><img src="https://cdn-images-1.medium.com/max/2012/1*M8Pwi9p_J_ng0zTheq8XaA.png" width="2012"></a></p><p class="medium-feed-snippet">Generate diagrams using the LLM Agent, which supports platforms such as AWS, Azure, IBM, etc.</p><p class="medium-feed-link"><a href="https://aiadvances.org/lab-6-chat-with-cloud-diagram-agent-chatgpt-langchain-streamlit-67ac3e211933?source=rss-67fca2f3dd91------2">Continue reading on AI Advances »</a></p></div>]]></description>
            <link>https://aiadvances.org/lab-6-chat-with-cloud-diagram-agent-chatgpt-langchain-streamlit-67ac3e211933?source=rss-67fca2f3dd91------2</link>
            <guid isPermaLink="false">https://medium.com/p/67ac3e211933</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Elinson]]></dc:creator>
            <pubDate>Fri, 23 Aug 2024 19:00:21 GMT</pubDate>
            <atom:updated>2024-08-24T05:09:06.733Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Lab #5: Chat with Multi-Agents (CrewAI, ChatGPT and Streamlit)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://blog.stackademic.com/lab-5-chat-with-multi-agents-crewai-chatgpt-and-streamlit-b91960064816?source=rss-67fca2f3dd91------2"><img src="https://cdn-images-1.medium.com/max/1548/1*4UKWHHJHW4u6Lemg9sJlVg.png" width="1548"></a></p><p class="medium-feed-snippet">Chatting with multi-agents is as simple as you can</p><p class="medium-feed-link"><a href="https://blog.stackademic.com/lab-5-chat-with-multi-agents-crewai-chatgpt-and-streamlit-b91960064816?source=rss-67fca2f3dd91------2">Continue reading on Stackademic »</a></p></div>]]></description>
            <link>https://blog.stackademic.com/lab-5-chat-with-multi-agents-crewai-chatgpt-and-streamlit-b91960064816?source=rss-67fca2f3dd91------2</link>
            <guid isPermaLink="false">https://medium.com/p/b91960064816</guid>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[streamlit]]></category>
            <dc:creator><![CDATA[Elinson]]></dc:creator>
            <pubDate>Sat, 03 Aug 2024 10:45:15 GMT</pubDate>
            <atom:updated>2024-08-05T01:32:22.589Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Lab #4: Chat with 10M data records (ChatGPT, PandasAI and Streamlit)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://blog.gopenai.com/lab-4-chat-with-10m-data-records-b2da20c4d9da?source=rss-67fca2f3dd91------2"><img src="https://cdn-images-1.medium.com/max/2356/1*NMiCDm8OGRjDWeOqudxwAA.png" width="2356"></a></p><p class="medium-feed-snippet">Ask question about your data in natural language</p><p class="medium-feed-link"><a href="https://blog.gopenai.com/lab-4-chat-with-10m-data-records-b2da20c4d9da?source=rss-67fca2f3dd91------2">Continue reading on GoPenAI »</a></p></div>]]></description>
            <link>https://blog.gopenai.com/lab-4-chat-with-10m-data-records-b2da20c4d9da?source=rss-67fca2f3dd91------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2da20c4d9da</guid>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[streamlit]]></category>
            <dc:creator><![CDATA[Elinson]]></dc:creator>
            <pubDate>Tue, 16 Jul 2024 17:16:53 GMT</pubDate>
            <atom:updated>2024-07-19T09:02:46.231Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Lab #3: Implementing RAG to build a “Chat with Multiple PDFs” app]]></title>
            <link>https://blog.gopenai.com/lab-3-implementing-rag-to-build-a-chat-with-multiple-pdfs-app-88c1d7cd5d19?source=rss-67fca2f3dd91------2</link>
            <guid isPermaLink="false">https://medium.com/p/88c1d7cd5d19</guid>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Elinson]]></dc:creator>
            <pubDate>Tue, 02 Jul 2024 08:17:35 GMT</pubDate>
            <atom:updated>2024-08-25T10:20:32.070Z</atom:updated>
            <content:encoded><![CDATA[<p>Using Streamlit, Langchain and OpenAI</p><blockquote>This is Part 2 of the article <strong>“Chat with PDF”</strong>, which was posted in the<a href="https://github.com/S0NM/chat-with-everything"><strong>“Chat with Everything”</strong></a> series. This part will focus on how to work with RAG to build a chat app with multiple PDFs.</blockquote><blockquote>For those of you who don’t know, the <strong>“Chat with Everything”</strong> series is a series that focuses on providing you with the tech knowledge and techniques in building LLM applications. All applications I’ve created using popular frameworks: Streamlit, Langchain &amp; OpenAI (LLM model).</blockquote><blockquote>You can find “Chat with Everything” series here: <a href="https://github.com/S0NM/chat-with-everything">My github</a></blockquote><h4>Difficulty Level: Intermediate 🎖️🎖️</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UTIFLGV3Wx0qNThJrJ8UhA.png" /></figure><h4>The main content I’m going to cover in this article:</h4><ol><li>Why is RAG important?</li><li>How RAG actually works</li><li>Applying RAG to build a “chat with multiple PDFs” app</li><li>Demo (For those of you who want to see the results first to be motivated.)</li></ol><h3>1. Why is RAG important?</h3><p>While using LLM models like GPT, Claude, BERT, etc., you might have encountered the following problems:</p><ul><li>The model fictionalizes the information and creates an unreal answer <strong>(hallucination effect)</strong></li><li>You want models <strong>running on your own data sources</strong>, from text data (pdf, doc, etc.) to various type of media data (video, audio, photo, etc.)</li><li>Sometimes, you work with very long content, resulting in <strong>expensive processing costs</strong> or your account simply being blocked for 1-2 hours (impacts on your productivity)</li></ul><p>If you’re sympathetic to the above problems, it’s time to learn about RAG.</p><h4>What is RAG?</h4><p><strong>RAG (Retrieval-augmented generation)</strong> is a technique for enhancing the accuracy and reliability of generative AI models with facts fetched from external sources. RAG is an important technique because:</p><ul><li><strong>Nearly every LLM</strong> can connect to almost any external resource using RAG.</li><li><strong>RAG makes your application more reliable (</strong>“TRUST”) to our users. Why? Because RAG gives models sources they can cite, like footnotes in a research paper, so users can check any claims. That builds trust.</li><li><strong>Reduces the possibility a model will make a wrong guess</strong>, a phenomenon sometimes called hallucination.</li><li>Finally, RAG makes the method <strong>faster and less expensive than retraining a model</strong> with additional datasets. And it lets users hot-swap new sources on the fly.</li></ul><h3>2. How RAG actually works</h3><p>At a high-level, the whole RAG process is illustrated in 2 phases:</p><ul><li><strong>Phase 1 (Pre-processing):</strong> Load external sources into our system</li><li><strong>Phase 2 (Inference):</strong> Generate answer for your user’s query with the support of LLM</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ebOb_Y5DckOhw9wA_9fnHw.png" /><figcaption><strong><em>Two-Phases in RAG process</em></strong></figcaption></figure><p>Let’s dive into two phases</p><p><strong>Phase 1: Pre-processing Phase</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g0EDp-JlQWgygJzs064vzw.png" /><figcaption>An example of processing with PDF file</figcaption></figure><p><strong>1. Load data from external sources to text:</strong> this process is done easily with the support of the langchain framework.</p><ul><li>In the above example, I use <strong>PyPDFLoader</strong> to load data from a PDF file</li><li>In practice, I also use other Document loaders to load the data from YouTube, CSV, Confluence, etc.</li><li>Y<a href="https://python.langchain.com/v0.2/docs/integrations/document_loaders/">ou can visit langchain official website</a> to get a list of all Document Loader</li></ul><p><strong>2. Transform Text into Chunks: </strong>Split text into small chunks to optimize processing, storage, and retrieval of information, while improving the quality and accuracy of AI systems.</p><p><strong>3. Embed Chunks into Vector Database: </strong>Vector database is considered to be the most common way in RAG implementation stack (in this article, I also chose a vector database that runs easily on local disk, which is Chroma). Selecting the best vector database is not covered in this article. If you want to go deep into the topic,<a href="https://superlinked.com/vector-db-comparison?via=topaitools"> <strong><em>please check the list from SuperLinked</em></strong></a><strong><em>.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RbXFm3XsVRTVqPDvwTWB8g.png" /><figcaption>An example of the comparison between vector database product</figcaption></figure><p><strong>Phase 2: The inference runtime phase</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bHYLb-naJkzApseh8hB9mQ.png" /></figure><p><strong>1. Input query (Question):</strong> The user who entered the query needs to be answered or processed.</p><p><strong>2. Embedding queries:</strong> Queries converted to embedding using an embedded model (embedding model).</p><p><strong>3. Information retrieval:</strong> Use the vector representation of the query to find relevant text from a large database containing embedded text.</p><p><strong>4. Text generator:</strong> The extracted text will be used with the original query to generate a new answer or text. Generators (usually large language models) will combine information from these text passages to generate feedback.</p><p><strong>5. Output (Answer)</strong>: The text created will be returned to the user as a complete answer.</p><h3>3. Applying RAG to build a “Chat with multiple PDFs” app</h3><p>Once you know how RAG works, it’s time to build a “chat with multiple PDFs” with me. And see how I apply RAG into practical application</p><h4><strong>Setup</strong></h4><p>Firstly, we need to install all packages</p><pre>import streamlit as st<br>from langchain_community.document_loaders import PyPDFLoader<br>from langchain_openai import ChatOpenAI, OpenAIEmbeddings<br>from langchain.prompts import ChatPromptTemplate<br>from langchain_community.vectorstores import Chroma<br>import chromadb<br>from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction<br>from langchain.text_splitter import RecursiveCharacterTextSplitter<br>from langchain.chains.combine_documents import create_stuff_documents_chain<br>from langchain.chains.retrieval import create_retrieval_chain</pre><p>Replace OPENAI_API_KEY with your own key, in the example, i’ve used streamlit secret instead:</p><pre># Replace it with your OPENAI API KEY if you use streamlit secrets<br>OPENAI_API_KEY = st.secrets[&quot;OPENAI_API_KEY&quot;]</pre><p>Create collection named <strong>“chat-with-pdf”</strong> into <strong>ChromaDB</strong></p><pre># Load Vector datasse<br>native_db = chromadb.PersistentClient(&quot;./chroma_db&quot;)<br>db = Chroma(client=native_db, collection_name=&quot;chat-with-pdf&quot;, embedding_function=OpenAIEmbeddings())</pre><p>In order to work with the collection, we will use the function <strong>get_collection</strong></p><pre>@st.cache_resource<br>def get_collection():<br>    print(&quot;DEBUG: call get_collection()&quot;)<br>    collection = None<br>    try:<br>        # Delete all documents<br>        native_db.delete_collection(&quot;chat-with-pdf&quot;)<br>    except:<br>        pass<br>    finally:<br>        collection = native_db.get_or_create_collection(&quot;chat-with-pdf&quot;, embedding_function=OpenAIEmbeddingFunction(api_key=OPENAI_API_KEY))<br>    return collection</pre><h4><strong>Phase 1:</strong> Pre-Processing Phase</h4><p>When user uploads some new files:</p><ul><li>Load all new uploaded files</li><li>Split their content into chunks</li><li>Embed chunks into ChromaDB, using and save them into ChromaDB</li></ul><pre># Load, transform and embed new files into Vector Database<br>def add_files(uploaded_files):<br>    collection = get_collection()<br><br>    # old_filenames: contains a list of names of files being used<br>    # uploaded_filenames: contains a list of names of uploaded files<br>    old_filenames = st.session_state.old_filenames<br>    uploaded_filename = [file.name for file in uploaded_files]<br>    new_files = [file for file in uploaded_files if file.name not in old_filenames]<br><br>    for file in new_files:<br>        # Step 1: load uploaded file<br>        temp_file = f&quot;./temp/{file.name}.pdf&quot;<br>        with open(temp_file, &quot;wb&quot;) as f:<br>            f.write(file.getvalue())<br>        loader = PyPDFLoader(temp_file)<br>        pages = loader.load()<br><br>        # Step 2: split content in to chunks<br>        text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)<br>        chunks = text_splitter.split_documents(pages)<br><br>        # Step 3: embed chunks into Vector Store<br>        # collection.add(ids=file.name,documents=chunks)<br>        for index, chunk in enumerate(chunks):<br>            collection.upsert(<br>                ids=[chunk.metadata.get(&quot;source&quot;) + str(index)], metadatas=chunk.metadata,<br>                documents=chunk.page_content<br>            )</pre><p>Otherwise, when user removes a file from the list, we need to remove all relevant chunks</p><pre># Remove all relevant chunks of the removed files<br>def remove_files(uploaded_files):<br>    collection = get_collection()<br><br>    # old_filenames: contains a list of names of files being used<br>    # uploaded_filenames: contains a list of names of uploaded files<br>    old_filenames = st.session_state.old_filenames<br>    uploaded_filename = [file.name for file in uploaded_files]<br><br>    # Step 1: Get the list of file that was removed from upload files<br>    deleted_filenames = [name for name in old_filenames if name not in uploaded_filename]<br><br>    # Step 2: Remove all relevant chunks of the removed files<br>    if len(deleted_filenames) &gt; 0:<br>        all_chunks = collection.get()<br><br>        ids = all_chunks[&quot;ids&quot;]<br>        metadatas = all_chunks[&quot;metadatas&quot;]<br><br>        if len(metadatas) &gt; 0:<br>            deleted_ids = []<br>            for name in deleted_filenames:<br>                for index, metadata in enumerate(metadatas):<br>                    if metadata[&#39;source&#39;] == f&quot;./temp/{name}.pdf&quot;:<br>                        deleted_ids.append(ids[index])<br>            collection.delete(ids=deleted_ids)</pre><p>Combine two methods into one function</p><pre># Return chunks after having any change in the file list<br>def refresh_chunks(uploaded_files):<br>    # old_filenames: contains a list of names of files being used<br>    # uploaded_filenames: contains a list of names of uploaded files<br>    old_filenames = st.session_state.old_filenames<br>    uploaded_filename = [file.name for file in uploaded_files]<br><br>    if len(old_filenames) &lt; len(uploaded_filename):<br>        add_files(uploaded_files)<br>    elif len(old_filenames) &gt; len(uploaded_filename):<br>        remove_files(uploaded_files)<br><br>    # Step 3: Save the state<br>    st.session_state.old_filenames = uploaded_filename</pre><h4>Phase 2: The Inference Runtime Phase</h4><ul><li>Create a Retriever to work with ChromaDB. Retriever is an interface that returns documents given an unstructured query.</li><li>Create a chain to link everything together</li></ul><pre># Init langchain<br>llm = ChatOpenAI(api_key=OPENAI_API_KEY)<br>prompt = ChatPromptTemplate.from_template(&quot;&quot;&quot;<br>Based on the provided context only, find the best answer for my question. Format the answer in markdown format<br>&lt;context&gt;<br>{context}<br>&lt;/context&gt;<br>Question:{input}<br>&quot;&quot;&quot;)<br>document_chain = create_stuff_documents_chain(llm, prompt)<br>retriever = db.as_retriever()<br>retriever_chain = create_retrieval_chain(retriever, document_chain)</pre><p>Whenever you want to work with <strong>retriever_chain</strong>, you can call <strong>invoke. </strong>For example:</p><pre>response = retriever_chain.invoke({&quot;input&quot;: &quot;How to create a prompt for a new digital product&quot;})</pre><p>The final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vwqWul8Fdbl_zErRRgMl3Q.png" /></figure><h3>4. Show case</h3><p>Video Demo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*wk8fVYUBfsgDWAMDGrxcMg.gif" /></figure><h3>Bonus 🎁</h3><p>You can easily search for practical examples using RAG. Here’s an interesting example of how to use RAG in text-to-sql: <strong>VannaAI</strong></p><p><strong>VannaAI</strong> has over 9k stars and 658 forks (at the time I wrote this article). Details can be found <a href="https://vanna.ai/docs/">here</a> <a href="https://vanna.ai/docs/">.</a> VannaAI is applying RAG to two things:</p><ul><li>Use retrieval augmentation to help you generate accurate SQL queries for your database using LLMs.</li><li>You can train a RAG “model” on your own data and then ask questions which will return SQL queries that can be set up to automatically run on your database.”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g66Dw6RvzIBSuf9lylLn_A.png" /></figure><h3>Before you go! 🤟</h3><p>If you found value in this article and wish to show your support, <strong>clap my article 10 times. </strong>👏, that will really motivate me and boost this article to others.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88c1d7cd5d19" width="1" height="1" alt=""><hr><p><a href="https://blog.gopenai.com/lab-3-implementing-rag-to-build-a-chat-with-multiple-pdfs-app-88c1d7cd5d19">Lab #3: Implementing RAG to build a “Chat with Multiple PDFs” app</a> was originally published in <a href="https://blog.gopenai.com/">GoPenAI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lab #2: Chat with YouTube (ChatGPT, Langchain and Streamlit)]]></title>
            <link>https://blog.gopenai.com/lab-2-chat-with-youtube-fdda0c3e1567?source=rss-67fca2f3dd91------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdda0c3e1567</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Elinson]]></dc:creator>
            <pubDate>Wed, 26 Jun 2024 15:47:23 GMT</pubDate>
            <atom:updated>2024-08-14T15:51:37.766Z</atom:updated>
            <content:encoded><![CDATA[<p>Ask anything about YouTube video content</p><blockquote><strong>Chat with YouTube </strong>is an article in the Series <a href="https://github.com/S0NM/chat-with-everything"><strong>“Chat with Everything”</strong></a><strong> </strong>addressed to those of you who are in the process of starting to learn the applications of LLMs. The series focuses on the techniques of working with the LLM and implementing them in simple applications using popular tech stacks like Streamlit &amp; Langchain.</blockquote><blockquote>You can find “Chat with Everything” Series here: <a href="https://github.com/S0NM/chat-with-everything">My github</a></blockquote><h4><strong>Difficulty Level: Beginner</strong> 🎖️</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*usgG7CMhA-idbihbMtOhTQ.png" /><figcaption><strong><em>How many creative ideas can you think of for combining LLMs and YouTube?</em></strong></figcaption></figure><h3>1. Story Behind</h3><h4>YouTube is the world’s largest video resource</h4><p>YouTube is the world’s largest video resource, containing all kinds of knowledge, from lectures and technical tutorials to entertainment and news. By combining the strengths of LLMs and YouTube, we can create exciting applications that solve many practical use cases, such as:</p><ul><li><strong>Content Summarization: </strong>Generate summaries and extract key points from news, lectures, and podcasts</li><li><strong>Content Review: </strong>Write a critique of a well-known film.</li><li><strong>Information Synthesis:</strong> Supports searching and synthesizing information from video seminars and research lectures.</li><li><strong>Hot Trend Analysis</strong> analyzes and predicts content trends, helping advertisers understand the latest trends on social media.</li><li><strong>Automatic Translation:</strong> Translates videos into different languages, expanding the reach of content.</li></ul><p><strong>Your turn:</strong> How many innovative ideas can you think of combining LLMs and YouTube?</p><h3>2. Let’s start with a simple chat app</h3><p>First, let’s see what we will achieve with the project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*pctnjXsXeuuxl_P8C_RSqA.gif" /><figcaption><strong>Chat with a kid story</strong></figcaption></figure><p>I won’t go into step-by-step implementation because you can find them here: <a href="https://github.com/S0NM/chat-with-everything/tree/main/chat-with-pdf">Github Link</a></p><h3>3. How it works</h3><p>Langchain is an incredibly powerful framework that simplifies interaction with popular models today (here, I use the gpt-3.5 model). The two most important steps in that application are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2XUEqenwfTenOtgbm0_rbw.png" /></figure><p><strong>Step 1: Convert from Video to Text</strong></p><pre># If YouTube video has transcript then return it<br>def get_trascript_content(url):<br>    content = &quot;&quot;<br>    try:<br>        parsed_url = urlparse(url)<br>        query_params = parse_qs(parsed_url.query)<br>        video_id = query_params.get(&#39;v&#39;, [None])[0]<br>        transcript_list = YouTubeTranscriptApi.get_transcript(video_id)<br><br>        #Get the content only<br>        for transcript in transcript_list:<br>            content = content + transcript[&quot;text&quot;]<br>    except Exception as e:<br>        print(f&quot;GETTING TRANSCRIPT FAILED: {e}&quot;)<br>    return content<br><br># If YouTube video has no transcript<br>def video_to_text(url):<br>    save_dir = &quot;./temp/&quot;<br><br>    loader = GenericLoader(YoutubeAudioLoader([url], save_dir), OpenAIWhisperParser())<br>    docs = loader.load()<br>    combined_content = [doc.page_content for doc in docs]<br>    content = &quot; &quot;.join(combined_content)<br><br>    # Save content<br>    st.session_state.content = content<br>    return content</pre><p><strong>Step 2: Working with any LLM </strong><br>Using a template prompt, create a chain. In the template prompt, two variables, {content} and {question}, will be passed on later.</p><pre>llm = ChatOpenAI(api_key=OPENAI_API_KEY)<br>output_parser = StrOutputParser()<br>prompt = ChatPromptTemplate.from_messages(<br>    [(&quot;system&quot;, &quot;You are a very helpful assistant&quot;),<br>     (&quot;user&quot;, &quot;Based on my content:{content}. Please answer my question: {question}&quot;)]<br>)<br><br># The beauty of langchain is this simple line of code  <br>chain = prompt | llm | output_parser</pre><p>The Q&amp;A process with the LLM is called by code</p><pre>response = chain.invoke({&quot;content&quot;: st.session_state.content, &quot;question&quot;: question})</pre><h3>4. Digging Deeper</h3><p>If you want to challenge yourself, here are some ideas for you, guys:</p><p>Implement full RAG pipeline to handle large amount of content quickly and efficiently ( I’ll update in another post)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dh9y27qTGPoTxN9lql2Mbg.png" /><figcaption><strong>Apply RAG Pipeline (Phase 1)</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nbPle_R2KQGIHpOZN8nyJg.png" /><figcaption><strong>Apply RAG Pipeline (Phase 2)</strong></figcaption></figure><p>Besides, there are some thoughts you might be considering for your application</p><p>🎖️🎖️ Intermediate Level</p><ul><li><strong>Selecting the Optimal LLM: </strong>Explore various LLM models like GPT-4-turbo and determine which one delivers the best performance for your application.</li><li><strong>Enhancing Transcript Quality:</strong> Focus on preprocessing YouTube video transcripts by removing noise and redundant data and improving the structure to ensure high-quality input for the LLM.</li><li><strong>Segmenting Long Videos: </strong>Learn techniques for breaking down lengthy video content into smaller, relevant segments to efficiently process with LLMs, considering token limits and cost optimization.</li></ul><p>🎖️🎖️🎖️ Advanced Level</p><ul><li><strong>Complex State Management: </strong>Develop sophisticated methods to handle conversation context over multiple interactions, ensuring seamless user experiences.</li><li><strong>Integrating Multimedia Elements:</strong> Implement solutions to extract and interpret non-text elements such as images, graphs, and audio from YouTube videos to provide comprehensive answers.</li><li><strong>Real-Time Performance Tuning: </strong>Optimize the application to minimize latency and manage costs effectively when making real-time requests to LLMs.</li><li><strong>Domain-Specific Model Fine-Tuning: </strong>Train the LLM with specialized datasets relevant to your application domain to enhance accuracy and relevance of responses.</li></ul><h3>Before you go! 🤟</h3><p>If you found value in this article and wish to show your support, <strong>clap my article 10 times. </strong>👏, that will really motivate me and boost this article to others.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdda0c3e1567" width="1" height="1" alt=""><hr><p><a href="https://blog.gopenai.com/lab-2-chat-with-youtube-fdda0c3e1567">Lab #2: Chat with YouTube (ChatGPT, Langchain and Streamlit)</a> was originally published in <a href="https://blog.gopenai.com/">GoPenAI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lab #1: Chat with PDF (ChatGPT, Langchain and Streamlit)]]></title>
            <link>https://medium.com/@elinson/chat-with-pdf-using-langchain-streamlit-92309684b214?source=rss-67fca2f3dd91------2</link>
            <guid isPermaLink="false">https://medium.com/p/92309684b214</guid>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Elinson]]></dc:creator>
            <pubDate>Sun, 23 Jun 2024 09:29:51 GMT</pubDate>
            <atom:updated>2024-08-14T15:54:14.363Z</atom:updated>
            <content:encoded><![CDATA[<p><em>The first step to bringing AI into our lives is to play with it</em></p><blockquote><strong>Chat with PDF<em> </em></strong><em>is the first article in the Series </em><a href="https://github.com/S0NM/chat-with-everything/"><strong><em>“Chat with Everything”</em></strong></a><em> addressed to those of you who are in the process of starting to learn the applications of LLMs. The series focuses on the techniques of working with the LLM and implementing them in simple applications using popular tech stacks like Streamlit &amp; Langchain.</em></blockquote><blockquote><em>You can find “Chat with Everything” Series here: </em><a href="https://github.com/S0NM/chat-with-everything"><em>My github</em></a></blockquote><p><strong>Difficulty Level: Beginner</strong> 🎖️</p><h3>1. Story Behind</h3><h4>How Important is Working with PDFs?</h4><p>PDF is a standard document format that is widely used in your day-to-day work, from daily reports, sales documents, aggregate research documents, invoice information, and contracts. The PDF can be said to be <strong>“Knowledge mine containing gold data”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jiibGq2JiFv9TANsh5cn6Q.png" /><figcaption><em>Knowledge mine containing gold data</em></figcaption></figure><p><strong>In fact:</strong> Imagine you’re a researcher working with thousands of pages of PDF documents containing valuable information. Searching for specific information in this pool of documents is a huge challenge and a time-consuming task. That’s when we need the support of our LLMs.</p><h3>2. Let’s start with a simple chat app</h3><p>First, let’s see what we will achieve with the project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*7cmVyy-Br-qzseGsnhcPxA.gif" /><figcaption>Chat with PDF demo</figcaption></figure><h3>3. How it works</h3><p>I won’t go into step-by-step implementation because you can find them here: <a href="https://github.com/S0NM/chat-with-everything/tree/main/chat-with-pdf">Github Link</a></p><p><strong>How the application works is described in the following picture:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vryZbthoMMriUIrSrLLKfg.png" /></figure><p>The two most important steps:</p><p><strong>1) Load full content from any data source (this is a PDF):</strong></p><p>To do that, langchain supports a lot of different “Document Loaders”. Here I use PyPDFLoader to load content from PDF :</p><pre>loader = PyPDFLoader(temp_file)  <br>pages = loader.load()<br><br># Get the full content of the PDF file  <br>content = &quot;&quot;  <br>for page in pages:  <br>    content = content + &quot;\n\n&quot; + page.page_content  <br>st.session_state.content = content</pre><p><strong>2) Working with any LLM: </strong><br>Using a template prompt, create a chain. In the template prompt, two variables, {content} and {question}, will be passed on later.</p><pre>prompt = ChatPromptTemplate.from_messages(  <br>    [(&quot;system&quot;, &quot;You are a very helpful assistant&quot;),  <br>     (&quot;user&quot;,  <br>      &quot;Based on my Pdf content:{content}. Please answer my question: {question}. Please use the language that I used in the question&quot;)]  <br>)  <br>llm = ChatOpenAI(api_key=OPENAI_API_KEY)  <br>output_parser = StrOutputParser()<br><br># The beauty of langchain is this simple line of code  <br>chain = prompt | llm | output_parser</pre><p>The Q&amp;A process with the LLM is called by code</p><pre>response = chain.invoke({&quot;content&quot;: st.session_state.content, &quot;question&quot;: question})</pre><h3>4. Digging Deeper</h3><p>If you want to challenge yourself, here are some ideas for you, guys:</p><h4><strong>🎖️🎖️ Intermediate Level</strong></h4><ul><li><strong>Finding the Right Model: </strong>Experiment with different LLM models to find the one that best suits your problem.</li><li><strong>Input Text Processing:</strong> For optimal results, input text quality is crucial. Focus on preprocessing the input text, such as cleaning, removing redundant information, or rearranging the input data.</li><li><strong>Applying text segmentation to handle large content &amp; optimizing the cost of processing:</strong> Study techniques for how to split large documents into smaller chunks to send relevant chunks to the LLM model (e.g., GPT-3.5-turbo has a limit of 16,385 tokens). GPT-4-turbo and GPT-4o will have a limit of 128,000 tokens.</li></ul><h4>🎖️🎖️🎖️ Advanced Level</h4><ul><li><strong>Advanced State Management:</strong> Manage more complex conversation states, maintain context across multiple requests, and improve personal experiences</li><li><strong>Handling Non-Text Elements:</strong> Study on recognizing and processing images, charts, and tables in PDFs using additional tools.</li><li><strong>Performance Optimization:</strong> Optimize costs and latency when sending requests to LLM models in real-time applications.</li><li><strong>Model Customization: </strong>Fine-tune the model with domain-specific data to improve performance for specialized applications.</li></ul><h3>Before you go! 🤟</h3><p>If you found value in this article and wish to show your support, <strong>clap my article 10 times </strong>👏, that will really motivate me and boost this article to others.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92309684b214" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>