Skip to content

Instantly share code, notes, and snippets.

@ninmonkey
Last active May 26, 2024 18:31
Show Gist options
  • Save ninmonkey/b9eed87ec23699e1ffa55b1f64270b8d to your computer and use it in GitHub Desktop.
Save ninmonkey/b9eed87ec23699e1ffa55b1f64270b8d to your computer and use it in GitHub Desktop.
Example of Copilot Generating code using my library in Power Query.md

snippet of my lib

The rest of the code is here: Write.Html.pq

// aliases
Write.Format  = String.Write.Format,
Write.Element = Write.Html.Element,
Write.Key     = Write.Html.KeyValue,
Tag           = Write.Html.Element,
P             = Write.Html.Paragraph,
B             = Write.Html.Bold,
UL            = Write.Html.UnorderedList,

My Version

This is what I wanted

NewVersion = StringBuilder.JoinParagraph({
    "MCopilot",
    UL({
        Write.Key( "Creator", "Oscar Martinez." ),
        Write.Key( "LinkedIn", "https://www.linkedin.com/in/oscarmartinezv/." ),
        Write.Key( "Web", "bibb.pro" )
    }),
    "This function, interacts with the OpenAI API to provide responses based on given prompts. It serves as a tool for generating meaningful explanations and full code related to Power Query.",
    "The function takes three parameters:",
    UL({
        Write.Key( "apiKey", "This is the Open API Key required for authentication." ),
        Write.Key( "model", "This is the GPT chosen model." ),
        Write.Key( "prompt", "This is the prompt provided to the function, requesting information or code related to Power Query." )
    }),
    "The function,  constructs a request to the OpenAI API endpoint https://api.openai.com/v1/chat/completions.",
    "The request body includes a system message indicating the role of the responder, as well as the user's prompt. The API key is included in the request headers for authentication.",
    "Upon receiving the response from the API, the function extracts the content of the response message and returns it as the output."
}),

The Expected / Target HTML to generate is:

Original = "
        <p><b>MCopilot</b></p>
        <li><b>Creator: </b>Oscar Martinez.</li>
        <li><b>LinkedIn:</b> https://www.linkedin.com/in/oscarmartinezv/.</li>
        <li><b>Web: </b>bibb.pro</li>

        <p>This function, interacts with the OpenAI API to provide responses based on given prompts. It serves as a tool for generating meaningful explanations and full code related to Power Query.</p>
        <p>The function takes three parameters:</p>
        <ul>
            <li><b>apiKey:</b> This is the Open API Key required for authentication.</li>
            <li><b>model:</b> This is the GPT chosen model.</li>
            <li><b>prompt:</b> This is the prompt provided to the function, requesting information or code related to Power Query.</li>
        </ul>
        <p>The function,  constructs a request to the OpenAI API endpoint <code>https://api.openai.com/v1/chat/completions</code>.</p>
        <p>The request body includes a system message indicating the role of the responder, as well as the user's prompt. The API key is included in the request headers for authentication.</p>
        <p>Upon receiving the response from the API, the function extracts the content of the response message and returns it as the output.</p>
    ",

Github-Copilot first pass

This is what copilot wrote, using my functions:

first_pass_from_copilot_to_my_lib = StringBuilder.Join({
    P( B("MCopilot") ),
    UL({
        B("Creator: ") & "Oscar Martinez.",
        B("LinkedIn:") & "https://www.linkedin.com/in/oscarmartinezv/.",
        B("Web: ") & "bibb.pro"
    }),
    P("This function, interacts with the OpenAI API to provide responses based on given prompts. It serves as a tool for generating meaningful explanations and full code related to Power Query."),
    P("The function takes three parameters:"),
    UL({
        B("apiKey:") & "This is the Open API Key required for authentication.",
        B("model:") & "This is the GPT chosen model.",
        B("prompt:") & "This is the prompt provided to the function, requesting information or code related to Power Query."
    }),
    P("The function,  constructs a request to the OpenAI API endpoint <code>https://api.openai.com/v1/chat/completions</code>."),
    P("The request body includes a system message indicating the role of the responder, as well as the user's prompt. The API key is included in the request headers for authentication."),
    P("Upon receiving the response from the API, the function extracts the content of the response message and returns it as the output.")

}),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment