diff --git a/README.md b/README.md index 612f3dd..ac1e6fe 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,80 @@ Some neat little utilities relied upon by Regreso clients. Right now, these can - Get metadata info about websites (for prefilling destination details automatically) - AI-generate a list of practically-usable, relevant tags to describe a location based on metadata (supports provided, self-hostable AI instance URL) +## 🚀 Usage + +Let's say you wanted to use this module in your own regreso client (or something entirely different), here's how: + +- **SiteTagger** - A class used to control AI-based website tagging behaviors. + + ``` + import { SiteTagger } from '@regreso/utils' + + async function demo() { + const tagger = new SiteTagger({ + maxTags: 3, + aiInstance: 'https://ai.hackclub.com', + maxRetries: 2, + requestDelay: 1000 + }) + + const demoSites = [ + { + url: 'https://github.com/microsoft/vscode', + headline: 'Visual Studio Code', + description: 'A lightweight but powerful source code editor' + }, + { + url: 'https://css-tricks.com/snippets/css/a-guide-to-flexbox/', + headline: 'A Complete Guide to Flexbox', + description: 'CSS Flexbox layout guide with examples' + } + ] + + // Generates a specified number of tags + + const result = await tagger.generateTags(demoSites[0]) + + if (result.success) { + console.log(`tags: ${result.tags.join(', ')} in ${result.metadata?.processingTime} ms.`) + } else { + console.log(`error: ${result.error}`) + } + + const batchResults = await tagger.generateTagsBatch(demoSites) + + console.log( + batchResults + .filter(r => r.result.success) + .map(r => `${r.headline}: [${r.result.tags.join(', ')}]`) + .join('\n') + ) + } + + ``` + +- **getWebDetails** - Gets the web details scraped from meta tags of specified website's URL. Returns multiple versions if relevant (title, og:title, twitter:title to be specific) + + ``` + import { getWebDetails } from '@regreso/utils' + + const webDetailsResult = getWebDetails('fbi.gov') + + console.log({ + url: webDetailsResult.url, // appends protocol if missing + title: webDetailsResult.title[0] + ?? webDetailsResult.title[1] + ?? webDetailsResult.title[2], + description: webDetailsResult.description[0] + ?? webDetailsResult.description[1] + ?? webDetailsResult.description[2] + }) + ``` + ## ☑️ TODOs +- [x] Add site metadata scraping - [x] Add AI-tagging - [ ] Document package + - [x] Basic Usage Demo - [ ] Support scraping image metadata - diff --git a/src/ai.ts b/src/ai.ts index b6c9cd4..03c4bbf 100644 --- a/src/ai.ts +++ b/src/ai.ts @@ -233,15 +233,6 @@ export class SiteTagger { private sleep(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } - - async getTagSuggestions( - site: SiteInput, - count: number = 8, - ): Promise { - const tempTagger = new SiteTagger({ ...this.config, maxTags: count }); - const result = await tempTagger.generateTags(site); - return result.tags; - } } export default SiteTagger;