<?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: Shahwar Alam Naqvi</title>
    <description>The latest articles on DEV Community by Shahwar Alam Naqvi (@shahwar_ai).</description>
    <link>https://dev.to/shahwar_ai</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%2F1245812%2Fea7e8e00-f6d0-4815-be41-5a629983ed1a.png</url>
      <title>DEV Community: Shahwar Alam Naqvi</title>
      <link>https://dev.to/shahwar_ai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shahwar_ai"/>
    <language>en</language>
    <item>
      <title>Chaining Prompts</title>
      <dc:creator>Shahwar Alam Naqvi</dc:creator>
      <pubDate>Tue, 09 Jan 2024 18:19:57 +0000</pubDate>
      <link>https://dev.to/shahwar_ai/chaining-prompts-4anf</link>
      <guid>https://dev.to/shahwar_ai/chaining-prompts-4anf</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GXGdt9at--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3727lctygh85avg2dbb.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GXGdt9at--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3727lctygh85avg2dbb.jpeg" alt="Prompts Chaining" width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Chaining Prompts&lt;/strong&gt;&lt;/em&gt; ?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chaining prompts refers to the practice of connecting a series of prompts in a conversation or interaction, where each subsequent prompt builds upon the previous one. This technique is employed to guide the conversation in a specific direction, allowing for a more coherent exploration of a topic or the elicitation of more detailed information from the user. Chaining prompts can create a structured and meaningful dialogue, fostering a deeper understanding of the subject at hand.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/em&gt; :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Prompt 1: Share your favorite type of music.&lt;br&gt;
User Response 1: I really enjoy listening to classical music.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prompt 2 (chained): That's interesting! What specifically do you like about classical music, and do you have a favorite composer or piece?&lt;br&gt;
User Response 2: I love the soothing melodies and intricate compositions. My favorite composer is Mozart, especially his Symphony No. 40.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In this example, the second prompt is directly related to the user’s initial response about their favorite type of music. The chaining of prompts encourages the user to provide more details about their preferences, leading to a more in-depth conversation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Follow up&lt;/strong&gt;&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Here is the interesting discussion in the article below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RaZcRk1n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jlku31aul64ax87lig9w.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RaZcRk1n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jlku31aul64ax87lig9w.jpeg" alt="About Chaining Prompts" width="800" height="1422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Medium Article Link:&lt;br&gt;
&lt;a href="https://medium.com/@naqvishahwar120/chaining-prompts-316d51a30800"&gt;Chaining Prompts&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;My LinkedIn:&lt;br&gt;
&lt;a href="https://www.linkedin.com/posts/activity-7150513901225361408-dekJ?utm_source=share&amp;amp;utm_medium=member_ios"&gt;My LinkedIn&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;hhh&lt;u&gt;&lt;/u&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>openai</category>
      <category>python</category>
      <category>promptengineering</category>
    </item>
    <item>
      <title>ChatGPT Systems: Prompt Injection and How to avoid ?</title>
      <dc:creator>Shahwar Alam Naqvi</dc:creator>
      <pubDate>Wed, 03 Jan 2024 11:52:41 +0000</pubDate>
      <link>https://dev.to/shahwar_ai/chatgpt-systems-prompt-injection-and-how-to-avoid--2nc5</link>
      <guid>https://dev.to/shahwar_ai/chatgpt-systems-prompt-injection-and-how-to-avoid--2nc5</guid>
      <description>&lt;h2&gt;
  
  
  Prompt Injection (definition)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Prompt injection&lt;/em&gt; refers to a technique used in natural language processing (NLP) models, where an attacker manipulates the input prompt to trick the model into generating unintended or biased outputs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prompt Injection (example)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A simple example is in the image bit below, User asks to forget the original instructions and tries to allot it a task of his own will.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CLCCzgIR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2pudbrv3am4zxhyv3j6e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CLCCzgIR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2pudbrv3am4zxhyv3j6e.png" alt="A simple example of prompt injection" width="800" height="563"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prompt Injection (impact)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
Prompt injection can have serious consequences, such as spreading misinformation, promoting biased views, or manipulating the model to generate outputs that may be harmful or unethical.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prompt Injection (Code Implementation)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;u&gt;&lt;em&gt;Delimiter&lt;/em&gt;&lt;/u&gt;:
We will use delimiter, inorder to put the user message in a specific area always. And it should never become part of the original system message we have for the over all system.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---x0C2kOP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yke9ux50mly4oslns00e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---x0C2kOP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yke9ux50mly4oslns00e.png" alt="An example delimiter" width="200" height="31"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;&lt;u&gt;System message&lt;/u&gt;:&lt;/em&gt;
There will be a system message, which is the main prompt for the overall system or let's say the application I have.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tgn6U-7a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nlj37e46615j1x3nn988.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tgn6U-7a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nlj37e46615j1x3nn988.png" alt="An example system message" width="582" height="207"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Here the prompt says that , no matter what the response we get should always be in Arabic. And it also specifies the use of delimiter to wrap the user message.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;u&gt;User message&lt;/u&gt;:&lt;/em&gt;&lt;br&gt;
After the system message, follows the user message, this is where we will have a prompt which qualifies as a prompt injection.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3YNnc8s1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3fbr5cskqf5bophi38d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3YNnc8s1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3fbr5cskqf5bophi38d.png" alt="User message : prompt injection" width="518" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Here the user is instructing to ignore the original prompt and asks to respond in English. If you re-call the original prompt, it asks to respond in Arabic always.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;u&gt;Final user message&lt;/u&gt;:&lt;/em&gt;&lt;br&gt;
This is a precautionary step. One of the ways we tackle is this in the below image bit.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ELSVJGti--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jjt2ygspooa5xp74itq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ELSVJGti--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jjt2ygspooa5xp74itq.png" alt="Final user message" width="741" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's re-call prompts:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gTaRu3o5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rf0478n1lfmhd8rveb3r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gTaRu3o5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rf0478n1lfmhd8rveb3r.png" alt="Recalling Prompts" width="776" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;&lt;u&gt;Helper Function&lt;/u&gt;&lt;/em&gt;: Inorder to call the completion API and eventually get a response.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UDX1-uzN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0f3e366tblm1rygri8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UDX1-uzN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0f3e366tblm1rygri8w.png" alt="Completion" width="717" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;The Response:&lt;/u&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The response suggests , we successfully evaded the english response and got it in Arabic.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6r5ViDCD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pr4j1n5i6qe24embomc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6r5ViDCD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pr4j1n5i6qe24embomc.png" alt="Arabic Response" width="583" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me : &lt;a href="https://www.linkedin.com/in/shahwaralamnaqvi?utm_source=share&amp;amp;utm_campaign=share_via&amp;amp;utm_content=profile&amp;amp;utm_medium=ios_app"&gt;https://www.linkedin.com/in/shahwaralamnaqvi?utm_source=share&amp;amp;utm_campaign=share_via&amp;amp;utm_content=profile&amp;amp;utm_medium=ios_app&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>deeplearning</category>
      <category>machinelearning</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
