<?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: yf-yang</title>
    <description>The latest articles on Forem by yf-yang (@yfyang).</description>
    <link>https://forem.com/yfyang</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%2F2581532%2Fa76d0c6d-7478-435a-8bc3-69ab75f0af32.png</url>
      <title>Forem: yf-yang</title>
      <link>https://forem.com/yfyang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/yfyang"/>
    <language>en</language>
    <item>
      <title>I Built an Alternative to v0 Using Copilot</title>
      <dc:creator>yf-yang</dc:creator>
      <pubDate>Tue, 17 Dec 2024 12:11:41 +0000</pubDate>
      <link>https://forem.com/yfyang/i-built-an-alternative-to-v0-using-copilot-2i7</link>
      <guid>https://forem.com/yfyang/i-built-an-alternative-to-v0-using-copilot-2i7</guid>
      <description>&lt;p&gt;&lt;a href="https://v0.dev/" rel="noopener noreferrer"&gt;v0.dev&lt;/a&gt; is an AI-assisted coding service launched by Vercel, the company behind Next.js. I've been using it to generate UI interfaces with excellent results. Unfortunately, it appears that free users are limited to 10 conversation rounds per day.&lt;/p&gt;

&lt;p&gt;Since I have GitHub Copilot, I decided to leverage its capabilities to create a simple alternative called &lt;strong&gt;v0-copilot&lt;/strong&gt;. While it doesn't match v0's full functionality, optimizing my personal workflow allows it to provide a decent level of coding assistance. I'm sharing it here in hopes of improving everyone's productivity and encouraging more people to help enhance this project.&lt;/p&gt;

&lt;p&gt;Repository: &lt;a href="https://github.com/yf-yang/v0-copilot" rel="noopener noreferrer"&gt;https://github.com/yf-yang/v0-copilot&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What Can v0-copilot Do?
&lt;/h2&gt;

&lt;p&gt;v0's capabilities extend beyond generating UI interfaces; it can create entire projects or websites. In the &lt;strong&gt;v0-vscode&lt;/strong&gt; version, I've focused on component generation. Specifically, my goal is to create a tool similar to v0 to facilitate the following workflow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Input a Component Description and Generate Its Code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Preview the Generated Component in Real Time&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By interactively repeating these two steps, once satisfied, I can migrate the component to other projects.&lt;/p&gt;

&lt;p&gt;During my use of v0, the real-time preview feature left a strong impression. It allowed me to adjust the final presentation of the component directly during the conversation, without concerning myself with the generated code (intermediate results), thereby greatly enhancing the coding experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Technology Stack of the Output
&lt;/h2&gt;

&lt;p&gt;Adhering to Vercel's Next.js ecosystem, I expect the generated components to be React components using Shadcn's UI library and styled with Tailwind CSS. Of course, this is just a conceptual framework. By configuring prompts and other inputs for the language model, you can adapt it to your specific needs.&lt;/p&gt;

&lt;h1&gt;
  
  
  How It Works
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Prompt
&lt;/h2&gt;

&lt;p&gt;The current version of GitHub Copilot supports a special file called &lt;a href="https://docs.github.com/en/copilot/customizing-copilot/adding-custom-instructions-for-github-copilot" rel="noopener noreferrer"&gt;.github/copilot-instructions.md&lt;/a&gt;. This file affects all Copilot Chats in the workspace. I modified a prompt based on a project called &lt;a href="https://github.com/Yuyz0112/dewhale/tree/main" rel="noopener noreferrer"&gt;dewhale&lt;/a&gt; and included it there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-Time Preview of Generated Components
&lt;/h2&gt;

&lt;p&gt;First, we need an environment to preview code changes in real time. Any toolchain that supports Hot Module Replacement can achieve this. For simplicity, starters like Create React App with webpack can be used. However, I chose &lt;strong&gt;Storybook&lt;/strong&gt; because it naturally separates the component itself from its preview cases. In Storybook, developers can quickly switch between and view the component's behavior under different input parameters, providing a better experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Enabling the Language Model to Use Shadcn's Components
&lt;/h3&gt;

&lt;p&gt;Currently, the outputs of large language models are limited by the input context. To provide sufficient information to the model, there are two approaches:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Include Shadcn's component information in the prompt.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Place Shadcn's component information into the workspace and direct the model to access it.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ideally, the second approach is more elegant. However, due to limitations in the current implementation of Copilot Chat, the model isn't very effective at autonomously searching the documentation for material and emulating it. Therefore, we copied the documentation and component code from the Shadcn repository into the current repository and retained many examples from dewhale in the prompt to guide the model's output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations
&lt;/h2&gt;

&lt;p&gt;The main limitations stem from GitHub Copilot. Due to its internal prompt settings, the model cannot always accurately access the intended locations. This affects the developer's experience in the following ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When conversing with Copilot, you need to &lt;strong&gt;explicitly specify&lt;/strong&gt; the two files to be modified (the source &lt;code&gt;Component.ts&lt;/code&gt; and the corresponding Storybook file &lt;code&gt;Component.stories.ts&lt;/code&gt;), or it may not update the correct files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When chatting with Copilot, you must include the &lt;code&gt;#codebase&lt;/code&gt; tag, which better guides Copilot to retrieve the necessary files from the entire codebase. Without specifying this tag, Copilot may still attempt to search for files but may not always succeed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Results
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fke9x0zqyzwehpoketax5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fke9x0zqyzwehpoketax5.gif" alt="Image description" width="600" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Personal Experience and Reflections
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;I found that &lt;strong&gt;Claude-3.5-sonnet&lt;/strong&gt; produced better results than &lt;strong&gt;GPT-4o-preview&lt;/strong&gt;. The GPT series models seemed to have difficulty understanding the relationship between Storybook and components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Despite the requirements specified in the prompt, these models did not adequately consider component generality. Without explicit instructions, they generally did not add &lt;code&gt;props&lt;/code&gt; to components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Possibly because the prompt included many examples covering various layouts but lacked examples of color usage, the models' color schemes were not ideal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Although this workflow is primarily suitable for component generation, Copilot can also be used for code modifications. Therefore, I recommend the following workflow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Creating Files&lt;/strong&gt;: When you need to create files, discuss with Copilot to determine the folder structure of the entire repository, then create the files for it to fill in (I'm not certain it can create files autonomously).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Writing New Components&lt;/strong&gt;: Create new components in the v0-copilot project, adjust the layout, and then migrate them to your repository.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Making Detailed Modifications&lt;/strong&gt;: Use Copilot for fine-tuning.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;h1&gt;
  
  
  Let's Collaborate to Build an Efficient Workflow
&lt;/h1&gt;

&lt;p&gt;This has been my attempt, and if it can help you, feel free to create your own repository based on this template to enhance your development efficiency. Additionally, while this project is limited to the VSCode + React + ShadcnUI tech stack, if you wish to create a similar tool for your own stack, I hope this provides some reference. You're also welcome to open-source your implementation!&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>githubcopilot</category>
      <category>react</category>
      <category>ui</category>
    </item>
  </channel>
</rss>
