From 9a68db8e44e3d655b94c5994f1923d7b31fa0e8c Mon Sep 17 00:00:00 2001 From: Jack Gerrits Date: Wed, 31 Jan 2024 09:06:33 -0500 Subject: [PATCH 01/15] Initial infrasctructure for notebooks page --- website/.gitignore | 5 ++ website/docs/Gallery.mdx | 3 +- website/docs/notebooks.mdx | 11 ++++ website/docusaurus.config.js | 5 +- website/src/components/GalleryPage.js | 77 +++++++++++++++---------- website/src/components/NotebookUtils.js | 23 ++++++++ 6 files changed, 90 insertions(+), 34 deletions(-) create mode 100644 website/docs/notebooks.mdx create mode 100644 website/src/components/NotebookUtils.js diff --git a/website/.gitignore b/website/.gitignore index 495a9753d172..0de69db32929 100644 --- a/website/.gitignore +++ b/website/.gitignore @@ -12,6 +12,11 @@ docs/reference docs/llm_endpoint_configuration.mdx +# These are generated files from the notebooks +docs/notebooks/*.mdx +docs/notebooks/**/*.png +docs/notebooks/*.svg + # Misc .DS_Store .env.local diff --git a/website/docs/Gallery.mdx b/website/docs/Gallery.mdx index 1b07b138152e..6a9c0975271c 100644 --- a/website/docs/Gallery.mdx +++ b/website/docs/Gallery.mdx @@ -1,4 +1,5 @@ import GalleryPage from '../src/components/GalleryPage'; +import galleryData from "../src/data/gallery.json"; # Gallery @@ -7,7 +8,7 @@ This page contains a list of demos that use AutoGen in various applications from **Contribution guide:** Built something interesting with AutoGen? Submit a PR to add it to the list! See the [Contribution Guide below](#contributing) for more details. - + ## Contributing diff --git a/website/docs/notebooks.mdx b/website/docs/notebooks.mdx new file mode 100644 index 000000000000..ec38a95bb537 --- /dev/null +++ b/website/docs/notebooks.mdx @@ -0,0 +1,11 @@ +import {findAllNotebooks} from '../src/components/NotebookUtils'; +import GalleryPage from '../src/components/GalleryPage'; + +# Notebooks + +This page contains a collection of notebooks that demonstrate how to use +AutoGen. The notebooks are tagged with the topics they cover. +For example, a notebook that demonstrates how to use function calling will +be tagged with `function call`. + + diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index b12f45fc1c48..caf77b759643 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -69,10 +69,9 @@ module.exports = { // label: 'Examples', // }, { - type: "doc", - docId: "Examples", + to: "docs/notebooks", position: "left", - label: "Examples", + label: "Notebooks", }, { label: "Resources", diff --git a/website/src/components/GalleryPage.js b/website/src/components/GalleryPage.js index 26b2bc7aa130..d24cc334fa1b 100644 --- a/website/src/components/GalleryPage.js +++ b/website/src/components/GalleryPage.js @@ -1,12 +1,11 @@ import React, { useEffect, useState, useCallback } from "react"; -import galleryData from "../data/gallery.json"; import { Card, List, Select, Typography } from "antd"; import { useLocation, useHistory } from "react-router-dom"; const { Option } = Select; const { Paragraph, Title } = Typography; -const GalleryPage = () => { +const GalleryPage = (props) => { const location = useLocation(); const history = useHistory(); @@ -28,15 +27,23 @@ const GalleryPage = () => { const TagsView = ({ tags }) => (
- {tags.map((tag, index) => ( - + {tags?.map((tag, index) => ( + + { + if (!selectedTags.includes(tag)) { + handleTagChange([...selectedTags, tag]) + } + evt.preventDefault(); + evt.stopPropagation(); + return false; + }} > {tag} ))}
); - const allTags = [...new Set(galleryData.flatMap((item) => item.tags))]; + const allTags = [...new Set(props.items.flatMap((item) => item.tags))]; const handleTagChange = (tags) => { setSelectedTags(tags); @@ -49,11 +56,38 @@ const GalleryPage = () => { const filteredData = selectedTags.length > 0 - ? galleryData.filter((item) => - selectedTags.some((tag) => item.tags.includes(tag)) - ) - : galleryData; + ? props.items.filter((item) => + selectedTags.some((tag) => item.tags.includes(tag)) + ) + : props.items; + + const defaultImageIfNoImage = props.allowDefaultImage ?? true; + console.log(defaultImageIfNoImage) + const imageFunc = (item) => { + const image = + {item.title} + ; + + const imageToUse = item.image ? image : defaultImageIfNoImage ? image : null; + return imageToUse; + } + const target = props.target ?? "_blank"; return (