From d297eaa1ef70c99841e89a4a375a5fced43bf12c Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Mon, 4 Sep 2023 10:48:02 +0200 Subject: [PATCH 01/11] TODOs --- config.ts | 2 ++ src/ai/text-to-text/writeWallpaperContent.ts | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/config.ts b/config.ts index 42ba9b950e..66e909382d 100644 --- a/config.ts +++ b/config.ts @@ -85,6 +85,8 @@ export const FONTS = [ // TODO: !! List more ] as const; +// TODO: !!! MAX_CHARS_IN_TITLE_WORD + export const MAX_CHARS_IN_TITLE = 'Futuristic Cityscape Wallpaper'.length - 7; // 'Tvořím něco z ničeho nic' // 'Futuristic Cityscape Wallpaper' diff --git a/src/ai/text-to-text/writeWallpaperContent.ts b/src/ai/text-to-text/writeWallpaperContent.ts index 885a592dc2..b215638fa9 100644 --- a/src/ai/text-to-text/writeWallpaperContent.ts +++ b/src/ai/text-to-text/writeWallpaperContent.ts @@ -28,6 +28,9 @@ export async function writeWallpaperContent( const { response, model: modelToCreateTitle } = chatThread; const { title, topic } = parseTitleAndTopic(removeQuotes(response)); + // TODO: Use !!! MAX_CHARS_IN_TITLE + // TODO: Use !!! MAX_CHARS_IN_TITLE_WORD + const contentStart = spaceTrim( (block) => ` @@ -50,9 +53,13 @@ export async function writeWallpaperContent( ), ); + // TODO: !!! Remove strange images https://1-2i.com/mountain-sunset-2gr7dv4ybstg + // TODO: !!! Test that the content is valid and rich markdown + const chatThreadFont = await chatThread.ask(createFontPromptTemplate()); const font = removeQuotes(chatThreadFont.response) as string_font_family; + // TODO: !!! Better font picking // console.log(chatThreadFont); return spaceTrim( From 1b789076fa0ea384930a35ce04f33187476b5816 Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Sat, 9 Sep 2023 18:13:45 +0200 Subject: [PATCH 02/11] TODOs --- src/ai/text-to-text/ChatThread.ts | 1 + src/ai/text-to-text/prompt-templates/TODO.txt | 1 + src/ai/text-to-text/writeWallpaperContent.ts | 2 ++ 3 files changed, 4 insertions(+) create mode 100644 src/ai/text-to-text/prompt-templates/TODO.txt diff --git a/src/ai/text-to-text/ChatThread.ts b/src/ai/text-to-text/ChatThread.ts index 32eafb8921..84f6cdeb0c 100644 --- a/src/ai/text-to-text/ChatThread.ts +++ b/src/ai/text-to-text/ChatThread.ts @@ -79,5 +79,6 @@ export class ChatThread { } /** + * TODO: !!! Save in database * TODO: !! [🧠] Log author, input/output, duration, model, cost, finish_reason,... in both completeWithGpt and ChatThread */ diff --git a/src/ai/text-to-text/prompt-templates/TODO.txt b/src/ai/text-to-text/prompt-templates/TODO.txt new file mode 100644 index 0000000000..08e920db76 --- /dev/null +++ b/src/ai/text-to-text/prompt-templates/TODO.txt @@ -0,0 +1 @@ +TODO: !!! Use .prompt.txt files \ No newline at end of file diff --git a/src/ai/text-to-text/writeWallpaperContent.ts b/src/ai/text-to-text/writeWallpaperContent.ts index b215638fa9..f53ee0fd8c 100644 --- a/src/ai/text-to-text/writeWallpaperContent.ts +++ b/src/ai/text-to-text/writeWallpaperContent.ts @@ -55,6 +55,8 @@ export async function writeWallpaperContent( // TODO: !!! Remove strange images https://1-2i.com/mountain-sunset-2gr7dv4ybstg // TODO: !!! Test that the content is valid and rich markdown + // TODO: !!! Use .prompt.txt files + // TODO: !!! Do NOT use words like "serene", "serenity" soo often const chatThreadFont = await chatThread.ask(createFontPromptTemplate()); const font = removeQuotes(chatThreadFont.response) as string_font_family; From 24f9dcf321bf7954089cea45fef6ad73c03d4199 Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Sun, 17 Sep 2023 18:40:01 +0200 Subject: [PATCH 03/11] TODOs --- src/ai/text-to-text/writeWallpaperContent.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ai/text-to-text/writeWallpaperContent.ts b/src/ai/text-to-text/writeWallpaperContent.ts index c14e49a8b8..6a0aa7aaf9 100644 --- a/src/ai/text-to-text/writeWallpaperContent.ts +++ b/src/ai/text-to-text/writeWallpaperContent.ts @@ -30,8 +30,9 @@ export async function writeWallpaperContent( const { response, model: modelToCreateTitle } = chatThread; const { title, topic } = parseTitleAndTopic(removeQuotes(response)); - // TODO: Use !!! MAX_CHARS_IN_TITLE - // TODO: Use !!! MAX_CHARS_IN_TITLE_WORD + // TODO: !!! Separate title, claim and content writing endpoint + // TODO: !!! Use MAX_CHARS_IN_TITLE + // TODO: !!! Use MAX_CHARS_IN_TITLE_WORD const contentStart = spaceTrim( (block) => ` From f27f4fc21df91572900917e6b9573ea0d77c05bf Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Sun, 17 Sep 2023 18:55:13 +0200 Subject: [PATCH 04/11] Prompt templates --- .../templates/modify-website-content.prompt.txt | 16 ++++++++++++++++ prompts/templates/write-website-claim.prompt.txt | 0 .../templates/write-website-content.prompt.txt | 3 +++ prompts/templates/write-website-font.prompt.txt | 12 ++++++++++++ prompts/templates/write-website-title.prompt.txt | 8 ++++++++ 5 files changed, 39 insertions(+) create mode 100644 prompts/templates/modify-website-content.prompt.txt create mode 100644 prompts/templates/write-website-claim.prompt.txt create mode 100644 prompts/templates/write-website-content.prompt.txt create mode 100644 prompts/templates/write-website-font.prompt.txt create mode 100644 prompts/templates/write-website-title.prompt.txt diff --git a/prompts/templates/modify-website-content.prompt.txt b/prompts/templates/modify-website-content.prompt.txt new file mode 100644 index 0000000000..be6af29868 --- /dev/null +++ b/prompts/templates/modify-website-content.prompt.txt @@ -0,0 +1,16 @@ +Craft a webpage content which incorporates the following wallpaper description as an alt text: + +"${block(wallpaperDescription)}" + +Guidelines: +- The webpage title should not directly copy the alt text but should be creatively derived from it. +- Utilize markdown format. +- Begin with a concise heading. +- Aim for content that realistically portrays a functioning website, not a mere display of the wallpaper. +- The heading should not include words like "wallpaper" or "background". +- The content should feature real sections such as references, contact information, user stories, etc., as per the objective of the page. +- Structure the content with headings, bullets, numbering, blockquotes, paragraphs, horizontal lines, etc. +- Feel free to use bold or _italic_ text for emphasis. +- Incorporate UTF-8 emojis for added appeal. +- Links should be only #hash anchors referring to the document itself. +- Avoid including any images. \ No newline at end of file diff --git a/prompts/templates/write-website-claim.prompt.txt b/prompts/templates/write-website-claim.prompt.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/prompts/templates/write-website-content.prompt.txt b/prompts/templates/write-website-content.prompt.txt new file mode 100644 index 0000000000..a0dc318390 --- /dev/null +++ b/prompts/templates/write-website-content.prompt.txt @@ -0,0 +1,3 @@ +Following is markdown content of a webpage: + +${block(contentStart)} diff --git a/prompts/templates/write-website-font.prompt.txt b/prompts/templates/write-website-font.prompt.txt new file mode 100644 index 0000000000..cbf81d7129 --- /dev/null +++ b/prompts/templates/write-website-font.prompt.txt @@ -0,0 +1,12 @@ +Write me a Google font which is best fitting for the website. + +Pick from the list: +${block( + [...FONTS] + .sort(() => Math.random() - 0.5) + .map((fontName) => `- ${fontName}`) + .join('\n'), +)} + + +Write just the font name nothing else. \ No newline at end of file diff --git a/prompts/templates/write-website-title.prompt.txt b/prompts/templates/write-website-title.prompt.txt new file mode 100644 index 0000000000..8cfa5c597a --- /dev/null +++ b/prompts/templates/write-website-title.prompt.txt @@ -0,0 +1,8 @@ +Craft a title for webpage which incorporates the following wallpaper description as an alt text: + +"${block(wallpaperAssigment)}" + +Guidelines: +- This is a title for real website +- Be short and concise +- The title should not include parasitic words like "wallpaper" or "background". \ No newline at end of file From 656045885afdf6a685663506b7da587d421d7faa Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Sun, 17 Sep 2023 18:57:00 +0200 Subject: [PATCH 05/11] Prompt templates --- prompts/templates/write-website-content.prompt.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/prompts/templates/write-website-content.prompt.txt b/prompts/templates/write-website-content.prompt.txt index a0dc318390..b249a66cc0 100644 --- a/prompts/templates/write-website-content.prompt.txt +++ b/prompts/templates/write-website-content.prompt.txt @@ -1,3 +1,5 @@ Following is markdown content of a webpage: -${block(contentStart)} +# {TITLE} + +> {TOPIC} \ No newline at end of file From 0afaf039b410c43f94fcba6b1a083ff0b9b415df Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Mon, 18 Sep 2023 01:25:56 +0200 Subject: [PATCH 06/11] Prompt template files are in markdown --- .../templates/{enhance-post.cs.prompt.txt => enhance-post.cs.md} | 0 .../templates/{enhance-post.en.prompt.txt => enhance-post.en.md} | 0 .../{enhance-prompt.en.prompt.txt => enhance-prompt.en.md} | 0 ...odify-website-content.prompt.txt => modify-website-content.md} | 0 .../{write-website-claim.prompt.txt => write-website-claim.md} | 0 ...{write-website-content.prompt.txt => write-website-content.md} | 0 .../{write-website-font.prompt.txt => write-website-font.md} | 0 .../{write-website-title.prompt.txt => write-website-title.md} | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename prompts/templates/{enhance-post.cs.prompt.txt => enhance-post.cs.md} (100%) rename prompts/templates/{enhance-post.en.prompt.txt => enhance-post.en.md} (100%) rename prompts/templates/{enhance-prompt.en.prompt.txt => enhance-prompt.en.md} (100%) rename prompts/templates/{modify-website-content.prompt.txt => modify-website-content.md} (100%) rename prompts/templates/{write-website-claim.prompt.txt => write-website-claim.md} (100%) rename prompts/templates/{write-website-content.prompt.txt => write-website-content.md} (100%) rename prompts/templates/{write-website-font.prompt.txt => write-website-font.md} (100%) rename prompts/templates/{write-website-title.prompt.txt => write-website-title.md} (100%) diff --git a/prompts/templates/enhance-post.cs.prompt.txt b/prompts/templates/enhance-post.cs.md similarity index 100% rename from prompts/templates/enhance-post.cs.prompt.txt rename to prompts/templates/enhance-post.cs.md diff --git a/prompts/templates/enhance-post.en.prompt.txt b/prompts/templates/enhance-post.en.md similarity index 100% rename from prompts/templates/enhance-post.en.prompt.txt rename to prompts/templates/enhance-post.en.md diff --git a/prompts/templates/enhance-prompt.en.prompt.txt b/prompts/templates/enhance-prompt.en.md similarity index 100% rename from prompts/templates/enhance-prompt.en.prompt.txt rename to prompts/templates/enhance-prompt.en.md diff --git a/prompts/templates/modify-website-content.prompt.txt b/prompts/templates/modify-website-content.md similarity index 100% rename from prompts/templates/modify-website-content.prompt.txt rename to prompts/templates/modify-website-content.md diff --git a/prompts/templates/write-website-claim.prompt.txt b/prompts/templates/write-website-claim.md similarity index 100% rename from prompts/templates/write-website-claim.prompt.txt rename to prompts/templates/write-website-claim.md diff --git a/prompts/templates/write-website-content.prompt.txt b/prompts/templates/write-website-content.md similarity index 100% rename from prompts/templates/write-website-content.prompt.txt rename to prompts/templates/write-website-content.md diff --git a/prompts/templates/write-website-font.prompt.txt b/prompts/templates/write-website-font.md similarity index 100% rename from prompts/templates/write-website-font.prompt.txt rename to prompts/templates/write-website-font.md diff --git a/prompts/templates/write-website-title.prompt.txt b/prompts/templates/write-website-title.md similarity index 100% rename from prompts/templates/write-website-title.prompt.txt rename to prompts/templates/write-website-title.md From 5b7c1d0350c2e69d7f77cfe3f7bef0d17e45d397 Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Mon, 18 Sep 2023 01:27:03 +0200 Subject: [PATCH 07/11] Workerify in better folder --- src/components/Dialogues/dialogues/promptDialogue.tsx | 2 +- src/workers/{_ => 0-Workerify}/PostMessages.ts | 0 src/workers/{_ => 0-Workerify}/Workerify.ts | 0 src/workers/createNewWallpaper/createNewWallpaper.common.ts | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename src/workers/{_ => 0-Workerify}/PostMessages.ts (100%) rename src/workers/{_ => 0-Workerify}/Workerify.ts (100%) diff --git a/src/components/Dialogues/dialogues/promptDialogue.tsx b/src/components/Dialogues/dialogues/promptDialogue.tsx index 8a9f93d98d..f694ddc3e2 100644 --- a/src/components/Dialogues/dialogues/promptDialogue.tsx +++ b/src/components/Dialogues/dialogues/promptDialogue.tsx @@ -1,7 +1,7 @@ import { forTime } from 'waitasecond'; import { isRunningInWebWorker } from '../../../utils/isRunningInWhatever'; import { message } from '../../../utils/typeAliases'; -import { IMessageMainToWorker, IMessagePromptDialogue } from '../../../workers/_/PostMessages'; +import { IMessageMainToWorker, IMessagePromptDialogue } from '../../../workers/0-Workerify/PostMessages'; import { isDialoguesRendered } from '../locks/Dialogues.lock'; import { promptDialogueQueue } from '../queues/prompts'; diff --git a/src/workers/_/PostMessages.ts b/src/workers/0-Workerify/PostMessages.ts similarity index 100% rename from src/workers/_/PostMessages.ts rename to src/workers/0-Workerify/PostMessages.ts diff --git a/src/workers/_/Workerify.ts b/src/workers/0-Workerify/Workerify.ts similarity index 100% rename from src/workers/_/Workerify.ts rename to src/workers/0-Workerify/Workerify.ts diff --git a/src/workers/createNewWallpaper/createNewWallpaper.common.ts b/src/workers/createNewWallpaper/createNewWallpaper.common.ts index 82369e441b..dd3a32cc02 100644 --- a/src/workers/createNewWallpaper/createNewWallpaper.common.ts +++ b/src/workers/createNewWallpaper/createNewWallpaper.common.ts @@ -1,5 +1,5 @@ import { string_wallpaper_id, uuid } from '../../utils/typeAliases'; -import { Workerify } from '../_/Workerify'; +import { Workerify } from '../0-Workerify/Workerify'; export interface ICreateNewWallpaperRequest { author: uuid; From 64b753047a2788d3ff71f00c0d1c837390d4c90b Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Mon, 18 Sep 2023 01:27:23 +0200 Subject: [PATCH 08/11] Remove old prompt templates --- .../createContentPromptTemplate.ts | 38 ------------------- .../createFontPromptTemplate.ts | 32 ---------------- .../createTitlePromptTemplate.ts | 30 --------------- 3 files changed, 100 deletions(-) delete mode 100644 src/ai/text-to-text/prompt-templates/createContentPromptTemplate.ts delete mode 100644 src/ai/text-to-text/prompt-templates/createFontPromptTemplate.ts delete mode 100644 src/ai/text-to-text/prompt-templates/createTitlePromptTemplate.ts diff --git a/src/ai/text-to-text/prompt-templates/createContentPromptTemplate.ts b/src/ai/text-to-text/prompt-templates/createContentPromptTemplate.ts deleted file mode 100644 index 232361ca92..0000000000 --- a/src/ai/text-to-text/prompt-templates/createContentPromptTemplate.ts +++ /dev/null @@ -1,38 +0,0 @@ -import spaceTrim from 'spacetrim'; -import { image_description, string_chat_prompt, string_midjourney_prompt } from '../../../utils/typeAliases'; - -/** - * Generates a template for creating web content based on a given wallpaper description - * - * @param wallpaperDescription: A description of the wallpaper. This could be a plain description of the image or a prompt created from Azure's image cognition or MidJourney services. - * @returns A template that can be used with ChatGPT to generate a webpage content. - */ -export function createContentPromptTemplate( - wallpaperDescription: Exclude | string_midjourney_prompt, -): string_chat_prompt { - return spaceTrim( - (block) => - ` - Craft a webpage content which incorporates the following wallpaper description as an alt text: - - "${block(wallpaperDescription)}" - - Guidelines: - - The webpage title should not directly copy the alt text but should be creatively derived from it. - - Utilize markdown format. - - Begin with a concise heading. - - Aim for content that realistically portrays a functioning website, not a mere display of the wallpaper. - - The heading should not include words like "wallpaper" or "background". - - The content should feature real sections such as references, contact information, user stories, etc., as per the objective of the page. - - Structure the content with headings, bullets, numbering, blockquotes, paragraphs, horizontal lines, etc. - - Feel free to use bold or _italic_ text for emphasis. - - Incorporate UTF-8 emojis for added appeal. - - Links should be only #hash anchors referring to the document itself. - - Avoid including any images. - `, - ); -} - -/** - * TODO: [🤡] Make some model comparision - */ diff --git a/src/ai/text-to-text/prompt-templates/createFontPromptTemplate.ts b/src/ai/text-to-text/prompt-templates/createFontPromptTemplate.ts deleted file mode 100644 index 893e50458a..0000000000 --- a/src/ai/text-to-text/prompt-templates/createFontPromptTemplate.ts +++ /dev/null @@ -1,32 +0,0 @@ -import spaceTrim from 'spacetrim'; -import { FONTS } from '../../../../config'; -import { string_chat_prompt } from '../../../utils/typeAliases'; - -/** - * Generates a template for figuring out best fitting font for the website. - * - * Note: This should be a second message in the conversation after the createTitlePromptTemplate - * - * @returns A template that can be used with ChatGPT to detect best fitting font for the website. - */ -export function createFontPromptTemplate(): string_chat_prompt { - return spaceTrim( - (block) => - ` - Write me a Google font which is best fitting for the website. - - Pick from the list: - ${block( - [...FONTS] - .sort(() => Math.random() - 0.5) - .map((fontName) => `- ${fontName}`) - .join('\n'), - )} - - - Write just the font name nothing else. - - - `, - ); -} diff --git a/src/ai/text-to-text/prompt-templates/createTitlePromptTemplate.ts b/src/ai/text-to-text/prompt-templates/createTitlePromptTemplate.ts deleted file mode 100644 index 48255b2d04..0000000000 --- a/src/ai/text-to-text/prompt-templates/createTitlePromptTemplate.ts +++ /dev/null @@ -1,30 +0,0 @@ -import spaceTrim from 'spacetrim'; -import { image_description, string_chat_prompt, string_midjourney_prompt } from '../../../utils/typeAliases'; - -/** - * Generates a template for creating web title based on a given wallpaper description - * - * @param wallpaperAssigment: A description of the wallpaper. This could be a plain description of the image or a prompt created from Azure's image cognition or MidJourney services. - * @returns A title of the web - */ -export function createTitlePromptTemplate( - wallpaperAssigment: Exclude | string_midjourney_prompt, -): string_chat_prompt { - return spaceTrim( - (block) => - ` - Craft a title for webpage which incorporates the following wallpaper description as an alt text: - - "${block(wallpaperAssigment)}" - - Guidelines: - - This is a title for real website - - Be short and concise - - The title should not include parasitic words like "wallpaper" or "background". - `, - ); -} - -/** - * TODO: [🤡] Make some model comparision - */ From 12f2badf507ffd9f7d89ef863a8f59d16c3b8e0c Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Mon, 18 Sep 2023 01:27:35 +0200 Subject: [PATCH 09/11] Prompt templates --- src/ai/text-to-text/ChatThread.ts | 13 +++--- src/ai/text-to-text/completeWithGpt.ts | 9 ++-- .../prompt-templates/PromptTemplate.ts | 42 +++++++++++++++++++ src/ai/text-to-text/prompt-templates/TODO.txt | 3 -- src/ai/text-to-text/prompt-templates/index.ts | 16 +++++++ src/ai/text-to-text/writeWallpaperContent.ts | 41 ++++++------------ src/utils/typeAliases.ts | 7 ++++ 7 files changed, 90 insertions(+), 41 deletions(-) create mode 100644 src/ai/text-to-text/prompt-templates/PromptTemplate.ts delete mode 100644 src/ai/text-to-text/prompt-templates/TODO.txt create mode 100644 src/ai/text-to-text/prompt-templates/index.ts diff --git a/src/ai/text-to-text/ChatThread.ts b/src/ai/text-to-text/ChatThread.ts index 449a78886c..f03369e394 100644 --- a/src/ai/text-to-text/ChatThread.ts +++ b/src/ai/text-to-text/ChatThread.ts @@ -1,6 +1,7 @@ import { getSupabaseForServer } from '../../utils/supabase/getSupabaseForServer'; -import { string_chat_prompt, string_model_name, uuid } from '../../utils/typeAliases'; +import { string_model_name, uuid } from '../../utils/typeAliases'; import { getOpenaiForServer } from './getOpenaiForServer'; +import { Prompt } from './prompt-templates/PromptTemplate'; /** * Thread to the ChotGPT @@ -14,7 +15,7 @@ export class ChatThread { * @param request text to send to the OpenAI API * @returns response from the OpenAI API wrapped in ChatThread */ - public static async ask(request: string_chat_prompt, clientId: uuid /* <-[🌺] */): Promise { + public static async ask(request: Prompt<'CHAT'>, clientId: uuid /* <-[🌺] */): Promise { return /* not await */ ChatThread.create(null, request, clientId); } @@ -24,7 +25,7 @@ export class ChatThread { */ private static async create( parentChatThread: null | ChatThread, - request: string_chat_prompt, + request: Prompt<'CHAT'>, clientId: uuid /* <-[🌺] */, ): Promise { const mark = `ask-gpt-${parentChatThread ? parentChatThread.chatSize : 1}`; @@ -38,7 +39,7 @@ export class ChatThread { messages: [ { role: 'user', - content: request, + content: request.toString(), }, ], }); @@ -109,7 +110,7 @@ export class ChatThread { public readonly clientId: uuid /* <-[🌺] */, public readonly parent: null | ChatThread, public readonly model: string_model_name, - public readonly request: string_chat_prompt, + public readonly request: Prompt<'CHAT'>, public readonly response: string, ) {} @@ -119,7 +120,7 @@ export class ChatThread { * @param request text to send to the OpenAI API * @returns response from the OpenAI API wrapped in ChatThread */ - public async ask(request: string_chat_prompt): Promise { + public async ask(request: Prompt<'CHAT'>): Promise { return /* not await */ ChatThread.create(this, request, this.clientId); } diff --git a/src/ai/text-to-text/completeWithGpt.ts b/src/ai/text-to-text/completeWithGpt.ts index 1a322ca8cb..dfa1147519 100644 --- a/src/ai/text-to-text/completeWithGpt.ts +++ b/src/ai/text-to-text/completeWithGpt.ts @@ -1,6 +1,7 @@ import { getSupabaseForServer } from '../../utils/supabase/getSupabaseForServer'; -import { string_completion_prompt, string_model_name, uuid } from '../../utils/typeAliases'; +import { string_model_name, uuid } from '../../utils/typeAliases'; import { getOpenaiForServer } from './getOpenaiForServer'; +import { Prompt } from './prompt-templates/PromptTemplate'; export interface ICompleteWithGptResult { response: string; @@ -13,14 +14,14 @@ export interface ICompleteWithGptResult { * Note: This function is aviable only on the server */ export async function completeWithGpt( - prompt: string_completion_prompt, + prompt: Prompt<'COMPLETION'>, clientId: uuid /* <-[🌺] */, ): Promise { const model = 'text-davinci-003'; const modelSettings = { model, max_tokens: 500, - // <- TODO: [🤡] Tweak, hardcode+note or put in config + Pick the best model, max_tokens, top_t,... other params + // <- TODO: Tweak, hardcode+note or put in config + Pick the best model, max_tokens, top_t,... other params }; const promptAt = new Date(); @@ -75,7 +76,7 @@ export async function completeWithGpt( performance.mark('complete-gpt-start'); const completion = await getOpenaiForServer().completions.create({ ...modelSettings, - prompt, + prompt: prompt.toString(), }); performance.mark('complete-gpt-end'); const answerAt = new Date(); diff --git a/src/ai/text-to-text/prompt-templates/PromptTemplate.ts b/src/ai/text-to-text/prompt-templates/PromptTemplate.ts new file mode 100644 index 0000000000..ecddf219b7 --- /dev/null +++ b/src/ai/text-to-text/prompt-templates/PromptTemplate.ts @@ -0,0 +1,42 @@ +import spaceTrim from 'spacetrim'; +import { string_prompt, string_template } from '../../../utils/typeAliases'; + +/** + * + */ +type PromptTemplateParams = Record; + +/** + * !!! Annotate all + + */ +export class PromptTemplate { + public constructor(public readonly templateContent: string_prompt & string_template) {} + + makePrompt(params: PromptTemplateParams): Prompt { + return new Prompt(this, params); + } +} + +/** + * !!! Annotate all + + */ +export class Prompt { + public constructor(public readonly template: PromptTemplate, public readonly params: PromptTemplateParams) {} + + toString(): string_prompt { + let prompt = this.template.templateContent; + prompt = spaceTrim(prompt); + // TODO: !!! Replace all params + // TODO: !!! Remove comments + + return prompt; + } +} + +/** + * TODO: !!! Model requirements like modelName + * TODO: !!! Model requirements like COMPLETION vs CHAT + ACRY DRY + * TODO: !!! template version + * TODO: !!! template language + * TODO: !!! Log the template + */ diff --git a/src/ai/text-to-text/prompt-templates/TODO.txt b/src/ai/text-to-text/prompt-templates/TODO.txt deleted file mode 100644 index d6b2dda160..0000000000 --- a/src/ai/text-to-text/prompt-templates/TODO.txt +++ /dev/null @@ -1,3 +0,0 @@ -TODO: !!! Use .prompt.txt files -TODO: !! Prompt templates should be in .txt files in /promps folder -TODO: !! Record all prompt (template) performance to be able to A/B test them diff --git a/src/ai/text-to-text/prompt-templates/index.ts b/src/ai/text-to-text/prompt-templates/index.ts new file mode 100644 index 0000000000..0b2598e28e --- /dev/null +++ b/src/ai/text-to-text/prompt-templates/index.ts @@ -0,0 +1,16 @@ +import modifyWebsiteContent from '../../../../prompts/templates/modify-website-content.md'; +import writeWebsiteClaim from '../../../../prompts/templates/write-website-claim.md'; +import writeWebsiteContent from '../../../../prompts/templates/write-website-content.md'; +import writeWebsiteFont from '../../../../prompts/templates/write-website-font.md'; +import writeWebsiteTitle from '../../../../prompts/templates/write-website-title.md'; +import { PromptTemplate } from './PromptTemplate'; + +export const MODIFY_WEBSITE_CONTENT_TEMPLATE = new PromptTemplate<'CHAT'>(modifyWebsiteContent); +export const WRITE_WEBSITE_TITLE_TEMPLATE = new PromptTemplate<'CHAT'>(writeWebsiteTitle); +export const WRITE_WEBSITE_CLAIM_TEMPLATE = new PromptTemplate<'CHAT'>(writeWebsiteClaim); +export const WRITE_WEBSITE_CONTENT_TEMPLATE = new PromptTemplate<'CHAT'>(writeWebsiteContent); +export const WRITE_WEBSITE_FONT_TEMPLATE = new PromptTemplate<'CHAT'>(writeWebsiteFont); + +/** + * TODO: This should be auto-generated from the /prompts/templates/ folder + */ diff --git a/src/ai/text-to-text/writeWallpaperContent.ts b/src/ai/text-to-text/writeWallpaperContent.ts index 6a0aa7aaf9..6b124ad5e0 100644 --- a/src/ai/text-to-text/writeWallpaperContent.ts +++ b/src/ai/text-to-text/writeWallpaperContent.ts @@ -10,8 +10,11 @@ import { } from '../../utils/typeAliases'; import { ChatThread } from './ChatThread'; import { completeWithGpt } from './completeWithGpt'; -import { createFontPromptTemplate } from './prompt-templates/createFontPromptTemplate'; -import { createTitlePromptTemplate } from './prompt-templates/createTitlePromptTemplate'; +import { + WRITE_WEBSITE_CONTENT_TEMPLATE, + WRITE_WEBSITE_FONT_TEMPLATE, + WRITE_WEBSITE_TITLE_TEMPLATE, +} from './prompt-templates'; /** * Writes the rich content of the wallpaper page @@ -25,11 +28,12 @@ export async function writeWallpaperContent( wallpaperAssigment: Exclude | string_midjourney_prompt, clientId: uuid /* <-[🌺] */, ): Promise { - const prompt = createTitlePromptTemplate(wallpaperAssigment); - const chatThread = await ChatThread.ask(prompt, clientId); - const { response, model: modelToCreateTitle } = chatThread; - const { title, topic } = parseTitleAndTopic(removeQuotes(response)); + const writeTitlePrompt = WRITE_WEBSITE_TITLE_TEMPLATE.makePrompt({}); + const writeTitleThread = await ChatThread.ask(writeTitlePrompt, clientId); + const { response: titleRaw, model: writeTitleModel } = writeTitleThread; + const { title, topic } = parseTitleAndTopic(removeQuotes(titleRaw)); + // TODO: !!! USE WRITE_WEBSITE_CLAIM_TEMPLATE // TODO: !!! Separate title, claim and content writing endpoint // TODO: !!! Use MAX_CHARS_IN_TITLE // TODO: !!! Use MAX_CHARS_IN_TITLE_WORD @@ -42,27 +46,16 @@ export async function writeWallpaperContent( `, ); - const { response: contentMiddle, model: modelToCreateContent } = await completeWithGpt( - spaceTrim( - // TODO: [🤡] This prompt should be also created in some template function - // TODO: [🤡] Pefect this prompt - (block) => ` - - Following is markdown content of a webpage: - - ${block(contentStart)} - - `, - ), + const { response: contentMiddle, model: modelToCreateContentMiddle } = await completeWithGpt( + WRITE_WEBSITE_CONTENT_TEMPLATE.makePrompt({ contentStart /* <- !!! In prompt template file */ }), clientId, ); // TODO: !!! Remove strange images https://1-2i.com/mountain-sunset-2gr7dv4ybstg // TODO: !!! Test that the content is valid and rich markdown - // TODO: !!! Use .prompt.txt files // TODO: !!! Do NOT use words like "serene", "serenity" soo often - const chatThreadFont = await chatThread.ask(createFontPromptTemplate()); + const chatThreadFont = await writeTitleThread.ask(WRITE_WEBSITE_FONT_TEMPLATE.makePrompt({})); const font = removeQuotes(chatThreadFont.response) as string_font_family; // TODO: !!! Better font picking @@ -75,14 +68,6 @@ export async function writeWallpaperContent( ${block(contentStart)} ${block(contentMiddle)} - - `, ); diff --git a/src/utils/typeAliases.ts b/src/utils/typeAliases.ts index d0a2781bf2..cffa6953b6 100644 --- a/src/utils/typeAliases.ts +++ b/src/utils/typeAliases.ts @@ -33,6 +33,13 @@ export type string_model_name = */ export type string_prompt = string; +/** + * Semantic helper + * + * For example `"A cat wearing a {ITEM}"` + */ +export type string_template = string; + /** * Semantic helper * From 6d8d453f18092bbdeeecb19c8faa251e85658fa1 Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Thu, 21 Sep 2023 23:43:26 +0200 Subject: [PATCH 10/11] Moving TODOs to branch feature/ptp --- config.ts | 2 - .../prompt-templates/PromptTemplate.ts | 42 ------------------- src/ai/text-to-text/writeWallpaperContent.ts | 9 +--- 3 files changed, 2 insertions(+), 51 deletions(-) delete mode 100644 src/ai/text-to-text/prompt-templates/PromptTemplate.ts diff --git a/config.ts b/config.ts index a99bff41af..7de739b74d 100644 --- a/config.ts +++ b/config.ts @@ -824,8 +824,6 @@ export const FONTS = [ 'Zeyada', ] as const; -// TODO: !!! MAX_CHARS_IN_TITLE_WORD - export const COPILOT_PLACEHOLDERS: Array = [ // Note: ⏣ Describe the change> 'Translate to Chinese', diff --git a/src/ai/text-to-text/prompt-templates/PromptTemplate.ts b/src/ai/text-to-text/prompt-templates/PromptTemplate.ts deleted file mode 100644 index ecddf219b7..0000000000 --- a/src/ai/text-to-text/prompt-templates/PromptTemplate.ts +++ /dev/null @@ -1,42 +0,0 @@ -import spaceTrim from 'spacetrim'; -import { string_prompt, string_template } from '../../../utils/typeAliases'; - -/** - * - */ -type PromptTemplateParams = Record; - -/** - * !!! Annotate all + - */ -export class PromptTemplate { - public constructor(public readonly templateContent: string_prompt & string_template) {} - - makePrompt(params: PromptTemplateParams): Prompt { - return new Prompt(this, params); - } -} - -/** - * !!! Annotate all + - */ -export class Prompt { - public constructor(public readonly template: PromptTemplate, public readonly params: PromptTemplateParams) {} - - toString(): string_prompt { - let prompt = this.template.templateContent; - prompt = spaceTrim(prompt); - // TODO: !!! Replace all params - // TODO: !!! Remove comments - - return prompt; - } -} - -/** - * TODO: !!! Model requirements like modelName - * TODO: !!! Model requirements like COMPLETION vs CHAT + ACRY DRY - * TODO: !!! template version - * TODO: !!! template language - * TODO: !!! Log the template - */ diff --git a/src/ai/text-to-text/writeWallpaperContent.ts b/src/ai/text-to-text/writeWallpaperContent.ts index 80ad5f5900..d298ac7926 100644 --- a/src/ai/text-to-text/writeWallpaperContent.ts +++ b/src/ai/text-to-text/writeWallpaperContent.ts @@ -123,8 +123,7 @@ export async function writeWallpaperContent(options: WriteWallpaperContentOption ); } - // TODO: !!! Use here addSections and links - + const { response: contentMiddle, model: modelToCreateContent } = await completeWithGpt( spaceTrim( // TODO: [🤡] This prompt should be also created in some template function @@ -142,11 +141,7 @@ export async function writeWallpaperContent(options: WriteWallpaperContentOption // TODO: !!! Use or makeWrite WRITE_WEBSITE_CONTENT_TEMPLATE - /* - TODO: !!! Better - const chatThreadFont = await chatThread.ask(createFontPromptTemplate()); - const font = removeQuotes(chatThreadFont.response) as string_font_family; - */ + const font = randomItem(...FONTS); From 05c3da26fbda6a7b42e5e64dcd245c5d1cf85328 Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Thu, 21 Sep 2023 23:45:13 +0200 Subject: [PATCH 11/11] Revert "Moving TODOs to branch feature/ptp" This reverts commit 6d8d453f18092bbdeeecb19c8faa251e85658fa1. --- config.ts | 2 + .../prompt-templates/PromptTemplate.ts | 42 +++++++++++++++++++ src/ai/text-to-text/writeWallpaperContent.ts | 9 +++- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/ai/text-to-text/prompt-templates/PromptTemplate.ts diff --git a/config.ts b/config.ts index 7de739b74d..a99bff41af 100644 --- a/config.ts +++ b/config.ts @@ -824,6 +824,8 @@ export const FONTS = [ 'Zeyada', ] as const; +// TODO: !!! MAX_CHARS_IN_TITLE_WORD + export const COPILOT_PLACEHOLDERS: Array = [ // Note: ⏣ Describe the change> 'Translate to Chinese', diff --git a/src/ai/text-to-text/prompt-templates/PromptTemplate.ts b/src/ai/text-to-text/prompt-templates/PromptTemplate.ts new file mode 100644 index 0000000000..ecddf219b7 --- /dev/null +++ b/src/ai/text-to-text/prompt-templates/PromptTemplate.ts @@ -0,0 +1,42 @@ +import spaceTrim from 'spacetrim'; +import { string_prompt, string_template } from '../../../utils/typeAliases'; + +/** + * + */ +type PromptTemplateParams = Record; + +/** + * !!! Annotate all + + */ +export class PromptTemplate { + public constructor(public readonly templateContent: string_prompt & string_template) {} + + makePrompt(params: PromptTemplateParams): Prompt { + return new Prompt(this, params); + } +} + +/** + * !!! Annotate all + + */ +export class Prompt { + public constructor(public readonly template: PromptTemplate, public readonly params: PromptTemplateParams) {} + + toString(): string_prompt { + let prompt = this.template.templateContent; + prompt = spaceTrim(prompt); + // TODO: !!! Replace all params + // TODO: !!! Remove comments + + return prompt; + } +} + +/** + * TODO: !!! Model requirements like modelName + * TODO: !!! Model requirements like COMPLETION vs CHAT + ACRY DRY + * TODO: !!! template version + * TODO: !!! template language + * TODO: !!! Log the template + */ diff --git a/src/ai/text-to-text/writeWallpaperContent.ts b/src/ai/text-to-text/writeWallpaperContent.ts index d298ac7926..80ad5f5900 100644 --- a/src/ai/text-to-text/writeWallpaperContent.ts +++ b/src/ai/text-to-text/writeWallpaperContent.ts @@ -123,7 +123,8 @@ export async function writeWallpaperContent(options: WriteWallpaperContentOption ); } - + // TODO: !!! Use here addSections and links + const { response: contentMiddle, model: modelToCreateContent } = await completeWithGpt( spaceTrim( // TODO: [🤡] This prompt should be also created in some template function @@ -141,7 +142,11 @@ export async function writeWallpaperContent(options: WriteWallpaperContentOption // TODO: !!! Use or makeWrite WRITE_WEBSITE_CONTENT_TEMPLATE - + /* + TODO: !!! Better + const chatThreadFont = await chatThread.ask(createFontPromptTemplate()); + const font = removeQuotes(chatThreadFont.response) as string_font_family; + */ const font = randomItem(...FONTS);