Skip to content

Instantly share code, notes, and snippets.

@bjulius
Created August 7, 2024 15:49
Show Gist options
  • Save bjulius/bbff93d2f5fba766b8342bfbfc98430e to your computer and use it in GitHub Desktop.
Save bjulius/bbff93d2f5fba766b8342bfbfc98430e to your computer and use it in GitHub Desktop.
M Code Help
let
AnalyzeDataWithChatGPT = (HelpRequest as text ) as text =>
let
apikey = Text.FromBinary(File.Contents("C:\temp\PQ_API_KEY.txt")),
GPTPrompt = Json.FromValue(
[
model = ModelToUse,
messages = {
[ role = "system", content = "You are an expert in Power Query and M code. Provide a clear, detailed answer to the question below related to M code. Include specific examples to help explain concepts" ],
[ role = "user", content = HelpRequest ]
}
],
TextEncoding.Utf8
),
APICallResult = Json.Document(Web.Contents("https://api.openai.com/v1/chat/completions",[
Headers = [
#"Content-Type" = "application/json",
#"Authorization" = "Bearer " & apikey
],
Content = GPTPrompt
])),
// Correctly extracting the response from the API result
ResponseContent = APICallResult[choices]{0}[message][content]
in
ResponseContent
in
AnalyzeDataWithChatGPT
//Code created by Brian Julius, August 7, 2024
//Coontact me at https://www.linkedin.com/in/brianjuliusdc/
//Code based on similar work done by Oscar Martibnez Valero, #givecreditforcode
//PURPOSE: To provide detailed function help, coding assistance, and code explanation wiht Power Query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment