Programmatic content generation

Cortex Click makes it easy to create high quality blog posts, tutorials, developer documentation, and SEO-optimized landing pages. With the SDK you can do all of this programmatically.

Content created programmatically can be viewed and refined from the app. Working with an SEO firm usually involves getting a spreadsheet of keywords or blog post titles every month. The SDK can speed up the process of turning these monthly goals into drafts, which can be further refined and manually edited prior to publishing.

Generate content

The Cortex class exposes convenient methods for starting a streaming or synchornous content generation:

Streaming

To stream content generation responses, set the stream parameter to true:

const cortex = client.getCortex("blog-writer");
 
const title = "Building a Support Slackbot for your Online Community";
const prompt = `Write a blog post about using the Cortex Click SDK to index developer documentation, 
into a catalog, create a cortex that consumes it, and finally auto-repsonds to community questions in slack with answers.
 
This post is designed to drive SEO on the keyword "AI Support Slackbots". 
SEO optimize this post by including keyword variations, long-tail keywords, and semantically related terms in the post content. 
`;
 
let contentResult = await cortex.generateContent({
  title,
  prompt,
  stream: true,
});
 
contentResult.contentStream.on("data", (data) => {
  process.stdout.write(data);
});
 
let content = await contentResult.content;

Synchronous

const cortex = client.getCortex("blog-writer");
 
const title = "Building a Support Slackbot for your Online Community";
const prompt = `Write a blog post about using the Cortex Click SDK to index developer documentation,
into a catalog, create a cortex that consumes it, and finally auto-repsonds to community questions in slack with answers.
 
This post is designed to drive SEO on the keyword "AI Support Slackbots".
SEO optimize this post by including keyword variations, long-tail keywords, and semantically related terms in the post content.
`;
 
let blogPost = await cortex.generateContent({
  title,
  prompt,
});
 
fs.writeFileSync("./building-ai-slackbots.md", blogPost.content);

Refine content

Content can also be refined programmatically. This can be useful for making bulk edits across your entire content base, for example rebranding campaigns or refreshing blog post links after a major product release.

Streaming

To stream content refinement responses, set the stream parameter to true:

const contentId = "...";
const content = await client.getContent(contentId);
 
const refinedResult = await content.refine({
    prompt: "Rebrand all usage of 'AI-native CMS' to 'Intelligent Content Engine',
    stream: true,
});
 
refinedResult.contentStream.on("data", (data) => {
    fullRefinedContent += data.toString();
});
 
const refinedContent = await refinedResult.content;

Synchronous

const contentId = "...";
const content = await client.getContent(contentId);
 
const refinedContent = await content.refine({
    prompt: "Rebrand all usage of 'AI-native CMS' to 'Intelligent Content Engine',
});
 
console.log(refinedContent.title);
console.log(refinedContent.content);

Edit content

Programmatically edit the title or contents of a piece of content:

const contentId = "...";
const content = await client.getContent(contentId);
 
const CTA = "Contact us to get started today!".
 
const updatedContent = content.content + `\n${CTA}`;
 
await content.edit({ title: content.title, content: updatedContent });

Get content

Retrieve a piece of content by id:

const contentId = "...";
const content = await client.getContent(contentId);
 
console.log(content.title);
console.log(content.content);

Versioning

All content is versioned. Each generation, refinement, and edit creates a new content version.

Get by version

The getContent method returns the latest version by default. Retrieve a specific version by setting the optional version parameter:

// get initial version (versions start at 0)
const version = 0;
const contentId = "...";
 
const initialContent = client.getContent(contentId, version);
console.log(initialContent.content);

Revert to a previous version

Content can be reverted to a previous version. Mechanically, this is done by creating a new version and rolling forward so that the entire content version history is maintained:

const contentId = "...";
const content = await client.getContent(contentId);
 
const revertedVersion = 0;
await content.revert(revertedVersion);

List content

Basic usage

const contentPage = await client.listContent();
 
for (const listResult of contentPage.content) {
  console.log(listResult.id, listResult.title);
  const content = await listResult.Content();
}
 
const nextPage = await contentPage.nextPage();

Filter by user

Filter content by the user that created it. The userEmail field corresponds to the email address associated with the user's Cortex Click account:

const contentPage = await client.listContent({ userEmail: "use@example.com" });

Filter by review status

Filtering content by review status is useful for automated publication workflows, such as rendering markdown files to a directory as a part of a build step.

const contentPage = await client.listContent({
  status: ContentStatus.Published,
});

Filter by cortex

Filter all content created by a particular cortex:

const contentPage = await client.listContent({ cortexName: "blog-writer" });

[Status & publishing]

Content has a status field to keep track of stages of the review workflow: DRAFT, IN_REVIEW, APPROVED, PUBLISHED.

Content is automatically created in DRAFT status, and the status can be edited via the app or the SDK:

const contentId = "...";
const content = await client.getContent(contentId);
 
console.log(content.status);
 
// set the status to approved
await content.setStatus(ContentStatus.Approved);
 
// publish a piece of content
await content.publish();
 
// unpublish a piece of content
await content.unpublish();

The publication guide has more details about programmatic publishing workflows with the SDK.