Andre Foeken

Andre Foeken

// 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 = 0
let maxTokens = 256
let 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 Tana
Into:
%%tana%%
- [[Andre Foeken]] uses Tana
Convert:
Suggest some fields for a movie
Into:
%%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=2
Convert:
Today
Into:
%%tana%%
- ${roamDate(new Date())}
Convert:
Tomorrow
Into:
%%tana%%
- ${roamDate(tomorrow)}
Convert:
3P with John Doe
Into:
%%tana%%
- 3P meeting with [[John Doe]] #3P
- Attendees:: [[John Doe]]
Convert:
1-1 meeting with John Doe
Into:
%%tana%%
- 1-1 meeting with [[John Doe]] #1-1
- Attendees:: [[John Doe]]
Convert:
I want to see this today
Into:
I want to see this ${roamDate(new Date())}
Convert:
Try out this thing on Today, Tue, 6 Dec
Into:
%%tana%%
- Try out this thing on [[December 6th, 2022]] #todo
- Planned:: [[December 6th, 2022]]
Convert:
The Obstacle is the Way
Into:
%%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 Holiday
Into:
%%tana%%
- Ryan Holiday #person
Convert:
Meeting about Compensation Structure with John Ruumpol and Andre Foeken
Into:
%%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)
<img width="929" alt="CleanShot 2022-11-28 at 17 46 29@2x" src="https://user-images.githubusercontent.com/13864/204334452-7e308d3d-0a2d-4c57-bead-44d864f57530.png">
// Name: OpenAI Replace
// Description: Replace using Open AI's API
// Shortcut: cmd ctrl s
import "@johnlindquist/kit"
let { Configuration, OpenAIApi } = await npm("openai")
let configuration = new Configuration({
apiKey: await env("OPENAI_API_KEY"),
})
let openai = new OpenAIApi(configuration)
let complete = async (prompt, maxTokens, temperature) => {
setTimeout(() => {
setLoading(true)
}, 250)
console.log(maxTokens)
console.log(temperature)
console.log(prompt)
let response = await openai.createCompletion({
model: "text-davinci-003",
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 prompt = await getSelectedText()
let regexMatch = null
let temperature = 0.7
let temperatureRegex = /\n Temperature: ([+-]?([0-9]*[.])?[0-9]+)/
regexMatch = temperatureRegex.exec(prompt)
if (regexMatch) {
temperature = parseFloat(regexMatch[1])
prompt = prompt.replace(temperatureRegex, "")
}
let maxTokens = 512
let maxTokensRegex = /\n Max Tokens: ([+-]?([0-9]*[.])?[0-9]+)/
regexMatch = maxTokensRegex.exec(prompt)
if (regexMatch) {
maxTokens = parseInt(regexMatch[1])
prompt = prompt.replace(maxTokensRegex, "")
}
let result = ""
while (true) {
if (result != "") {
prompt = await editor(prompt)
}
div("Give me a second ...", "text-center text-4xl p-10 font-semibold")
result = await complete(prompt, maxTokens, temperature)
let retryOrContinue = await arg(
{
placeholder: "",
hint: "[R]etry another prompt, [E]dit the reply, or continue (enter)",
ignoreBlur: true,
}, div(md(result), 'm-4')
)
if (retryOrContinue === "E") {
result = await editor(result)
break
}
if (retryOrContinue === "") break
}
setSelectedText("%%tana%%\n" + result)