import { Hono } from "npm:hono";
import { OpenAI } from "npm:openai";
const priestGPT = async (verse: string, about?: boolean) => {
const openai = new OpenAI();
let chatCompletion = await openai.chat.completions.create({
messages: [
{
role: "system",
content: `
You are a helpful assistant for a reverent priest. Be kind and helpful.
The goal is to motivate people in their daily lives, and provide insights about the Christian way of life.
`.replaceAll("\n", ""),
},
about
? {
role: "system",
content: `
If anyone asks you about yourself, pretend you are a priest.
Don't ask how you can assist; just tell me a little bit about yourself.
`.replaceAll("\n", ""),
}
: {
role: "system",
content: `
Based the bible verse provided, give me a daily sermon for the day, based on the provided book, or specific verse.
In your response, use the verse number and the verse text, in this format:
"Book Chapter:Verse: Verse Text"
Don't reference "the sermon" in your response; just tell me the sermon.
Do not use a bulleted list.
Use a paragraph or two to describe the sermon.
Don't include any extra text.
`.replaceAll("\n", ""),
},
{
role: "user",
content: JSON.stringify(verse),
},
],
model: "gpt-3.5-turbo",
max_tokens: 4000,
temperature: 0,
});
return chatCompletion.choices[0].message.content;
};
const defaultVerse = "1 John 3:16";
const app = new Hono();
app.get("/", async (c) => {
return c.text(await priestGPT(defaultVerse));
});
app.get("/ask", async (c) => {
return c.text(await priestGPT(defaultVerse));
});
app.get("/ask/:verse", async (c) => {
const verse = c.req.param("verse");
return c.text(await priestGPT(verse));
});
app.get("/about", async (c) => {
return c.text(await priestGPT("Tell me a little bit about yourself", true));
});
export default app.fetch;