<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[FlyPython Newsletter]]></title><description><![CDATA[Unleashing LLMs with Python. Explore the edge of AGI with FlyPython, where Python meets Large Language Models. Dive into tutorials, projects, and a community eager to push the boundaries of LLM applications.]]></description><link>https://blog.flypython.com</link><image><url>https://substackcdn.com/image/fetch/$s_!ACpH!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78c5695d-6e68-4565-b021-a574ce4ed89e_1280x1280.png</url><title>FlyPython Newsletter</title><link>https://blog.flypython.com</link></image><generator>Substack</generator><lastBuildDate>Mon, 06 Apr 2026 19:58:52 GMT</lastBuildDate><atom:link href="https://blog.flypython.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[FlyPython]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[flypython@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[flypython@substack.com]]></itunes:email><itunes:name><![CDATA[flypython]]></itunes:name></itunes:owner><itunes:author><![CDATA[flypython]]></itunes:author><googleplay:owner><![CDATA[flypython@substack.com]]></googleplay:owner><googleplay:email><![CDATA[flypython@substack.com]]></googleplay:email><googleplay:author><![CDATA[flypython]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[#2 Mergekit: Unlocking the Power of Large Language Model Fusion]]></title><description><![CDATA[In today's rapidly advancing field of artificial intelligence, the capabilities of Large Language Models (LLMs) are ever-increasing, demonstrating astonishing potential across various domains of natu&#8230;]]></description><link>https://blog.flypython.com/p/2-mergekit-unlocking-the-power-of</link><guid isPermaLink="false">https://blog.flypython.com/p/2-mergekit-unlocking-the-power-of</guid><dc:creator><![CDATA[pxiaoer]]></dc:creator><pubDate>Wed, 14 May 2025 11:36:47 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!UZ0G!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e8a2b4e-bda7-4ca6-a4dd-534393f3f7e3_1354x970.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In today's rapidly advancing field of artificial intelligence, the capabilities of Large Language Models (LLMs) are ever-increasing, demonstrating astonishing potential across various domains of natu&#8230;</p>
      <p>
          <a href="https://blog.flypython.com/p/2-mergekit-unlocking-the-power-of">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[#1 build a basic GPT chatbot using Python]]></title><description><![CDATA[How many lines of code do you think it takes to create a GPTBot?]]></description><link>https://blog.flypython.com/p/1-build-a-basic-gpt-chatbot-using-python</link><guid isPermaLink="false">https://blog.flypython.com/p/1-build-a-basic-gpt-chatbot-using-python</guid><dc:creator><![CDATA[flypython]]></dc:creator><pubDate>Tue, 05 Mar 2024 10:10:20 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!sSs0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sSs0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sSs0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png 424w, https://substackcdn.com/image/fetch/$s_!sSs0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png 848w, https://substackcdn.com/image/fetch/$s_!sSs0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png 1272w, https://substackcdn.com/image/fetch/$s_!sSs0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sSs0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png" width="1200" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:128937,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sSs0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png 424w, https://substackcdn.com/image/fetch/$s_!sSs0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png 848w, https://substackcdn.com/image/fetch/$s_!sSs0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png 1272w, https://substackcdn.com/image/fetch/$s_!sSs0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F647b2fea-09b2-4993-9907-fb3ba94fab17_1200x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This article will introduce you to how to build a basic GPT chatbot using Python, leveraging Hyperdiv and OpenAI's GPT models. Even beginners can follow the steps below to create an interactive chatbot.</p><h3>Preparation</h3><p>Before starting, please ensure that Python 3.9 or higher is installed on your machine. You will also need to install the necessary Python packages, which can be done by running the <code>pip install -r requirements.txt</code> command in the terminal. This command installs all the dependencies listed in the <code>requirements.txt</code> file, which can be found in the project's GitHub repository.</p><h3>Setting Up the Environment</h3><p>First, you need an OpenAI API key to interact with GPT models. You can obtain this key by creating an account on the OpenAI platform and generating a new API key from the API section. Once you have the key, you can set it as an environment variable (<code>OPENAI_API_KEY</code>), or directly replace <code>&lt;your OpenAI API key if not set as env var&gt;</code> in the code with your actual API key.</p><p></p><h3>Understanding the Code</h3><h3>Importing Libraries</h3><p>The script begins by importing necessary Python libraries:</p><ul><li><p><code>sys</code> and <code>os</code> for system-level operations.</p></li><li><p><code>openai</code> for interacting with the OpenAI API.</p></li><li><p><code>hyperdiv</code> as <code>hd</code>, for creating UI components for our chatbot.</p></li></ul><p></p><h3>Setting the API Key</h3><p>The API key is retrieved from environment variables, allowing the script to use OpenAI's services for authentication.</p><p></p><h3><code>add_message</code> Function</h3><p>This function is crucial for maintaining the chat history. It adds a new message to the state, assigning it a role (for example, &#8220;user&#8221; or &#8220;assistant&#8221;), content, an ID, and the model used.</p><p></p><h3><code>request</code> Function</h3><p>This function sends the collected messages as prompts to the OpenAI API, using the specified GPT model to generate a response. The response is then added to the chat history.</p><p></p><h3>Rendering Messages</h3><p>The <code>render_user_message</code> function creates a UI component for user messages, including the message content and the GPT model used.</p><p></p><h3><code>main</code> Function</h3><p>The <code>main</code> function is where the chatbot's UI is assembled using Hyperdiv components. It includes:</p><ul><li><p>A loop to render messages.</p></li><li><p>An input form for users to input their messages.</p></li><li><p>A dropdown menu to select the GPT model.</p></li><li><p>A button to start over and reset the chat history.</p></li></ul><p></p><h3>Detailed Code Introduction</h3><p>First, we need to import necessary libraries, including <code>sys</code>, <code>os</code>, <code>openai</code>, and <code>hyperdiv</code>. Then, we retrieve the OpenAI API key from the environment variables.</p><pre><code><code>import sys
import os
import openai
import hyperdiv as hd

api_key=os.environ.get("OPENAI_API_KEY","&lt;your OpenAI API key if not set as env var&gt;")
</code></code></pre><p>Next, we define several functions, including <code>add_message</code>, <code>request</code>, and <code>render_user_message</code>. These functions are used to add messages to the chat history, send requests to the OpenAI API and obtain replies, and render the user's messages, respectively.</p><pre><code><code>def add_message(role, content, state, gpt_model):
    ...

def request(gpt_model, state):
    ...

def render_user_message(content, gpt_model):
    ...

</code></code></pre><p>In the <code>main</code> function, we create a state object to store the chat history, the current reply, the GPT model used, and the message ID. We also create a task object to manage the running state of the chatbot.</p><pre><code><code>def main():
    state = hd.state(messages=(), current_reply="", gpt_model="gpt-4", message_id=0)
    task = hd.task()
    ...

</code></code></pre><p></p><p>In the user interface, we first render the chat history, then an input form where users can enter their messages and select the GPT model to use. When the form is submitted, we add the user's message to the chat history and rerun the task to get a new reply.</p><pre><code><code>    with hd.box(align="center", gap=1.5):
        ...
        with hd.form(direction="horizontal", width="100%") as form:
            ...
            if form.submitted:
                add_message("user", prompt.value, state, model.value)
                prompt.reset()
                task.rerun(request, model.value, state)

</code></code></pre><p>Finally, we use <code>hd.run(main)</code> to start the chatbot.</p><p></p><h3>Running the Chatbot</h3><p>Simply executing the script runs the chatbot. The Hyperdiv framework will render a user interface where you can interact with the chatbot. Enter your message, select the GPT model you wish to use, and press enter to see the chatbot's response.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dIwI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dIwI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png 424w, https://substackcdn.com/image/fetch/$s_!dIwI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png 848w, https://substackcdn.com/image/fetch/$s_!dIwI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png 1272w, https://substackcdn.com/image/fetch/$s_!dIwI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dIwI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png" width="1456" height="662" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:662,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:366181,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dIwI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png 424w, https://substackcdn.com/image/fetch/$s_!dIwI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png 848w, https://substackcdn.com/image/fetch/$s_!dIwI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png 1272w, https://substackcdn.com/image/fetch/$s_!dIwI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb63ebc8-16e3-4fc8-b61f-e1d5c125117c_2000x909.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>This introduction provides a basic understanding of how to create a GPT-based chatbot using Python. By exploring each function and component, you can customize and extend your chatbot according to your needs.</p><p></p><p><strong>The code:  <a href="https://github.com/flypythoncom/FlyPythonLLM/tree/main/01.GPTChat">GPTChat</a></strong></p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.flypython.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">FlyPython Newsletter is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>