|
| 1 | +Step-by-step: Find AI-generated code with AboutCode |
| 2 | +======================================================== |
| 3 | + |
| 4 | + |
| 5 | +In this tutorial, we first generate code using ChatGPT, then scan the generated code in ScanCode |
| 6 | +using the MatchCode pipeline. |
| 7 | + |
| 8 | + |
| 9 | +- Visit https://chatgpt.com/. |
| 10 | + |
| 11 | +- Enter this prompt to generate code: |
| 12 | + |
| 13 | +``Write JS code that is similar to https://github.com/isaacs/inherits/`` |
| 14 | + |
| 15 | ++-----------------------------------------------------------+ |
| 16 | +| .. image:: images/image_2.jpg | |
| 17 | +| :width: 600 | |
| 18 | ++-----------------------------------------------------------+ |
| 19 | + |
| 20 | +- The results will look something like this: |
| 21 | + |
| 22 | + |
| 23 | ++-----------------------------------------------------------+ |
| 24 | +| .. image:: images/chatgpt_1.png | |
| 25 | +| :width: 600 | |
| 26 | ++-----------------------------------------------------------+ |
| 27 | + |
| 28 | +- Click "Copy" button to copy the generated code then paste this in a text editor to save the |
| 29 | + generated code to a file named "foo.js": |
| 30 | + |
| 31 | ++-----------------------------------------------------------+ |
| 32 | +| .. image:: images/image_4.jpg | |
| 33 | +| :width: 600 | |
| 34 | ++-----------------------------------------------------------+ |
| 35 | + |
| 36 | + |
| 37 | +- Next, open your ScanCode.io URL and click on the "New Project" button. |
| 38 | + |
| 39 | ++-----------------------------------------------------------+ |
| 40 | +| .. image:: images/image_3.jpg | |
| 41 | +| :width: 600 | |
| 42 | ++-----------------------------------------------------------+ |
| 43 | + |
| 44 | + |
| 45 | +- Click "Drop files over here (or click)" and upload the saved "foo.js" file. |
| 46 | + |
| 47 | ++-----------------------------------------------------------+ |
| 48 | +| .. image:: images/image_5.jpg | |
| 49 | +| :width: 600 | |
| 50 | ++-----------------------------------------------------------+ |
| 51 | + |
| 52 | + |
| 53 | +- Then select the initial "scan_codebase" pipeline and click the "Create" button: |
| 54 | + |
| 55 | ++-----------------------------------------------------------+ |
| 56 | +| .. image:: images/image_7.jpg | |
| 57 | +| :width: 600 | |
| 58 | ++-----------------------------------------------------------+ |
| 59 | + |
| 60 | +- Click "Add pipeline" button. |
| 61 | + |
| 62 | ++-----------------------------------------------------------+ |
| 63 | +| .. image:: images/image_8.jpg | |
| 64 | +| :width: 600 | |
| 65 | ++-----------------------------------------------------------+ |
| 66 | + |
| 67 | +- Then select the "fingerprint_codebase" and cliem the "Add pipeline" button. |
| 68 | + |
| 69 | ++-----------------------------------------------------------+ |
| 70 | +| .. image:: images/image_9.jpg | |
| 71 | +| :width: 600 | |
| 72 | ++-----------------------------------------------------------+ |
| 73 | + |
| 74 | +- Repeat with the "match_to_matchcode" pipeline: |
| 75 | + |
| 76 | ++-----------------------------------------------------------+ |
| 77 | +| .. image:: images/image_12.jpg | |
| 78 | +| :width: 600 | |
| 79 | ++-----------------------------------------------------------+ |
| 80 | + |
| 81 | +- When the scan is done, click the "Resources" link to see the match results |
| 82 | + |
| 83 | ++-----------------------------------------------------------+ |
| 84 | +| .. image:: images/image_14.jpg | |
| 85 | +| :width: 600 | |
| 86 | ++-----------------------------------------------------------+ |
| 87 | + |
| 88 | +- You can see the file was matched to the "pkg:github/isaacs/inherits@v2.0.3" PURL. This is for |
| 89 | + this package: https://github.com/isaacs/inherits/ |
| 90 | + |
| 91 | ++-----------------------------------------------------------+ |
| 92 | +| .. image:: images/image_15.jpg | |
| 93 | +| :width: 600 | |
| 94 | ++-----------------------------------------------------------+ |
| 95 | + |
| 96 | + |
| 97 | +- Click on "pkg:github/isaacs/inherits@v2.0.3" package link. |
| 98 | + |
| 99 | ++-----------------------------------------------------------+ |
| 100 | +| .. image:: images/image_16.jpg | |
| 101 | +| :width: 600 | |
| 102 | ++-----------------------------------------------------------+ |
| 103 | + |
| 104 | +- From there click on the "Resources" tab: |
| 105 | + |
| 106 | ++-----------------------------------------------------------+ |
| 107 | +| .. image:: images/image_17.jpg | |
| 108 | +| :width: 600 | |
| 109 | ++-----------------------------------------------------------+ |
| 110 | + |
| 111 | +- Click the "foo.js" link to see the file details. |
| 112 | + |
| 113 | ++-----------------------------------------------------------+ |
| 114 | +| .. image:: images/image_18.jpg | |
| 115 | +| :width: 600 | |
| 116 | ++-----------------------------------------------------------+ |
| 117 | + |
| 118 | +- Click on the "Viewer" tab to see the file content. |
| 119 | + |
| 120 | ++-----------------------------------------------------------+ |
| 121 | +| .. image:: images/image_19.jpg | |
| 122 | +| :width: 600 | |
| 123 | ++-----------------------------------------------------------+ |
| 124 | + |
| 125 | +- Click "Matched Snippets" sub-tab of the viewer to see the highlighted matched code: |
| 126 | + |
| 127 | ++-----------------------------------------------------------+ |
| 128 | +| .. image:: images/image_20.jpg | |
| 129 | +| :width: 600 | |
| 130 | ++-----------------------------------------------------------+ |
| 131 | + |
| 132 | + |
| 133 | +- The AI-generated code is highlighted as matched code below: |
| 134 | + |
| 135 | ++-----------------------------------------------------------+ |
| 136 | +| .. image:: images/image_21.png | |
| 137 | +| :width: 600 | |
| 138 | ++-----------------------------------------------------------+ |
| 139 | + |
| 140 | + |
| 141 | +- The matched original code is also highlighted for reference: |
| 142 | + https://github.com/isaacs/inherits/blob/v2.0.3/inherits_browser.js |
| 143 | + |
| 144 | ++-----------------------------------------------------------+ |
| 145 | +| .. image:: images/image_22.png | |
| 146 | +| :width: 600 | |
| 147 | ++-----------------------------------------------------------+ |
| 148 | + |
0 commit comments