Skip to content

Instantly share code, notes, and snippets.

@foeken
Created December 6, 2022 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foeken/b81a79f996283d79bad4321f7e125d22 to your computer and use it in GitHub Desktop.
Save foeken/b81a79f996283d79bad4321f7e125d22 to your computer and use it in GitHub Desktop.
// 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()}
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment