<?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>Forem: Ebrahim Khalil</title>
    <description>The latest articles on Forem by Ebrahim Khalil (@ekamid).</description>
    <link>https://forem.com/ekamid</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%2F291604%2Fa9edcb47-f80d-4e4a-9fbf-b5637fd7e865.jpg</url>
      <title>Forem: Ebrahim Khalil</title>
      <link>https://forem.com/ekamid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ekamid"/>
    <language>en</language>
    <item>
      <title>I built an AI-powered web builder using OpenAI chat API, Next.js, and Styled Component</title>
      <dc:creator>Ebrahim Khalil</dc:creator>
      <pubDate>Wed, 22 Mar 2023 11:57:01 +0000</pubDate>
      <link>https://forem.com/ekamid/i-built-an-ai-powered-web-builder-using-openai-chat-api-nextjs-and-styled-components-3ab4</link>
      <guid>https://forem.com/ekamid/i-built-an-ai-powered-web-builder-using-openai-chat-api-nextjs-and-styled-components-3ab4</guid>
      <description>&lt;p&gt;ChatGPT, the artificial intelligence chatbot developed by OpenAI has the potential to automate a wide range of tasks across various industries. ChatGPT can understand natural language, allowing it to converse with users in a human-like manner, making it an effective tool for customer service, support, and development. With its ability to learn and adapt, ChatGPT can continuously improve its performance, making it an increasingly valuable tool for automating tasks and streamlining workflows. Overall, the possibilities of AI and ChatGPT to automate tasks are vast, and they are expected to transform the way businesses operate in the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I was recently playing with OpenAI chat API, and ended up building a basic web builder.&lt;/strong&gt;&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%2Fnyd984fs0loj9ufsrkh7.jpg" 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%2Fnyd984fs0loj9ufsrkh7.jpg" alt="I know what you're thinking!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  About the project
&lt;/h2&gt;

&lt;p&gt;This project allows users to&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Type instructions for web components and instantly receive corresponding HTML, CSS, and JavaScript code generated by OpenAI chat API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Users can preview their code and even make changes directly in the editor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is a history function that allows users to revisit previous instructions and code snippets.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Project Repository
&lt;/h2&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/ekamid" rel="noopener noreferrer"&gt;
        ekamid
      &lt;/a&gt; / &lt;a href="https://github.com/ekamid/cgpt-web-builder" rel="noopener noreferrer"&gt;
        cgpt-web-builder
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A basic Ai-powered web builder!
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div&gt;
  &lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;cgpt-web-builder&lt;/h1&gt;
&lt;/div&gt;
  &lt;p&gt;
    A basic Ai-powered web builder
    &lt;br&gt;
    &lt;br&gt;
    &lt;a href="https://cgpt-web-builder.vercel.app/" rel="nofollow noopener noreferrer"&gt;View Demo&lt;/a&gt;
    ·
    &lt;a href="https://github.com/ekamid/cgpt-web-builder/issues" rel="noopener noreferrer"&gt;Report Bug&lt;/a&gt;
  &lt;/p&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;About The Project&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;This app allows users to type instructions for web components and instantly receive corresponding HTML, CSS, and JavaScript code generated by OPENAI CHAT API. Users can preview their code and even make changes directly in the editor, making it easier than ever to fine-tune the appearance and functionality of their website. There is a history function that allows users to revisit previous instructions and code snippets.&lt;/p&gt;
&lt;p&gt;Built with &lt;code&gt;Nextjs&lt;/code&gt; and &lt;code&gt;Styled Components&lt;/code&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Cloning and Running the Application in local&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Clone the project into local&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;git clone https://github.com/ekamid/cgpt-web-builder.git
&lt;span class="pl-c1"&gt;cd&lt;/span&gt; cgpt-web-builder&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Install all the npm packages. Go into the project folder and type the following command to install all npm packages&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;npm install&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Rename the .env.example to .env and add your OpenAI API Key&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;NEXT_PUBLIC_OPENAI_API_KEY=your-openai-api-key&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In order to run the application in dev mode type the following command&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;…
&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/ekamid/cgpt-web-builder" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Project Live
&lt;/h2&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://cgpt-web-builder.vercel.app/" rel="noopener noreferrer"&gt;
      cgpt-web-builder.vercel.app
    &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  See in action
&lt;/h2&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://www.linkedin.com/feed/update/urn:li:activity:7043848943457239040/" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.licdn.com%2Fdms%2Fimage%2Fv2%2FC5605AQHvXwChB4aVNg%2Fvideocover-high%2Fvideocover-high%2F0%2F1679384439418%3Fe%3D2147483647%26v%3Dbeta%26t%3DtHjr_nTeePv4tTzJ3a_Qr1_v0TL3V8DiJ1feo6fKj8U" height="auto" class="m-0"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://www.linkedin.com/feed/update/urn:li:activity:7043848943457239040/" rel="noopener noreferrer" class="c-link"&gt;
          Ebrahim Khalil on LinkedIn: #openai #openaichatgpt #nextjs #reactjs #javascript #typescript…
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;p class="truncate-at-3"&gt;
          Was playing with OpenAI API, and ended up building a basic AI-powered web builder! 😅

