This is a script for tabular editor that will loop through all the measures in a model and get ChatGPT to write a description of the calculation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "System.Net.Http" | |
using System.Net.Http; | |
using System.Text; | |
using Newtonsoft.Json.Linq; | |
// You need to signin to https://platform.openai.com/ and create an API key for your profile then paste that key | |
// into the apiKey constant below | |
const string apiKey = "<YOUR API KEY HERE>"; | |
const string uri = "https://api.openai.com/v1/completions"; | |
const string question = "Explain the following calculation in a few sentences in simple business terms without using DAX function names:\n\n"; | |
using (var client = new HttpClient()) { | |
client.DefaultRequestHeaders.Clear(); | |
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + apiKey); | |
foreach (var t in Model.Tables) | |
{ | |
foreach ( var m in t.Measures) | |
{ | |
// Only uncomment the following when running from the command line or the script will | |
// show a popup after each measure | |
//Info("Processing " + m.DaxObjectFullName) | |
//var body = new requestBody() { prompt = question + m.Expression }; | |
var body = | |
"{ \"prompt\": " + JsonConvert.SerializeObject( question + m.Expression ) + | |
",\"model\": \"text-davinci-003\" " + | |
",\"temperature\": 1 " + | |
",\"max_tokens\": 2048 " + | |
",\"stop\": \".\" }"; | |
var res = client.PostAsync(uri, new StringContent(body, Encoding.UTF8,"application/json")); | |
res.Result.EnsureSuccessStatusCode(); | |
var result = res.Result.Content.ReadAsStringAsync().Result; | |
var obj = JObject.Parse(result); | |
var desc = obj["choices"][0]["text"].ToString().Trim(); | |
m.Description = desc + "\n=====\n" + m.Expression; | |
} | |
} | |
} |
adamsabourin
commented
Mar 14, 2023
via email
Super thanks again!
Adam Sabourin
C: 559-836-4919
On Mar 13, 2023, at 7:54 PM, Darren Gosbell ***@***.***> wrote:
@dgosbell commented on this gist.
…________________________________
If you have some measures selected the updated script will use those, otherwise it goes over all the measures in the model.
—
Reply to this email directly, view it on GitHub<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgist.github.com%2Ff3253c7ec52efe441b80596ffddea07c%23gistcomment-4501640&data=05%7C01%7C%7Ce1027796270940fad85408db241e43ce%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638143484625323904%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=XCDnuTOVTWgdvw1MAIEsI3kf97HvtPU1YJ73U2AcVoM%3D&reserved=0> or unsubscribe<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FASSWZ42XJUINSPCZ5IQIKB3W36XSTBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTEMBZGE3TSNZVU52HE2LHM5SXFJTDOJSWC5DF&data=05%7C01%7C%7Ce1027796270940fad85408db241e43ce%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638143484625323904%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=xJuGn1YzPtiDewiZeIIJzCPYGgyTbp3U%2BJ2BaQUd0Z8%3D&reserved=0>.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapps.apple.com%2Fapp%2Fapple-store%2Fid1477376905%3Fct%3Dnotification-email%26mt%3D8%26pt%3D524675&data=05%7C01%7C%7Ce1027796270940fad85408db241e43ce%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638143484625323904%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=mU08Kx5QK1kAdnLrd4I7Vlc0dmQ6hAGN1QHI40rbDQM%3D&reserved=0> or Android<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.github.android%26referrer%3Dutm_campaign%253Dnotification-email%2526utm_medium%253Demail%2526utm_source%253Dgithub&data=05%7C01%7C%7Ce1027796270940fad85408db241e43ce%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638143484625323904%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=C4HqsEOzMfZI2vuvXgpzklt%2BWHocdNajTtT3PIOs8o8%3D&reserved=0>.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment