-
Notifications
You must be signed in to change notification settings - Fork 2
/
dataProvider.ts
55 lines (52 loc) · 15.5 KB
/
dataProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { DataProvider } from "react-admin";
import localStorageDataProvider from "ra-data-local-storage";
import { addGetCompletionBasedOnOpenAIAPI } from "@react-admin/ra-ai";
const LoremIpsumText =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus nisl ut sagittis euismod. Aenean convallis, lacus sed faucibus ornare, lectus magna consequat leo, at eleifend orci sem sed est. In rhoncus, sapien vel rutrum placerat, diam ante consequat enim, vitae dapibus sem nisi aliquam risus. Sed porta porttitor nibh eu aliquam. Sed eu tincidunt justo. Donec pulvinar, metus vel ultrices lobortis, nunc massa pharetra nulla, vitae tristique purus ante pellentesque mauris. Aenean scelerisque, quam sed molestie finibus, erat mauris blandit risus, a laoreet est sem in nisl. Donec hendrerit lacus ligula, et pharetra turpis facilisis vitae. Aenean quis augue malesuada, hendrerit diam eget, consequat felis. Quisque dignissim efficitur convallis. Nullam ac risus molestie, dictum dui eget, sagittis risus. Pellentesque sed velit velit. Praesent nec ipsum et sem faucibus placerat. Curabitur quis consequat augue. Aenean luctus velit eros, non feugiat augue suscipit a. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Phasellus bibendum erat vitae efficitur tristique. Fusce pretium tellus tempor pulvinar placerat. Integer viverra nisl justo, a varius tortor vulputate ac. Sed interdum eros magna, quis tristique tellus varius non. Nullam nec ipsum eu sem fermentum ultricies. Aliquam et purus risus. Mauris ornare in turpis vitae vestibulum. Cras facilisis tincidunt nisl, et ultricies nisi commodo ut. Duis in nisl arcu. Donec non placerat mi. Suspendisse sodales nec dui ac scelerisque. Cras quis pretium sem. Duis fermentum diam nunc, quis sodales sem vestibulum pellentesque. Duis diam purus, sollicitudin ut malesuada sed, dignissim ut eros. Integer aliquet est tortor, id rutrum nibh aliquet sed. Aenean posuere nisl sed justo placerat suscipit. Donec elementum lobortis neque, eget lacinia enim porta eget. Duis blandit a lacus facilisis sagittis. Etiam pellentesque sit amet nibh ac vestibulum. Nulla eu rhoncus lacus, id eleifend felis. Suspendisse non faucibus enim. Ut eleifend dolor eget venenatis viverra. Pellentesque pretium sagittis quam, in faucibus odio congue ut. Cras bibendum enim felis, vel auctor massa ultrices egestas. Aliquam accumsan mattis magna eu sodales. Donec hendrerit nisi leo, id tempus leo iaculis sed. In vel orci quis dolor interdum faucibus et porta diam. In hac habitasse platea dictumst. Vestibulum tempor velit risus, eget egestas mauris volutpat id. Pellentesque pretium sapien sit amet pellentesque sagittis. Maecenas aliquam, risus ut pharetra placerat, sapien orci commodo erat, id sollicitudin nulla quam quis arcu. Etiam aliquet feugiat sapien non sodales. Vestibulum in nisi accumsan mauris dignissim tempor vitae vitae lorem. Quisque nulla velit, vehicula et nulla non, tincidunt varius eros. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus sed leo turpis. Fusce lectus arcu, gravida eu sodales quis, mattis vel neque. Duis blandit a orci quis scelerisque. Mauris eu faucibus metus, egestas interdum orci. Fusce pulvinar, risus tristique lobortis molestie, eros purus aliquam tellus, in feugiat nisl mauris sed justo. Nulla et purus massa. Integer euismod nibh in ullamcorper aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sollicitudin lorem sapien, elementum blandit ex interdum sit amet. Aliquam lacus erat, lacinia eget dui nec, ultricies ultricies augue. Nulla scelerisque, nulla sit amet dictum cursus, ligula est convallis diam, et fringilla metus velit nec erat. Phasellus ac augue ac arcu consectetur semper. Nunc felis risus, porta sit amet ex vel, pretium fermentum est. Mauris tempor sed lacus vitae venenatis. Nam ac tellus fringilla, convallis leo in, iaculis libero. Mauris porttitor, dolor non volutpat sollicitudin, nisl lectus imperdiet sem, et efficitur mi erat eget orci. Sed nec quam tortor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed mollis ornare nisi. Donec interdum ante tempor, porttitor nulla non, iaculis erat. Mauris convallis rutrum aliquet. Nunc ac erat purus. Vivamus vehicula eu enim nec rutrum. Proin porttitor sem nec ante porta, ut pretium nisl ornare. Vestibulum nec tellus eu justo porttitor laoreet a vel nisi. Vivamus egestas, tellus in dapibus tristique, justo ipsum mollis massa, sit amet dictum nisi dolor vel mi. Nullam vel sapien ultrices, interdum dolor quis, viverra ante. Morbi ac dignissim quam. Fusce cursus, arcu feugiat facilisis tempus, diam sem sollicitudin augue, vel viverra nunc massa sed augue. Donec id dignissim erat. Praesent eget faucibus ipsum, id porta lacus. Pellentesque tincidunt odio elit, aliquam dapibus magna egestas eu. Morbi facilisis, felis non sagittis condimentum, urna leo placerat turpis, et sagittis turpis elit in turpis. Mauris porta libero vel nisl cursus aliquam. Quisque tempus purus ac lobortis porta. In eget neque elit. Aliquam sit amet ullamcorper ligula. Aliquam sed ligula varius, euismod velit eu, fringilla quam. Sed mattis vulputate mi vitae tempus. Sed ut fermentum augue. Duis nec eros nec nibh tempor lacinia. Cras tristique dignissim ex in euismod. Suspendisse potenti. Aenean ullamcorper lacus ultrices, bibendum odio vel, imperdiet lorem. In convallis orci sit amet neque dictum, placerat gravida diam posuere. Nam vitae neque dolor. Nunc pharetra massa sit amet aliquet mattis. Maecenas pellentesque turpis a accumsan cursus. Sed dignissim rhoncus odio, a scelerisque augue ultrices in. Ut turpis metus, ornare sed justo vel, tincidunt rutrum felis. Suspendisse molestie eget sem accumsan tincidunt. Praesent volutpat convallis mattis. Vivamus fringilla libero ut ante facilisis, ac iaculis arcu euismod. Duis elit purus, cursus id massa in, tincidunt dapibus lacus. Cras dapibus odio ac commodo tincidunt. Nullam a velit tristique, posuere urna at, porta lacus. Aenean quis viverra turpis. Sed nec iaculis sapien. Nulla malesuada sem sed justo faucibus condimentum. Fusce tincidunt ut nulla a fringilla. Sed magna nibh, malesuada vel venenatis feugiat, dignissim at turpis. Sed et bibendum lorem, quis rhoncus lectus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dictum, diam non porta luctus, nisi metus porta massa, nec finibus sem leo vel turpis. Aliquam tempus sodales lectus, quis fermentum ipsum egestas eu. Aenean cursus mi lacus, sed ullamcorper nisi ullamcorper sit amet. Nam vel aliquam ante, sed convallis nibh. Sed in feugiat nisl. Sed hendrerit metus sollicitudin sem aliquet congue a mattis eros. Proin vitae dolor vel est aliquam scelerisque. Sed auctor vehicula leo dignissim maximus. Etiam egestas, nunc viverra lobortis efficitur, nunc ante congue nisi, id sodales ligula tortor ac lectus. Nulla vitae rhoncus sapien. Donec in finibus odio. Cras eu tincidunt leo, eget rhoncus ipsum. Vestibulum malesuada elementum nunc vitae fermentum. Maecenas at pretium eros, in semper massa. Mauris sodales tortor sit amet dolor laoreet, in dignissim libero mollis. Praesent id urna ante. Mauris lobortis nec tellus id condimentum. Ut rhoncus posuere massa, ut congue tortor dignissim nec. Aliquam eleifend dolor varius est malesuada blandit. Praesent mollis nibh quis leo molestie vehicula.";
const sentences = LoremIpsumText.split(".");
const addGetCompletionBasedOnLoremIpsum = (dataProvider: DataProvider) => ({
...dataProvider,
getCompletion: (params: any) => {
const hasOpenAIKey = localStorage.getItem("ra-ai.openai-api-key");
if (hasOpenAIKey) {
return dataProvider.getCompletion(params);
} else {
// return a random sentence from the Lorem Ipsum text
const randomIndex = Math.floor(Math.random() * sentences.length);
const randomSentence = sentences[randomIndex];
return Promise.resolve({ data: randomSentence });
}
},
});
export const dataProvider = addGetCompletionBasedOnLoremIpsum(
addGetCompletionBasedOnOpenAIAPI({
dataProvider: localStorageDataProvider({
loggingEnabled: true,
defaultData: {
compositions: [
{
title: "Snow White",
created_at: "2023-10-16T20:56:13.390Z",
updated_at: "2023-11-08T15:22:18.909Z",
id: 3,
body: "Snow White\n\nIn a far-off kingdom, Snow White was born to a kind queen and king, with skin as white as snow, lips as red as blood, and hair as black as ebony. Sadly, Snow White’s mother died soon after her birth, and her father remarried a woman who was beautiful but prideful and cruel. The new queen possessed a magical mirror, and every day she asked, \"Mirror, mirror on the wall, who is the fairest of them all?\" The mirror always replied that the Queen was the fairest, which pleased her.\n\nYears passed, and Snow White grew up to be a kind and gentle young woman with beauty that surpassed even that of the Queen. One day, the mirror told the Queen that Snow White was now the fairest in the land. Enraged by jealousy, the Queen ordered a huntsman to take Snow White into the forest and kill her. The huntsman, unable to carry out the evil deed, urged Snow White to flee into the forest.\n\nLost and frightened, Snow White stumbled upon a tiny cottage belonging to seven dwarfs who worked in the mines. The dwarfs, upon finding her, were charmed by her and offered her shelter in exchange for housekeeping. Snow White and the dwarfs grew to love one another as a family.\n\nMeanwhile, the Queen discovered that Snow White was still alive and, using her dark magic, disguised herself as an old peddler woman. She visited Snow White while the dwarfs were away and tricked her into biting a poisoned apple, which put Snow White into a deathlike sleep. The dwarfs returned to find Snow White lifeless and, too heartbroken to bury her, placed her in a glass coffin in the forest.\n\nTime passed, and a prince who had heard tales of Snow White's beauty found her. Captivated by her, he begged the dwarfs to let him take the coffin. As his servants carried it away, they stumbled, causing the piece of poisoned apple to dislodge from Snow White's throat, awakening her.\n\nThe prince and Snow White quickly fell in love, and he asked her to marry him. Snow White agreed, and the kingdom rejoiced. They invited every noble to their wedding, including Snow White’s stepmother.\n\nUnaware of Snow White's identity, the Queen once again consulted her mirror before attending the wedding, needing assurance of her unrivaled beauty. The mirror revealed that the new bride, Snow White, was still the fairest of all. Enraged and jealous, the Queen arrived at the wedding only to find that the bride was her stepdaughter, Snow White. Her fury led to her downfall, and she was defeated.\n\nSnow White and the prince were married, and they lived happily ever after, ruling with kindness and fairness over the land for many years.\n\nThe end.",
},
{
title: "Cinderella",
created_at: "2023-10-17T07:52:24.541Z",
updated_at: "2023-11-08T15:20:36.374Z",
id: 2,
body: "Cinderella\n\nOnce upon a time, in a kingdom filled with song and celebration, there lived a kind-hearted young woman named Cinderella. She was the daughter of a gentle and loving father, but after his untimely death, Cinderella found herself at the mercy of her cruel stepmother and two stepsisters, who turned her into their servant. Despite her hardships, Cinderella remained compassionate and optimistic, finding solace in her animal friends and her dreams of a better life.\n\nOne day, the kingdom announced a royal ball, where the Prince would choose his bride. Cinderella’s stepmother forbade her to attend and cruelly ripped apart her homemade gown. Heartbroken, Cinderella ran into the garden, where her tears summoned her Fairy Godmother. With a flick of magic and a cheerful “Bibbidi-Bobbidi-Boo,” the Fairy Godmother transformed Cinderella, creating a stunning dress, glass slippers, and a golden carriage from a pumpkin and mice.\n\nThe only warning: At the stroke of midnight, the spell would break.\n\nCinderella arrived at the ball and immediately enchanted everyone, including the Prince. They danced under the stars, lost in each other’s company. But as the clock began to strike twelve, Cinderella fled, losing one glass slipper on the palace stairs.\n\nThe next day, the Prince, determined to find the mysterious woman who stole his heart, initiated a kingdom-wide search. The glass slipper was the key, and the Prince’s royal footman traveled from house to house, looking for the slipper’s owner.\n\nWhen he arrived at Cinderella’s home, the stepmother locked her away. But Cinderella’s animal friends freed her just in time for her to try on the slipper. It was a perfect fit. Recognizing her at last, the Prince whisked Cinderella away from her life of servitude.\n\nCinderella and the Prince married, sharing their kindness and generosity with the kingdom. Cinderella's grace and compassion touched everyone's lives, and she and the Prince lived happily ever after.\n\nThe end.",
},
{
title: "The Tree Little Pigs",
created_at: "2023-10-18T07:35:20.501Z",
updated_at: "2023-11-08T15:23:31.200Z",
id: 1,
body: "The Tree Little Pigs\n\nOnce upon a time, there were three little pigs who set out into the world to seek their fortunes. Each pig decided to build a house to live in. \n\nThe first little pig, eager and carefree, didn't want to toil too much. He gathered a heap of straw and constructed a flimsy house in no time. He then danced and played the rest of the day.\n\nThe second pig worked a little harder, but he also preferred leisure to labor. He gathered sticks and put together a slightly sturdier house. It stood wobbly, but it was faster than building a strong house, and so he too spent his days dancing and playing.\n\nThe third little pig was wise and industrious. He knew the value of hard work. He gathered bricks and painstakingly built a solid house. It took him much longer than his brothers, but the brick house stood firm and secure.\n\nOne day, a hungry wolf came upon the first pig’s straw house. He smelled the pig inside and licked his lips. The wolf knocked and said, “Little pig, little pig, let me in!”\n\nBut the little pig saw the wolf’s shadow and replied, “Not by the hair of my chinny-chin-chin!”\n\nSo the wolf huffed and puffed and blew the house down. The first little pig ran as fast as he could to his brother’s stick house.\n\nThe wolf followed and found the stick house. He knocked and said, “Little pigs, little pigs, let me in!”\n\nBut the little pigs replied, “Not by the hair of our chinny-chin-chins!”\n\nSo the wolf huffed and puffed and blew the house down. The two little pigs scampered to the third pig’s brick house.\n\nWhen the wolf reached the brick house, he was more determined than ever. He knocked and said, “Little pigs, little pigs, let me in!”\n\nBut the pigs replied, “Not by the hair of our chinny-chin-chins!”\n\nThe wolf huffed and puffed, but the brick house didn’t budge. Furious, he tried to enter through the chimney, but the clever third pig had a pot of boiling water waiting. The wolf fell in and ran away, never to bother the pigs again.\n\nThe two lazy pigs learned their lesson and with their brother’s help, they built their own brick houses. From then on, the three little pigs lived securely and worked hard, never underestimating the value of good workmanship again. And they all lived happily ever after.\n\nThe end.\n\n\n\n",
},
],
},
}),
})
);