About the project:
This app allows users to type instructions for web…
        &lt;/p&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstatic.licdn.com%2Faero-v1%2Fsc%2Fh%2Fal2o9zrvru7aqj8e1x2rzsrca"&gt;
        linkedin.com
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Whenever user click on a generate section with an instruction, it trigger a hook called &lt;em&gt;&lt;strong&gt;useMessageWithChatGPT&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The instruction will wrap by another instruction &lt;strong&gt;&lt;em&gt;"Write code. Html should be without html, body, head and script tag. Wrap html code with ---starthtml--- ---endhtml---, css code with ---startcss--- ---endcss--- and javascript code ---startjs--- ---endjs---. And ---startcss--- ---endcss--- and javascript code ---startjs--- ---endjs--- will not be between  ---starthtml--- ---endhtml---"&lt;/em&gt;&lt;/strong&gt; and call the api.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The API will return a content based on the instruction. For example the html code will be wrapped by &lt;strong&gt;&lt;em&gt;---starthtml--- {html code} ---endhtml---&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now we will call a helper function called &lt;strong&gt;extractCode()&lt;/strong&gt; to extract code using regular expression from the content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And finally update preview by &lt;strong&gt;updatePreview()&lt;/strong&gt; helper function.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Run the app to localhost
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Clone the project into local&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/ekamid/cgpt-web-builder.git
&lt;span class="nb"&gt;cd &lt;/span&gt;cgpt-web-builder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Install all the npm packages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go into the project folder and type the following command to install all npm packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Rename the .env.example to .env and add your OpenAI API Key&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;NEXT_PUBLIC_OPENAI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-openai-api-key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the OpenAI API key&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go to &lt;a href="https://platform.openai.com" rel="noopener noreferrer"&gt;https://platform.openai.com&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Login to your account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to &lt;a href="https://platform.openai.com/account/api-keys" rel="noopener noreferrer"&gt;https://platform.openai.com/account/api-keys&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a new secret key&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy and paste the secret key to your .env file&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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%2Fqv73416zm45tsyy8eple.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%2Fqv73416zm45tsyy8eple.png" alt="Open AI API Key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In order to run the application in dev mode type the following command&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Application Runs on &lt;strong&gt;localhost:3000&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Leave a star if you like the project. Any suggestions are wellcome.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>chatgpt</category>
      <category>nextjs</category>
      <category>react</category>
      <category>api</category>
    </item>
    <item>
      <title>How can I decouple the socket event emitter and listener from the io connection in server?</title>
      <dc:creator>Ebrahim Khalil</dc:creator>
      <pubDate>Tue, 03 Jan 2023 07:16:30 +0000</pubDate>
      <link>https://forem.com/ekamid/how-i-can-decouple-the-socket-event-emitter-and-listener-from-the-io-connection-in-server-28hh</link>
      <guid>https://forem.com/ekamid/how-i-can-decouple-the-socket-event-emitter-and-listener-from-the-io-connection-in-server-28hh</guid>
      <description>&lt;p&gt;Do you know how I can decouple the socket event emitter and listener from the io connection? Suppose for now I have to emit/listen to everything from the &lt;/p&gt;

&lt;p&gt;`io.on("connection", async (socket) =&amp;gt; {&lt;br&gt;
  console.log(User Connected: ${socket.id});&lt;/p&gt;

&lt;p&gt;//here&lt;br&gt;
 socket.emit('emit something)&lt;br&gt;
socket.on('listen something')&lt;br&gt;
});`&lt;/p&gt;

&lt;p&gt;but I want to emit from different places of the application, like from services. How can I achieve that?&lt;/p&gt;

</description>
      <category>socketio</category>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to run a function in background?</title>
      <dc:creator>Ebrahim Khalil</dc:creator>
      <pubDate>Thu, 22 Dec 2022 02:59:46 +0000</pubDate>
      <link>https://forem.com/ekamid/how-to-run-a-function-in-background-2c7g</link>
      <guid>https://forem.com/ekamid/how-to-run-a-function-in-background-2c7g</guid>
      <description>&lt;p&gt;Suppose I have a function that will run every time a user creates. The function will check if the user is nearby of other users. It's a long process, right? I don't wan to wait for its response. So I want to run this function in the background. How can I do that?&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>help</category>
      <category>node</category>
      <category>express</category>
    </item>
  </channel>
</rss>
