Skip to content

Commit

Permalink
feat: book library compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
pkarw committed Dec 9, 2024
1 parent 926e567 commit 9c77c8c
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 0 deletions.
102 changes: 102 additions & 0 deletions example/assets/book_library_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book Library</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
width: 80%;
margin: auto;
overflow: hidden;
}
header {
background: #333;
color: #fff;
padding-top: 30px;
min-height: 70px;
border-bottom: #77aaff 3px solid;
}
header a {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header ul {
padding: 0;
list-style: none;
}
header li {
float: left;
display: inline;
padding: 0 20px 0 20px;
}
header #branding {
float: left;
}
header #branding h1 {
margin: 0;
}
header nav {
float: right;
margin-top: 10px;
}
.book-list {
margin: 20px 0;
padding: 20px;
background: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.book-list h2 {
margin-top: 0;
}
.book-item {
border-bottom: 1px solid #ccc;
padding: 10px 0;
}
.book-item:last-child {
border-bottom: none;
}
</style>
</head>
<body>
<header>
<div class="container">
<div id="branding">
<h1>Book Library</h1>
</div>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</div>
</header>
<div class="container">
<div class="book-list">
<h2>Book List</h2>
<div class="book-item">
<h3>Book Title 1</h3>
<p>Author: Author Name 1</p>
<p>Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="book-item">
<h3>Book Title 2</h3>
<p>Author: Author Name 2</p>
<p>Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<!-- Add more book items as needed -->
</div>
</div>
</body>
</html>
Binary file added example/assets/photo-library.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions example/src/library_photo_to_website.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { agent } from '@dead-simple-ai-agent/framework/agent'
import { teamwork } from '@dead-simple-ai-agent/framework/teamwork'
import { logger } from '@dead-simple-ai-agent/framework/telemetry'
import { solution, workflow } from '@dead-simple-ai-agent/framework/workflow'
import { visionTool } from '@dead-simple-ai-agent/tools/vision'
import path from 'path'

import { listFiles, readFile, saveFile } from './tools/fsTools.js'

const librarian = agent({
role: 'Librarian',
description: `
You are skilled at scanning and identifying books in the library.
You look at the book library and automatically list all the books including
Title and author saving the result to a JSON file.
`,
tools: {
visionTool,
saveFile: saveFile({
workingDir: path.resolve(__dirname, '../assets/'),
}),
},
})

const webmaster = agent({
role: 'HTML Webmaster',
description: `
You are skilled at creating HTML pages.
You can create a simple HTML page with the list of items (books etc)
from the JSON database.
You are good at finding and using templates for creating HTML pages.
You are scanning the folder looking for assets and then bunding it all together.
`,
tools: {
saveFile: saveFile({
workingDir: path.resolve(__dirname, '../assets/'),
}),
readFile: readFile({
workingDir: path.resolve(__dirname, '../assets/'),
}),
listFiles: listFiles({
workingDir: path.resolve(__dirname, '../assets/'),
}),
},
})

const imagePath = path.resolve(__dirname, '../assets/photo-library.jpg')
const bookLibraryWorkflow = workflow({
members: [librarian, webmaster],
description: `
Analyze the photo located in '${imagePath}' and list ALL the books.
Your working directory is: '${path.resolve(__dirname, '../assets/')}'.
Use absolute paths for tool calls - within this directory.
There is about 10 books in the photo.
Create a JSON database with the list of books and save it to file.
Create a simple HTML page based on a *.html template found in the directory.
Save the result to HTML file.
Important information:
- a HTML template is somewhere in the folder '.'
- the photo of books is located in the './assets/photo-library
`,
output: `
HTML page saved under 'library.html' with the list of books from the library.
`,
snapshot: logger,
})

const result = await teamwork(bookLibraryWorkflow)

console.log(solution(result))

0 comments on commit 9c77c8c

Please sign in to comment.