Last active
October 18, 2022 19:45
-
-
Save PolBaladas/9fdbbef51c840f331f7d3d6769a33c24 to your computer and use it in GitHub Desktop.
fermat-std.js
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
var const FERMAT_STD = String.raw` | |
@macro "place" "placeThis" | |
@macro "right of" "rightOf" | |
@macro "right" "rightOf" | |
@macro "below" "belowOf" | |
@macro "below of" "belowOf" | |
@macro "width of" "widthOf" | |
@macro "width" "widthOf" | |
@macro "height of" "heightOf" | |
@macro "height" "heightOf" | |
# Spatial Positioning Library | |
set offset to 5 | |
set widthOf to (e) : first of size of e | |
set heightOf to (e) : second of size of e | |
set rightOf to (e) : e.position + [first of size of e + offset, 0] | |
set belowOf to (e) : e.position + [0, second of size of e + offset] | |
set placeThis to (ent, pos) : | |
if type of ent is "EntityReference" then set ent.position to pos | |
else if type of ent is "PString" then set (new text with ent).position to pos | |
else if type of ent is "PList" | |
set currentPos to pos | |
for each in ent (e) : | |
if type of e is "PString" | |
set e to new text with e | |
end | |
set e.position to currentPos | |
set currentPos to currentPos + [first of size of e + offset, 0] | |
end | |
end | |
end | |
# AI Models | |
set gpt3 to {} | |
set gpt3.prompt to "" | |
set gpt3.temperature to 0.7 | |
set gpt3.max_tokens to 256 | |
set gpt3.model to "text-davinci-002" | |
set gpt3.optimize to false | |
set gpt3.optimizer_prompt to "Provide an optimal professional profile to answer or accomplish the following questions or tasks: \n\n #Task: How to cook the best cookies.\n#Profile: You are a world-class baker willing to offer your best tips and secrets.\n\n#Task: How to dry my smartphone if it fall to a pool?\n#Profile: You are an experienced technician specialized in smartphones who enjoys to teach others.\n\n#Task: Why did the World War 2 happen?\n#Profile: You are a history professor who loves to talk about modern wars and to explain them in a very detailed manner.\n\n#Task: Summarize the following text.\n#Profile: You are a powerful NLP model fine-tuned to summarize text.\n\n#Task: How would you build a log cabin?\n#Profile: You are a veteran carpenter who has built many log cabins in the past and wants to share his experience.\n\n#Task: Answer the following question: What is a black hole?\n#Profile: You are an astrophysicist who loves to explain the mysteries of outer space.\n\n #Task:" | |
set optimizePrompt to(text, optimize_callback): | |
set prompt to gpt3.optimizer_prompt + text + "\n#Profile: " | |
set parameters to { | |
"temperature" to gpt3.temperature | |
"max_tokens" to gpt3.max_tokens | |
"model" to gpt3.model | |
} | |
set optimize_query to { | |
"method" to "POST" | |
"url" to "https://gateway.fermat.ws/models/GPT3/custom" | |
"headers" to { | |
"content-type" to "application/json" | |
} | |
"body" to { | |
"data" to { | |
"prompt" to prompt | |
} | |
"parameters" to parameters | |
} | |
} | |
do fetch optimize_query then(response): | |
set parsed to (do parseJson with response) | |
set output to parsed["output"] | |
do optimize_callback with output | |
end | |
end | |
set request to (text, request_callback): | |
set parameters to { | |
"temperature" to gpt3.temperature | |
"max_tokens" to gpt3.max_tokens | |
"model" to gpt3.model | |
} | |
set api to { | |
"method" to "POST" | |
"url" to "https://gateway.fermat.ws/models/GPT3/custom" | |
"headers" to { | |
"content-type" to "application/json" | |
} | |
"body" to { | |
"data" to { | |
"prompt" to gpt3.prompt + text | |
} | |
"parameters" to parameters | |
} | |
} | |
do fetch api then(response): | |
set parsed to (do parseJson with response) | |
set output to parsed["output"] | |
do request_callback with output | |
end | |
end | |
set gpt3.ask to (text, user_callback): | |
if gpt3.optimize is true: | |
do optimizePrompt with text then (result): | |
set gpt3.prompt to result | |
do request with text then (response): | |
do user_callback with response | |
end | |
end | |
else: | |
do request with text then (response): | |
do user_callback with response | |
end | |
end | |
end | |
set gpt3.summarize to (text, style, user_callback): | |
set gpt3.optimize to false | |
set gpt3.prompt to "Summarize the text in a specific style.\n\n Style:" + style + "\nText:\n" | |
set text to text + "\nSummary:\n" | |
do gpt3.ask with text then (response): | |
do replace "\n" with "" in response | |
do user_callback with response | |
end | |
end | |
set gpt3.rephrase to (text, style, user_callback): | |
set gpt3.optimize to false | |
set gpt3.prompt to "Rephrase the text in a specific style.\n\n Style:" + style + "\nText:\n#" | |
set text to text + "\nRephrased text:\n" | |
do gpt3.ask with text then (response): | |
do user_callback with response | |
end | |
end | |
set gpt3.tags to (text, user_callback): | |
set gpt3.optimize to false | |
set gpt3.prompt to "Extract tags from the following text in the following format:\n\nFormat:\n#tag1#tag2#tag3\n\nText:\nA black hole is a region of spacetime where gravity is so strong that nothing – no particles or even electromagnetic radiation such as light – can escape from it.[2] The theory of general relativity predicts that a sufficiently compact mass can deform spacetime to form a black hole.[3][4] The boundary of no escape is called the event horizon. Although it has a great effect on the fate and circumstances of an object crossing it, it has no locally detectable features according to general relativity.[5] In many ways, a black hole acts like an ideal black body, as it reflects no light.[6][7] Moreover, quantum field theory in curved spacetime predicts that event horizons emit Hawking radiation, with the same spectrum as a black body of a temperature inversely proportional to its mass. This temperature is of the order of billionths of a kelvin for stellar black holes, making it essentially impossible to observe directly.\n\nTags:\n#black hole#spacetime#gravity#relativity#event horizon#quantum field theory#curved spacetime#hawking radiation\n\nText:\n" | |
set text to text + "\nTags:\n#" | |
do gpt3.ask with text then (response): | |
set tags_array to (do split response with "#") | |
do user_callback with tags_array | |
end | |
end | |
set gpt3.keypoints to (text, user_callback): | |
set gpt3.optimize to false | |
set gpt3.prompt to "Extract the keypoints from the following text in the following format:\n\nFormat:\n#keypoint1#keypoint2#keypoint3\n\nText:\nA black hole is a region of spacetime where gravity is so strong that nothing – no particles or even electromagnetic radiation such as light – can escape from it.[2] The theory of general relativity predicts that a sufficiently compact mass can deform spacetime to form a black hole.[3][4] The boundary of no escape is called the event horizon. Although it has a great effect on the fate and circumstances of an object crossing it, it has no locally detectable features according to general relativity.[5] In many ways, a black hole acts like an ideal black body, as it reflects no light.[6][7] Moreover, quantum field theory in curved spacetime predicts that event horizons emit Hawking radiation, with the same spectrum as a black body of a temperature inversely proportional to its mass. This temperature is of the order of billionths of a kelvin for stellar black holes, making it essentially impossible to observe directly.\n\nKeypoints:\n#Black holes#Event horizon#Hawking radiation\n\nText:\n" | |
set text to text + "\nKeypoints:\n#" | |
do gpt3.ask with text then (response): | |
set keypoints_array to (do split response with "#") | |
do user_callback with keypoints_array | |
end | |
end | |
set gpt3.feeling to (text, user_callback): | |
set gpt3.optimize to false | |
set gpt3.prompt to "Which is the main feeling of the following text?\n\nText:\nWhen we are in love, we’re blinded to see the signs and the trails. Everything seems perfect till the heart gets broken and life becomes a horrible experience.\n\nFeeling:\n#Sadness\n\nText:\nMommy's love cannot be replaced. It's what keeps kids happy and keeps a smile on each face. It's what we know from the very start. Mommy's love comes purely from the heart. Happy Mother's Day!\n\nFeeling:\n#Love\n\nText:\nI can not believe it! Have you really been accepted to work for Microsoft? I did not expect it!\n\nFeeling:\n#Surprise\n\nText:\n" | |
set text to text + "Feeling:\n#" | |
do gpt3.ask with text then (response): | |
do user_callback with response | |
end | |
end | |
set gpt3.translate to (text, language_to, user_callback): | |
set gpt3.optimize to false | |
set gpt3.prompt to "Translate the following text to " + language_to + ":\n\nText:\n" | |
set text to text + "\n\n" | |
do gpt3.ask with text then (response): | |
do user_callback with response | |
end | |
end | |
set gpt3.randomTopic to (number_topics, user_callback): | |
set temp to gpt3.temperature | |
set gpt3.temperature to 1 | |
set gpt3.optimize to false | |
set text to "Generate 1 random topic:\n\n#Whether time travel is possible\n\nGenerate 2 random topic:\n\n#Whether extraterrestrial life exists#The nature of consciousness\n\nGenerate " | |
set text to text + (number_topics as text) + " random topic :\n\n#" | |
do gpt3.ask with text then (response): | |
set topics_array to (do split response with "#") | |
set gpt3.temperature to temp | |
do user_callback with topics_array | |
end | |
end | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment