Skip to content

DeepTeam is a framework to red team LLMs and AI agents.

3.9 KB
Raw Blame
import { siteUrl as BASE_URL } from "@/lib/shared";

export interface ArticleSchemaProps {
  title: string;
  url: string;
  description?: string;
  datePublished?: string;
  dateModified?: string;
  authors?: (string | undefined)[] | undefined;
  image?: string;
}

export interface BreadcrumbItem {
  name: string;
  url?: string;
}

export interface ProductSchemaProps {
  name: string;
  description: string;
  url: string;
  image?: string;
}

export interface Author {
  name: string;
  title: string;
  url: string;
  image_url: string;
}

export interface BlogPost {
  title: string;
  description: string;
  slug: string;
  authors: string[];
  date: string;
}

export function buildWebSiteSchema(): object {
  return {
    "@context": "https://schema.org",
    "@type": "WebSite",
    name: "DeepTeam - The LLM Red Teaming Framework",
    url: BASE_URL,
  };
}

export function buildArticleSchema({
  title,
  description,
  url,
  datePublished,
  dateModified,
  authors,
  image,
}: ArticleSchemaProps): object {
  const authorSchema =
    authors && authors.length > 0
      ? authors.map((name) => ({
          "@type": "Person",
          name: name,
        }))
      : undefined;

  return {
    "@context": "https://schema.org",
    "@type": "TechArticle",
    headline: title,
    ...(description ? { description } : {}),
    ...(image ? { image } : {}),
    ...(datePublished ? { datePublished } : {}),
    ...(dateModified ? { dateModified } : {}),
    mainEntityOfPage: {
      "@type": "WebPage",
      "@id": `${BASE_URL}${url}`,
    },
    ...(authorSchema
      ? { author: authorSchema.length === 1 ? authorSchema[0] : authorSchema }
      : {}),
    publisher: {
      "@type": "Organization",
      name: "Confident AI Inc.",
      url: BASE_URL,
      logo: {
        "@type": "ImageObject",
        url: `${BASE_URL}/icons/deepteam.svg`,
      },
    },
  };
}

export function buildBreadcrumbSchema(trail: BreadcrumbItem[]): object | null {
  if (!trail || trail.length === 0) return null;

  const items: object[] = [
    { "@type": "ListItem", position: 1, name: "Home", item: BASE_URL },
  ];

  let currentPosition = 2;

  trail.forEach((crumb, i) => {
    const isLast = i === trail.length - 1;
    let itemUrl = crumb.url;

    if (itemUrl) {
      if (itemUrl.startsWith("/")) {
        itemUrl = `${BASE_URL}${itemUrl}`;
      } else if (!itemUrl.startsWith("http")) {
        itemUrl = `${BASE_URL}/${itemUrl}`;
      }
    }

    if (itemUrl || isLast) {
      items.push({
        "@type": "ListItem",
        position: currentPosition,
        name: crumb.name,
        ...(!isLast && itemUrl ? { item: itemUrl } : {}),
      });
      currentPosition++;
    }
  });

  return {
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    itemListElement: items,
  };
}

export interface FAQItem {
  question: string;
  answer: string;
}

export function buildFAQPageSchema(qas: FAQItem[]): object | null {
  if (!qas || qas.length === 0) return null;

  return {
    "@context": "https://schema.org",
    "@type": "FAQPage",
    mainEntity: qas.map(({ question, answer }) => ({
      "@type": "Question",
      name: question,
      acceptedAnswer: {
        "@type": "Answer",
        text: answer,
      },
    })),
  };
}

export function buildBlogHomeSchema(posts: BlogPost[]): object {
  return {
    "@context": "https://schema.org",
    "@type": "Blog",
    name: "DeepTeam LLM Red Teaming Blog",
    description:
      "Deep dives into LLM red teaming, jailbreaks, adversarial attacks, and AI safety.",
    url: `${BASE_URL}/blog`,
    publisher: {
      "@type": "Organization",
      name: "Confident AI Inc.",
      logo: {
        "@type": "ImageObject",
        url: `${BASE_URL}/icons/deepteam.svg`,
      },
    },
    blogPost: posts.map((post) => ({
      "@type": "BlogPosting",
      headline: post.title,
      url: `${BASE_URL}/blog/${post.slug}`,
      datePublished: post.date,
      description: post.description,
    })),
  };
}