-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
263 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as quote_cron from "./routes/quote/_cron/generate_quote.ts"; | ||
|
||
// TODO: discover all _cron modules and generate this function | ||
|
||
export default function initCron() { | ||
Deno.cron(quote_cron.name, quote_cron.schedule, quote_cron.default); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"unstable": [ | ||
"kv" | ||
"kv", | ||
"cron" | ||
], | ||
"tasks": { | ||
"build": "deno run --allow-all scripts/build.ts", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import handler from "./handler.ts"; | ||
import init from "@http/fns/hosting/init_deploy"; | ||
import initCron from "./cron.ts"; | ||
|
||
await initCron(); | ||
|
||
await Deno.serve(await init(handler)).finished; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getQuote } from "../_lib/quote_store.ts"; | ||
|
||
export async function Quote() { | ||
const quote = await getQuote(); | ||
|
||
return ( | ||
<blockquote class="quote-of-the-moment"> | ||
<p>{quote}</p> | ||
<footer>- a generative AI</footer> | ||
</blockquote> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { setQuote } from "../_lib/quote_store.ts"; | ||
import OpenAI from "npm:openai"; | ||
|
||
export const name = "Generate a new quote of the moment"; | ||
|
||
export const schedule = Deno.env.get("QUOTE_SCHEDULE") ?? "*/30 * * * *"; | ||
|
||
export default async function generateQuote() { | ||
console.log("Generating a new quote..."); | ||
|
||
const openai = new OpenAI(); | ||
|
||
const completion = await openai.chat.completions.create({ | ||
model: "gpt-4", | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: | ||
"Generate a new unique inspirational quote of the day. Do not attribute it to anyone", | ||
}, | ||
], | ||
}); | ||
|
||
const content = completion?.choices[0]?.message.content; | ||
|
||
if (content) { | ||
await setQuote(content); | ||
} | ||
} | ||
|
||
export const init = generateQuote; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as store from "$store"; | ||
|
||
export async function getQuote() { | ||
return await store.getItem<string>(["quote"]) ?? "Nothing to see here"; | ||
} | ||
|
||
export async function setQuote(quote: string) { | ||
await store.setItem(["quote"], quote); | ||
} |
Oops, something went wrong.