<?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 Sushwanth Nimmagadda on Medium]]></title>
        <description><![CDATA[Stories by Sushwanth Nimmagadda on Medium]]></description>
        <link>https://medium.com/@sushwanth.n?source=rss-1e0f613b7da8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5bR-AE_ADTbuGlOz</url>
            <title>Stories by Sushwanth Nimmagadda on Medium</title>
            <link>https://medium.com/@sushwanth.n?source=rss-1e0f613b7da8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:36:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sushwanth.n/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[How to train ChatGPT with your custom data and create your own chatbot]]></title>
            <link>https://medium.com/@sushwanth.n/how-to-train-chatgpt-with-your-custom-data-and-create-your-own-chatbot-6d525fc7f20f?source=rss-1e0f613b7da8------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d525fc7f20f</guid>
            <category><![CDATA[chatgpt-chatbot]]></category>
            <category><![CDATA[ai-chatbot-development]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[ai-chatbot]]></category>
            <dc:creator><![CDATA[Sushwanth Nimmagadda]]></dc:creator>
            <pubDate>Thu, 01 Jun 2023 20:17:08 GMT</pubDate>
            <atom:updated>2023-06-13T21:50:34.416Z</atom:updated>
            <content:encoded><![CDATA[<p>With ChatGPT API&#39;s advent, you can now create your own AI-based simple chat app by training it with your custom data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zNpwLtam-z4J5qHo" /><figcaption>Photo by <a href="https://unsplash.com/@maria_shalabaieva?utm_source=medium&amp;utm_medium=referral">Mariia Shalabaieva</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, I will walk you through the steps of training the ChatGPT API with your custom data (pdf files) and see the results of the experiment.</p><h3>Requirements:</h3><h4>Python3:</h4><p>Use the command below to check if you have python3 installed.</p><pre>python --version</pre><p>If not, you can follow the steps from <a href="https://docs.python-guide.org/starting/install3/osx/">this guide</a> to install Python3 in your system.</p><h4>Upgrade / Install pip3:</h4><p>Upgrade/install pip3 using the below command</p><pre>python3 -m pip install --upgrade pip </pre><h4>Dependent libraries:</h4><p>Use the below commands to install the dependent libraries that we will be using in our script to train chatGPT on custom data.</p><pre>pip3 install openai<br>pip3 install llama-index <br>pip3 install pypdf <br>pip3 install gradio </pre><ol><li>openai — This is to install the <a href="https://github.com/openai/openai-python">OpenAI python library</a></li><li>llama-index — This is to install the <a href="https://gpt-index.readthedocs.io/en/latest/">LlamaIndex</a> data framework for our LLM application</li><li>pypdf — This is the <a href="https://pypi.org/project/pypdf/">open source python library</a> that will be used to read the pdf files we want our AI chat bot to train on</li><li>gradio —<a href="https://gradio.app/"> Gradio.app</a> is a simple wayto create a simple web UI to demo our AI application and see the results of our trained model</li></ol><h4>Getting the API key from OpenAI:</h4><p>If you haven’t already generated an API key, now is the time to sign up at OpenAI. Go on to <a href="https://platform.openai.com/signup">Get started</a> link on the OpenAI webpage and sign up.</p><p>Head over to <a href="https://platform.openai.com/account/api-keys">API Keys</a> page and create a new API Key.</p><p><strong>Note: M</strong>ake sure you have a copy of this key saved somewhere because this key will not be displayed later again.</p><h4>Setting up the folders:</h4><p>Create a folder in your system with a name of your choice, for example “<em>myAIApp</em>”</p><p>Now crete a subfolder named “<em>trainingData</em>” within it. We will also have a python script “<em>app.py</em>” in the same folder. This is how the folder structure would look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*7sDwX8Isd6vxM5uRq48MAQ.png" /></figure><p>Now add the PDF files that have the content that you would like to train your data on in the “<em>trainingData”</em> folder.</p><h4>Creating the app:</h4><p>We will be adding below code to the app.py file</p><pre>from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader, LLMPredictor, ServiceContext, StorageContext, load_index_from_storage<br>from langchain import OpenAI<br>import gradio<br>import os<br><br>os.environ[&quot;OPENAI_API_KEY&quot;] = &#39;Replace This string with your API key&#39;<br><br>def construct_index(directory_path):<br>    # set number of output tokens<br>    num_outputs = 256<br><br>    _llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.5, model_name=&quot;gpt-3.5-turbo&quot;, max_tokens=num_outputs))<br><br>    service_context = ServiceContext.from_defaults(llm_predictor=_llm_predictor)<br><br>    docs = SimpleDirectoryReader(directory_path).load_data()<br><br>    index = GPTVectorStoreIndex.from_documents(docs, service_context=service_context)<br>    <br>    #Directory in which the indexes will be stored<br>    index.storage_context.persist(persist_dir=&quot;indexes&quot;)<br><br>    return index<br><br>def chatbot(input_text):<br>    <br>    # rebuild storage context<br>    storage_context = StorageContext.from_defaults(persist_dir=&quot;indexes&quot;)<br>    <br>    #load indexes from directory using storage_context <br>    query_engne = load_index_from_storage(storage_context).as_query_engine()<br>    <br>    response = query_engne.query(input_text)<br>    <br>    #returning the response<br>    return response.response<br><br>#Creating the web UIusing gradio<br>iface = gradio.Interface(fn=chatbot,<br>                     inputs=gradio.inputs.Textbox(lines=5, label=&quot;Enter your question here&quot;),<br>                     outputs=&quot;text&quot;,<br>                     title=&quot;Custom-trained AI Chatbot&quot;)<br><br>#Constructing indexes based on the documents in traininData folder<br>#This can be skipped if you have already trained your app and need to re-run it<br>index = construct_index(&quot;trainingData&quot;)<br><br>#launching the web UI using gradio<br>iface.launch(share=True)</pre><h4>Running the app:</h4><p>Use the below command to start the app. It will take some time to read the pdf files, index them and learn from them.</p><pre>python3 app.py</pre><p>Wait till you see a prompt showing the url where you can test your trained chat model. The mode data you have in the “<em>trainingData”</em> folder, the longer it is going to take for the app to read and learn. When it is done learning and ready to serve, the terminal looks something like the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RMpRIYhBqUZ1kIlgizGH5w.png" /></figure><p>You will also observe two new sub-folders created in your “<em>myAIApp”</em> directory. It would look like the picture below. “<em>indexes” </em>is the folder that has all the indexes created based on the data in the “<em>trainingData”</em> folder. The Flagged responses will go to the “<em>flagged</em>” folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*WVS9MnPp1qpqAXdKXNLnjQ.png" /></figure><p>Go on to the URL: <a href="http://127.0.0.1:7860/">http://127.0.0.1:7860/</a> on your local machine and you will be seeing a simple chat UI with a window to give your question. Make sure you keep the app running for the chat UI to work and give you the response.</p><p>The web UI would look like the picture below. Enjoy using the app and try experimenting with different training data and observing the responses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wmxWK6k5ZXMBJ1TboN0-jg.png" /></figure><p>Hint: When the AI mentions context, it refers to the data set that you have trained it on (pdf files in trainingData folder)</p><h4>What Next?</h4><p>Now that you have learned how to train using customData, you can use these learnings as stepping stones for your larger projects where you create your own AI models using private datasets and deploy your own AI chatbots.</p><p>I hope this article helped in your development journey. Remember to stay updated on my latest content by following me and subscribing to the newsletter. Thank you for reading!</p><p>If you like my content and want to support me, I would appreciate a coffee!</p><figure><a href="https://www.buymeacoffee.com/sushwanth"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2NQK6zHro2czbEZ-o9ZJ_w.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d525fc7f20f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>