Another Tana script. This time using GPT-3 to automatically tag people and companies. It can also do natural language field building and suggest fields for a specific type of thing. Besides that it supports natural language dates and some math.
Note this is on actually model 2 (works enough and is faster) and temperature 0 so I doesn't get too creative.
// Shortcut: command control a// Name:// Description: Enrich using Open AI's API// Shortcut:import "@johnlindquist/kit"let { Configuration, OpenAIApi } = await npm("openai")let configuration = new Configuration({apiKey: await env("OPENAI_API_KEY"),})Date.prototype.getDateWithDateOrdinal = function () {var d = this.getDate(); // from here on I've used Kennebec's answer, but improved it.if (d > 3 && d < 21) return d + 'th';switch (d % 10) {case 1: return d + "st";case 2: return d + "nd";case 3: return d + "rd";default: return d + "th";}}let tomorrow = new Date()tomorrow.setDate(new Date().getDate() + 1)let roamDate = (date) => {const monthNames = ["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"]return "[[" + monthNames[date.getMonth()] + " " + date.getDateWithDateOrdinal() + ", " + date.getFullYear() + "]]"}let openai = new OpenAIApi(configuration)let complete = async (prompt, maxTokens, temperature) => {setTimeout(() => {setLoading(true)}, 250)let response = await openai.createCompletion({model: "text-davinci-002",prompt: `${prompt}`,temperature: temperature,max_tokens: maxTokens,top_p: 1,frequency_penalty: 0,presence_penalty: 0,})setLoading(false)return response?.data?.choices[0]?.text?.trim()}let convert = await getSelectedText()let temperature = 0let maxTokens = 256let prompt = `You try to interpret what I want to say in Tana Paste Format. Put double brackets around dates, people and company names. Today is ${new Date()}.Replace AF with [[Andre Foeken]]Replace PB with [[Pieter Bos]]Convert:AF uses TanaInto:%%tana%%- [[Andre Foeken]] uses TanaConvert:Suggest some fields for a movieInto:%%tana%%- Amazing Movie #movie- Title::- Release Year::- Director::- Plot Summary::Convert:Add a field Attendees and "Meeting topic"Into:%%tana%%- Add a field Attendees and "Meeting topic"- Attendees::- Meeting topic::Convert:1+1=Into:%%tana%%- 1+1=2Convert:TodayInto:%%tana%%- ${roamDate(new Date())}Convert:TomorrowInto:%%tana%%- ${roamDate(tomorrow)}Convert:3P with John DoeInto:%%tana%%- 3P meeting with [[John Doe]] #3P- Attendees:: [[John Doe]]Convert:1-1 meeting with John DoeInto:%%tana%%- 1-1 meeting with [[John Doe]] #1-1- Attendees:: [[John Doe]]Convert:I want to see this todayInto:I want to see this ${roamDate(new Date())}Convert:Try out this thing on Today, Tue, 6 DecInto:%%tana%%- Try out this thing on [[December 6th, 2022]] #todo- Planned:: [[December 6th, 2022]]Convert:The Obstacle is the WayInto:%%tana%%- The Obstacle is the Way #book- Author:: [[Ryan Holiday]]Convert:Ryan Holiday is the author of [[The Obstacle is the Way]]Into:%%tana%%- [[Ryan Holiday]] is the author of [[The Obstacle is the Way]]Convert:Ryan HolidayInto:%%tana%%- Ryan Holiday #personConvert:Meeting about Compensation Structure with John Ruumpol and Andre FoekenInto:%%tana%%- Meeting about [[Compensation Structure]] with [[John Doe]] and [[Andre Foeken]] #meeting- Attendees::- [[John Doe]]- [[Andre Foeken]]Convert: ${convert}Into:`let result = await complete(prompt, maxTokens, temperature)setSelectedText(result)