DEV Community

shashank ms
shashank ms

Posted on

Unlocking Creative Potential with LLMs

We are going to build a command-line creative writing partner that turns a one-sentence premise into a structured short story, complete with a title and back-cover blurb. It is useful for authors who want to blast through writer's block or content teams that need fictional prototypes fast. Because Oxlo.ai charges one flat rate per request, you can iterate on long outlines and full drafts without token costs scaling with every paragraph. See https://oxlo.ai/pricing for details.

What you'll need

Step 1: Set up the client and system prompt

I define a single system prompt that grounds the model in narrative craft. Keeping one prompt lets me reuse it across every stage of the pipeline.

SYSTEM_PROMPT = """You are an experienced fiction editor who specializes in tight, literary short fiction. You write in a modern, accessible prose style. You avoid clichés and deus ex machina endings. When asked for an outline, produce a three-act structure with one paragraph per act. When asked for prose, write complete scenes with sensory detail and dialogue. When asked for metadata, return compact JSON containing exactly two keys: title and blurb."""

Next I initialize the Oxlo.ai client. The OpenAI SDK works as a drop-in replacement, so only the base URL and API key change.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

Step 2: Generate a three-act outline

The first function takes a user premise and returns a structured outline. I use Llama 3.3 70B because it handles general-purpose creative reasoning reliably.

def generate_outline(premise: str) -> str:
    user_message = (
        f"Write a three-act outline for a 1,000-word short story based on this premise: {premise}"
    )

    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ],
    )

    return response.choices[0].message.content

Step 3: Draft the story

With the outline in hand, the second function asks the model for the full prose. I switch to Qwen 3 32B here to show how easily you can swap models on Oxlo.ai to match the task.

def draft_story(outline: str) -> str:
    user_message = (
        f"Turn the following outline into a complete 1,000-word short story.\n\n{outline}"
    )

    response = client.chat.completions.create(
        model="qwen-3-32b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ],
    )

    return response.choices[0].message.content

Step 4: Generate title and blurb

Finally, I extract marketing metadata. I ask for JSON so I can parse the result downstream. DeepSeek V3.2 handles structured instructions well, and Oxlo.ai supports JSON mode without extra configuration.

import json

def generate_metadata(story_text: str) -> dict:
    user_message = (
        f"Return JSON with a title and a one-sentence blurb for this story:\n\n{story_text}"
    )

    response = client.chat.completions.create(
        model="deepseek-v3.2",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ],
        response_format={"type": "json_object"},
    )

    raw = response.choices[0].message.content
    return json.loads(raw)

Step 5: Assemble the pipeline

Now I wire the three functions into a single script. I print each stage so I can watch the creative pipeline unfold.

def main():
    premise = input("Story premise: ")

    print("\nGenerating outline...")
    outline = generate_outline(premise)
    print("\n--- OUTLINE ---\n", outline)

    print("\nDrafting story...")
    story = draft_story(outline)
    print("\n--- STORY ---\n", story)

    print("\nGenerating metadata...")
    meta = generate_metadata(story)
    print("\n--- METADATA ---\n", json.dumps(meta, indent=2))

if __name__ == "__main__":
    main()

Run it

Save everything into a file named story_builder.py, export your key, and run the script.

export OXLO_API_KEY="YOUR_OXLO_API_KEY"
python story_builder.py

Example session using the premise "A librarian discovers that overdue books predict the future":

Story premise: A librarian discovers that overdue books predict the future

Generating outline...

--- OUTLINE ---
Act I: Elena notices that every book returned late by a specific patron contains highlighted passages describing accidents that happen the next day...
Act II: She tests the pattern by withholding a return, and a predicted fire breaks out in the cafe across the street...
Act III: She confronts the patron, only to learn he is not predicting the future but rewriting it, and the overdue fees are the price of his guilt...

Drafting story...

--- STORY ---
The dust motes danced in the afternoon sun as Elena opened the returns bin. She had worked at the West Branch library for eleven years, and she knew every patron's habits...

Generating metadata...

--- METADATA ---
{
  "title": "The Late Prophecies",
  "blurb": "When a small-town librarian notices that overdue books describe tomorrow's disasters, she uncovers a patron who rewrites reality one page at a time."
}

Wrap-up and next steps

This pipeline gives you a reproducible way to go from idea to draft in under a minute. Because Oxlo.ai pricing is flat per request, you can rerun the pipeline or swap in larger context windows for novella-length outlines without worrying about token costs.

Two concrete next steps: add a revision loop where you feed the story back to the model with a critique prompt and ask for a rewritten second draft, or expose the pipeline through a lightweight FastAPI endpoint so a frontend can call it.

Top comments (0)