Learn more about our ✨ new ✨ native MCP
Directus Logo
  • Use Cases and Features
    • Headless CMS
      Manage and deliver content with ease
    • Backend-as-a-Service
      Build and ship applications faster
    • Headless Commerce
      A single source of truth for products
    • 100+ More Use Cases
      Build anything (or everything)
    • Instant APIs
      Connect a database, get REST + GraphQL APIs
    • Granular Policy-Based Auth
      Provide secure, autonomous data access
    • Visual Automation Builder
      Automate content and data workflows with ease
    • 50+ More Features
      Get everything you need out-of-the-box
    Project Showcase
    Built With Directus

    Built With Directus

    See what everyone's been building with Directus

  • Learn More
    • Blog
      Read our latest articles and guides
    • Case Studies
      Case studies and success stories
    • Community
      Join our new community forum.
    • Agency Directory
      Browse our list of agency partners
    • About Us
      Learn more about Directus and the team
    • Wall of Love
      See what others are saying about us
    • Contact
      Have a general inquiry or question for us?
    • Support
      Reach out to Directus support
    Watch Directus TV
    Directus TV
    Video

    Directus TV

    Go down the rabbit hole with hours of original video content from our team.

  • Developers
  • Enterprise
  • Pricing
Book a DemoGet StartedLog In
GitHub logo33,617
Directus Marketplace
Marketplace
  1. Extensions
  2. Integrations
  3. Templates
Back to Extensions
operation

AI Writer Operation

Use OpenAI, Claude, Meta and Mistral Text Generation APIs to generate text.

AI Writer Operation

Generate text based on a written prompt within Directus Flows with this custom operation, powered by OpenAI's Text Generation API, Anthropic MistralAi (via Replicate) and Meta's LLama (via Replicate).

The AI Writer operation, showing a masked OpenAI API Key field, model and prompt selection fields, and a multiline text input.

Configuration

This operation contains some configuration options - an Api-Key, a selection of which model and prompt to use, and a text input. The text input can contain references like {{$last.data}} to refer to data available in the current flow. The prompt can be customised further using the optional Messages repeater field. The operation returns a string of the transformed or generated text.

The output showing a string that has been grammatically fixed.

API-Keys

You can generate your API-Keys on the follosing sites:

  • OpenAI
  • Anthropic
  • Replicate

Custom Prompts

For a completely custom prompt using the "Create custom prompt" type, you will need to create a system message at the start of the message thread so that the Text Generation API knows how it should respond. Examples of initial system prompts can be found in the config objects of each built-in prompt in the source code of this extension. OpenAI also provides a solid overview of how to write good prompts.

Customising Responses (Advanced users)

The Messages repeater can be used to create or extend seed prompts to OpenAI's Text Generation API. The Messages repeater creates an array of messages that form a conversation thread. The Text Generation API will refer to the thread to determine how it should respond to further user prompts. The content in the Text field is used as the last user prompt sent to the Text Generation API before receiving the final response. This response is forwarded to the next operation in the flow as a string.

Messages can be simulated as coming from one of three roles:

  • System — Modifies the personality of the assistant or provide specific instructions about how it should behave throughout the conversation. An initial system message is already included for each prompt type. Using this option will add further system messages to the thread.
  • User — User provided requests or comments for the assistant to respond to
  • Assistant — Example responses generated by the Text Generation API to help provide hints on how the Generative Text API should respond.

OpenAI's Documentation explains further how the underlying API and models work. It may be helpful to read these to better understand the underlying process. The following quote from the documentation is important for understanding the Message Thread format and intent:

Typically, a conversation is formatted with a system message first, followed by alternating user and assistant messages.

Getting a desired output works best when following the format of creating a system message first followed by alternating between user, then assistant responses. Each of the preset prompt types available in the drop down field include a system message except for the "Create Custom Prompt" option which allows you a lot more flexibility.

Extending Built-in Prompts

You can add more messages to the conversation thread, before getting your final response, by adding them to the Messages repeater field. These are injected at the end of the built-in seed thread and before the final prompt is sent.

This can be useful for:

  • Providing examples of the expected behaviour
  • Injecting content from your Directus instance to show the type of tone used in your project
  • Providing clarifying instructions - the Editor prompt makes use of this as Chat GPT-3.5 can get confused when given a prompt to edit that looks like a new instruction

Keep in mind that OpenAI pricing charges for both tokens received and sent. Longer seed threads will result in higher usage costs.

@directus-labs/ai-writer-operation

npm i @directus-labs/ai-writer-operation
This extension is sandboxed and can be installed through the Directus Marketplace. Learn more.
Bryant Gillespie
Bryant Gillespie
Verified
1.4.1
Works with v10.0.0+ or v11.0.0+
Updated 2 months ago
MIT License
86.4 KiB (5 files)
npm
  • Directus LogoDirectus Logo

    A composable backend to build your Headless CMS, BaaS, and more. 

  • Solutions
    • Headless CMS
    • Backend-as-a-Service
    • Product Information
    • 100+ Things to Build
  • Resources
    • Documentation
    • Guides
    • Community
    • Release Notes
  • Support
    • Issue Tracker
    • Feature Requests
    • Community Chat
    • Cloud Dashboard
  • Organization
    • About
    • Careers
    • Brand Assets
    • Contact
©2025 Monospace Inc
  • Cloud Policies
  • License
  • Terms
  • Privacy