Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Generate prompt for leonardo #56

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

AliLee0923
Copy link
Contributor

  • Created a function for generating detailed image prompts based on an array of words using the OpenAI gpt-3.5-turbo-instruct model. It creates a pictogram-style description for each word, determining whether the word represents an ACTION or OBJECT, and formats the prompt accordingly. (generatePromptForImageGeneration)
  • Created another function for combining the functionality of generating word suggestions and prompts for Leonardo AI. It fetches suggestions based on a given prompt, processes them into a list of detailed image prompts, and returns the results. (getPromptsForLenonardo)
  • Created a function for generating a detailed image prompt for a single word using the OpenAI API. This is a simplified and focused version of generatePromptForImageGeneration, handling only one word at a time. (generateAPromptForLeonardo)

src/engine.ts Outdated
words: string[];
}): Promise<Array<{ word: string; prompt: string }>> {
const completionRequestParams = {
model: "gpt-3.5-turbo-instruct",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the model to the 4o mini

src/engine.ts Outdated
Comment on lines 188 to 276
// A function to generate a prompt for generating images from Leonardo AI using gpt-4o-mini and provided template and words
export async function generatePromptForImageGeneration({
words,
}: {
words: string[];
}): Promise<Array<{ word: string; prompt: string }>> {
const completionRequestParams = {
model: "gpt-4o-mini",
messages: [
{
role: "system",
content: `Create a detailed prompt to generate a pictogram for each word of the words array: '${words}'.
First, determine if this is primarily an ACTION or OBJECT, then create a prompt following the appropriate template below.

For ACTIONS (verbs, activities):
- Show a figure actively performing the action
- Include clear motion indicators where appropriate
- Focus on the most recognizable moment of the action
- Use side view if it better shows the action
- Include minimal but necessary context elements

Style requirements:
- Bold black outlines
- Flat colors
- High contrast
- Centered composition
- White background
- Simple geometric shapes

Return only the prompt for each word, no explanations. Keep it under 100 words for each word.
The returned template should be like this:
word1: 'prompt',
word2: 'prompt',
...
wordN: 'prompt'`,
},
{
role: "user",
content: `Generate Prompts for ${words}`,
},
],
temperature: 0,
max_tokens: 1500,
};

const response = await globalConfiguration.openAIInstance.createCompletion(
completionRequestParams
);
const promptText = response.data?.choices[0]?.text;
if (!promptText)
throw new Error("Error generating prompt for image generation");
try {
// Split the text by newlines and parse each line
const lines = promptText.split("\n").filter((line) => line.trim());
return lines.map((line) => {
const [word, ...promptParts] = line.split(":");
return {
word: word.trim(),
prompt: promptParts
.join(":")
.trim()
.replace(/^['"]|['"]$/g, ""), // Remove quotes if present
};
});
} catch (error) {
throw new Error("Error parsing image generation prompts: " + error);
}
}

export async function getPromptsForLenonardo({
prompt,
maxWords,
language,
}: {
prompt: string;
maxWords: number;
language: string;
}) {
const promptedWords = await getWordSuggestions({
prompt,
maxWords,
language,
});
const leonardoPrompts = await generatePromptForImageGeneration({
words: promptedWords,
});

return leonardoPrompts;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are not going to use this two functions. At least their are not being added to the return of the init function. Do you think we are going to use this? Also the generatePromptForImageGeneration it has a really different prompt content than the generateAPromptForLeonardo.
If you consider that we are going to use it, add it to the init return. Otherwise remove this functions from the PR 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants