UNPKG

llm-pdf

Version:

Command Line tool to automate LLM and image models to generate a pdf by converting the generated text into markdown format and save it as a pdf document.

80 lines (73 loc) 5.06 kB
import Together from "together-ai"; // import dotenv from "dotenv"; import generateImage from "./image.js"; // dotenv.config(); const together = new Together({ apiKey: "26d7651e279a9c77d6b0a1e3fdd5167788978e10ca35a02a02a0047fa6c714cc" }); async function generatePrompt(prompt) { try { const response = await together.chat.completions.create({ messages: [ { role: "system", content: `Objective: This system will generate creative and detailed AI image prompts based on a user's description, emulating the distinctive style and structure observed in a comprehensive set of user-provided example prompts. The system will aim for accuracy, detail, and flexibility, ensuring the generated prompts are suitable for use with AI image generators like Midjourney, Stable Diffusion, and DALL-E. Core Principles: Faithful Style Replication: The system will prioritize mirroring the nuanced style of the user's examples. This includes: Concise Subject Introduction: Starting with a clear and brief subject or scene description. Varied Style Keywords: Incorporating a diverse range of keywords related to art style, photography techniques, and desired aesthetics (e.g., "cinematic," "Pixar-style," "photorealistic," "minimalist," "surrealism"). Artistic References: Integrating specific artists, art movements, or pop culture references to guide the AI's stylistic interpretation. Optional Technical Details: Including optional yet specific details about: Camera and Lens: "Canon EOS R5," "Nikon D850 with a macro lens," "35mm lens at f/8." Film Stock: "Kodak film," "Fujifilm Provia." Post-Processing: "Film grain," "lens aberration," "color negative," "bokeh." AI Model Parameters: Adding relevant parameters like aspect ratio ("--ar 16:9"), stylization ("--stylize 750"), chaos ("--s 750"), or version ("--v 6.0"). Negative Prompts: Employing negative prompts to exclude undesired elements. Emphasis Techniques: Utilizing parentheses, brackets, or capitalization to highlight key elements within the prompt. User-Centric Design: Clarity and Specificity: The generated prompts should be clear, specific, and easily understood by the AI. Open-Ended Options: Allow for open-ended descriptions when users seek more creative freedom. Iterative Refinement: Support modifications and adjustments based on user feedback to facilitate an iterative creation process. Comprehensive Prompt Structure: Subject: Clearly define the primary subject(s) of the image. Action/Pose: Describe actions or poses the subject(s) might be performing. Environment/Background: Establish the scene's setting, including background elements. Style/Art Medium: Specify the desired artistic style or medium (photography, illustration, painting, pixel art, etc.). Lighting: Detail the lighting conditions (soft light, dramatic light, natural light, studio lighting, etc.). Color Palette: Suggest a specific color palette or individual colors. Composition: Indicate the preferred composition (close-up, wide-angle, symmetrical, minimalist, etc.). Details/Texture: Include descriptions of textures, patterns, and specific features. Mood/Atmosphere: Optionally evoke a mood or atmosphere to guide the AI's interpretation (melancholic, mysterious, serene, etc.). Example Interaction: User Input: "A portrait of a futuristic robot, with neon lights reflecting on its metallic surface, in a cyberpunk city." System Output: "Portrait of a futuristic robot, neon lights reflecting on its metallic surface, standing in a cyberpunk city, detailed circuitry, glowing eyes, (gritty), (cyberpunk aesthetic), in the style of Syd Mead, cinematic lighting, 85mm lens, film grain, --ar 3:2 --v 6.0 --style raw"` }, { role: "user", content: `The user is asking a question or a topic, Generate a prompt for generating a photographic image to correctly describe the thing. Here is the question / topic: ${prompt}` } ], model: "meta-llama/Llama-3.3-70B-Instruct-Turbo-Free", // model: "deepseek-ai/DeepSeek-R1-Distill-Llama-70B-free", max_tokens: null, temperature: 0.7, top_p: 0.7, top_k: 50, repetition_penalty: 1, stop: ["/bye"], stream: true }); let content = ""; for await (const token of response) { const messageToken = token.choices[0]?.delta?.content || ''; process.stdout.write(messageToken); content += messageToken; } console.log("\n"); const imageInMarkdown = await generateImage(content); return imageInMarkdown; } catch (error) { console.error("Error getting response:", error); } } export default generatePrompt;