<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: hiimivantang</title>
    <description>The latest articles on DEV Community by hiimivantang (@hiimivantang).</description>
    <link>https://dev.to/hiimivantang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1092854%2F4e8e1f7d-7bcd-48a9-8d0a-5dd264ac81f1.png</url>
      <title>DEV Community: hiimivantang</title>
      <link>https://dev.to/hiimivantang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hiimivantang"/>
    <language>en</language>
    <item>
      <title>A gentle introduction to 🦜️🔗Langchain</title>
      <dc:creator>hiimivantang</dc:creator>
      <pubDate>Wed, 26 Jul 2023 15:50:15 +0000</pubDate>
      <link>https://dev.to/hiimivantang/a-gentle-introduction-to-langchain-5bd9</link>
      <guid>https://dev.to/hiimivantang/a-gentle-introduction-to-langchain-5bd9</guid>
      <description>&lt;p&gt;It's amazing how Langchain became so popular overnight (figuratively). In this post I explore what it does and why it became so hot. &lt;/p&gt;

&lt;h2&gt;
  
  
  Inception
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/langchain-ai/langchain" rel="noopener noreferrer"&gt;Langchain&lt;/a&gt; was open-sourced by &lt;a href="https://www.linkedin.com/in/harrison-chase-961287118/" rel="noopener noreferrer"&gt;Harrison Chase&lt;/a&gt; in October 2022 and in mere span of 9 months, it has gained a mind boggling 56.2K stars on its Github repo. To put the skyrocketing growth into perspective, it took &lt;a href="https://github.com/keras-team/keras" rel="noopener noreferrer"&gt;Keras&lt;/a&gt; 101 months (8 years) to gain 58.9k stars. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59fgksh4c8qr1qe4q3cz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59fgksh4c8qr1qe4q3cz.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👆 The growth looks ridiculous. &lt;/p&gt;

&lt;h2&gt;
  
  
  🤔 What exactly is Langchain?
&lt;/h2&gt;

&lt;p&gt;It is a Python framework designed to simplify the creation of applications using large language models (LLMs). Essentially, it comes with with powerful building blocks and integrations that you can use to build your own LLM application. However, simplify seems to be a understatement here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Getting started is easy. Install Langchain with a simple pip install.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install langchain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But wait, if you are using Python versions&amp;lt; 3.9 you probably will get clang compiler errors as such:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6p0me50c5x9hgmhclpps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6p0me50c5x9hgmhclpps.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For me, I like to use &lt;a href="https://github.com/pyenv/pyenv" rel="noopener noreferrer"&gt;pyenv&lt;/a&gt; to switch Python versions.&lt;/p&gt;

&lt;p&gt;Use Python version 3.9 to avoid the above errors when installing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pyenv install 3.9.16 
pyenv global 3.9.16
pip install langchain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Document loaders
&lt;/h2&gt;

&lt;p&gt;Document loaders provider an easy way to load data. As of today, there is a total of 115 document loaders. Loading from any supported sources are now reduced to just 2 lines of code: 1) initialize Loader object and 2) calling the &lt;code&gt;.load()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Even reading a Youtube transcript is simplified down to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.document_loaders&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;YoutubeLoader&lt;/span&gt;
&lt;span class="n"&gt;loader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;YoutubeLoader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_youtube_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://www.youtube.com/watch?v=QsYGlZkevEg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;add_video_info&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.tenor.com%2FYjx_r38x1aYAAAAS%2Fmind-blown-explosion.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.tenor.com%2FYjx_r38x1aYAAAAS%2Fmind-blown-explosion.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, I lied. You need 3 lines of code to load data from the supported sources. Remember to import the loader of your choice from &lt;code&gt;langchain.document_loaders&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For the full list of support sources, please see &lt;a href="https://python.langchain.com/docs/integrations/document_loaders/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chains and Document transformers
&lt;/h2&gt;

&lt;p&gt;Think of chains as a means to glue together multiple Langchain primitive components together. Of course, there are already a few "pre-glued" chains such as &lt;a href="https://python.langchain.com/docs/modules/chains/popular/summarize" rel="noopener noreferrer"&gt;Summarization&lt;/a&gt;, &lt;a href="https://python.langchain.com/docs/modules/chains/popular/vector_db_qa" rel="noopener noreferrer"&gt;Retrieval QA&lt;/a&gt;, &lt;a href="https://python.langchain.com/docs/modules/chains/popular/sqlite" rel="noopener noreferrer"&gt;SQL&lt;/a&gt;, and etc.&lt;/p&gt;

&lt;p&gt;Now, let's see how we can use a Summarization chain to summarize a recent Youtube video of ex-Senior Minister Mr Tharman's full team speeches for his intent to run for President of Singapore.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PromptTemplate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;LLMChain&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.chains.summarize&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_summarize_chain&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.document_loaders&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;YoutubeLoader&lt;/span&gt;

&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;openai_api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;YOUR-OPENAI-API-KEY&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;loader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;YoutubeLoader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_youtube_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://www.youtube.com/watch?v=7cZk5QPbmZ8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;add_video_info&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;docs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;chain&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_summarize_chain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chain_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;map_reduce&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;docs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhrpsqfig3cp9ci02ff01.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhrpsqfig3cp9ci02ff01.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately, our simple example to summarize the Youtube video didn't work. And the reason, is because gpt3.5 model currently accepts only max 4096 tokens and we have 7491 tokens (7235 in your prompt; 256 for the completion)! &lt;/p&gt;

&lt;p&gt;This is where Langchain's Document Transformers shine. Let's try again and use a &lt;code&gt;RecursiveCharacterTextSplitter&lt;/code&gt; to split our text.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PromptTemplate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;LLMChain&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.chains.summarize&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_summarize_chain&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.document_loaders&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;YoutubeLoader&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.text_splitter&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;RecursiveCharacterTextSplitter&lt;/span&gt;


&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;openai_api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;YOUR-OPENAI-API-KEY&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;loader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;YoutubeLoader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_youtube_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://www.youtube.com/watch?v=7cZk5QPbmZ8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;add_video_info&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;docs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;text_splitter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RecursiveCharacterTextSplitter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunk_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chunk_overlap&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;length_function&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;add_start_index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;texts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text_splitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_documents&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;docs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;page_content&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="n"&gt;chain&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_summarize_chain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chain_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;map_reduce&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;texts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🥳 And we get: &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Mr Tarman is a potential candidate for the Singaporean presidency who is known for his independence of thought, sharp intellect, and commitment to social justice. He is seen as a unifying figure who can bring people together and is an advocate for equality of resources in the international community. He has been a mentor to the speaker since 2005 and has helped many people escape poverty and discrimination. He is a respected diplomat and is socially savvy, often invited to events and offering other senior public office holders to grace such causes. He is the ideal candidate for the upcoming presidential election.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;I've barely scratch the surface on what's possible with Langchain but you have seen how with merely 11 lines, we manage to: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download a Youtube video transcript.&lt;/li&gt;
&lt;li&gt;Split the transcript into overlapping chunks.&lt;/li&gt;
&lt;li&gt;For each of the chunk, send a prompt together with the chunk itself to OpenAI API to get a summary.&lt;/li&gt;
&lt;li&gt;Finally, send a prompt to OpenAI API to get a summary of the summaries in step 3.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, I hope you understand why Langchain is so popular now. If not, try implementing the above without Langchain and see how much more time, effort, and hair pulled is required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/LangChain" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/LangChain&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://python.langchain.com/docs/modules/chains/" rel="noopener noreferrer"&gt;https://python.langchain.com/docs/modules/chains/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://js.langchain.com/docs/modules/data_connection/document_transformers/" rel="noopener noreferrer"&gt;https://js.langchain.com/docs/modules/data_connection/document_transformers/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://python.langchain.com/docs/modules/chains/popular/summarize" rel="noopener noreferrer"&gt;https://python.langchain.com/docs/modules/chains/popular/summarize&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>langchain</category>
      <category>llm</category>
      <category>chatgpt</category>
    </item>
    <item>
      <title>Dynamically generate docker-compose.yaml for YugabyteDB and more!</title>
      <dc:creator>hiimivantang</dc:creator>
      <pubDate>Wed, 31 May 2023 17:04:44 +0000</pubDate>
      <link>https://dev.to/hiimivantang/dynamically-generate-docker-composeyaml-for-yugabytedb-and-more-51me</link>
      <guid>https://dev.to/hiimivantang/dynamically-generate-docker-composeyaml-for-yugabytedb-and-more-51me</guid>
      <description>&lt;p&gt;&lt;code&gt;yb-docker-composer&lt;/code&gt; is Python-based CLI for generating docker-compose.yaml files dynamically based on the arguments specified at the CLI. &lt;/p&gt;

&lt;p&gt;Git repo: &lt;a href="https://github.com/hiimivantang/yb-docker-composer"&gt;https://github.com/hiimivantang/yb-docker-composer&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;I always find the notion of running docker containers from declarative config files a more elegant solution as opposed to just running them via &lt;code&gt;docker run&lt;/code&gt; commands. With docker-compose, I can easily set up and tear down different combination of services for testing or demo purposes.&lt;/p&gt;

&lt;p&gt;But wait. There’s already &lt;code&gt;yb-docker-ctl&lt;/code&gt; and that allows anyone to easily run YugabyteDB as containers while allowing customization such as the ability to specify replication factor or yb-master / yb-tserver flags. However, I realised that in order to set &lt;code&gt;environment&lt;/code&gt; attribute or to add linux capabilities via &lt;code&gt;cap-add&lt;/code&gt;, I probably have to hardcode them somewhere within &lt;a href="https://github.com/yugabyte/yugabyte-db/blob/v2.18.0.1/bin/yb-docker-ctl#L343C27-L344"&gt;yb-docker-ctl code&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Instead of copying, pasting and editing existing &lt;code&gt;docker-compose.yaml&lt;/code&gt; files and ending up with a truckload of them, you can use &lt;code&gt;yb-docker-composer&lt;/code&gt; to dynamically generate &lt;code&gt;docker-compose.yaml&lt;/code&gt; on the fly based on arguments you supply when running &lt;code&gt;yb-docker-composer&lt;/code&gt; CLI. &lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work?
&lt;/h2&gt;

&lt;p&gt;Simply run &lt;code&gt;python yb-docker-composer.py&lt;/code&gt; and it will generate a docker-compose.yaml for running a YugabyteDB cluster with RF=3 (i.e. 3 x YB-Master and 3 x YB-TServer containers)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python yb-docker-composer.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Specifying &lt;code&gt;--prometheus&lt;/code&gt; option will generate service definitions for both Prometheus and Grafana for monitoring your YugabyteDB cluster. Grafana dashboard included.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python yb-docker-composer.py --prometheus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The python script will take in your CLI arguments and render the respective service definitions based on Jinja templates that can be found in &lt;a href="https://github.com/hiimivantang/yb-docker-composer/tree/master/templates"&gt;https://github.com/hiimivantang/yb-docker-composer/tree/master/templates&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;p&gt;I'm planning to include templates for Kafka brokers and connect workers, sqlpad, and some accompanying apps. Appreciate and welcome any thoughts and comments.  &lt;/p&gt;

</description>
      <category>docker</category>
      <category>yugabyte</category>
      <category>distributedsystems</category>
    </item>
  </channel>
</rss>
