smol-ai / developer

the first library to let you embed a developer agent in your own app!
https://twitter.com/SmolModels
MIT License
11.74k stars 1.03k forks source link

Running example prompt in prompt.md file generates non-working chrome extension - Error: Could not load icon 'icon16.png' specified in 'icons'. Could not load manifest. #76

Closed Hisma closed 1 year ago

Hisma commented 1 year ago

Tested several times, always with the same results.
I get no errors in the console. Here is what I run - modal run main.py --prompt prompt.md --model=gpt-4

Here is the result - `✓ Initialized. View app at https://modal.com/apps/ap-2X0ikxpFtqmLoE63zZSiah ✓ Created objects. ├── 🔨 Created generate_response. ├── 🔨 Created mount /mnt/nas/developer/main.py ├── 🔨 Created mount /mnt/nas/developer/utils.py ├── 🔨 Created mount /mnt/nas/developer/constants.py └── 🔨 Created generate_file. hi its me, 🐣the smol developer🐣! you said you wanted: a Chrome Manifest V3 extension that reads the current page, and offers a popup UI that has the page title+content and a textarea for a prompt (with a default value we specify). When the user hits submit, it sends the page title+content to the Anthropic Claude API along with the up to date prompt to summarize it. The user can modify that prompt and re-send the prompt+content to get another summary view of the content.

Important Details:

debugging notes

inside of background.js, just take the getPageContent response directly

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  if (request.action === 'storePageContent') {
    // dont access request.pageContent
    chrome.storage.local.set({ pageContent: request }, () => {
      sendResponse({ success: true });
    });
  } else if (request.action === 'getPageContent') {
    chrome.storage.local.get(['pageContent'], (result) => {
      // dont access request.pageContent
      sendResponse(result);
    });
  }
  return true;
});

inside of popup.js, Update the function calls to requestAnthropicSummary in popup.js to pass the apiKey:

chrome.storage.local.get(['apiKey'], (result) => {
  const apiKey = result.apiKey;
  requestAnthropicSummary(defaultPrompt, apiKey);
});

sendButton.addEventListener('click', () => {
  chrome.storage.local.get(['apiKey'], (result) => {
    const apiKey = result.apiKey;
    requestAnthropicSummary(userPrompt.value, apiKey);
  });
});

in popup.js, store the defaultPrompt at the top level. also, give a HTML format to the anthropic prompt

89 tokens in prompt: You are an AI developer who is trying to write a p... 1785 tokens in prompt: a Chrome Manifest V3 extension that reads the curr... [ "manifest.json", "background.js", "content_script.js", "popup.html", "popup.js", "styles.css" ] 145 tokens in prompt: You are an AI developer who is trying to write a p... 1785 tokens in prompt: a Chrome Manifest V3 extension that reads the curr... Shared dependencies:

  1. Exported variables:

    • defaultPrompt
    • defaultStyle
    • finalPrompt
  2. Data schemas:

    • storePageContent action data
    • getPageContent action data
  3. ID names of DOM elements:

    • loadingIndicator
    • userPrompt
    • stylePrompt
    • sendButton
    • content
  4. Message names:

    • storePageContent
    • getPageContent
  5. Function names:

    • requestAnthropicSummary shared_dependencies.md Shared dependencies:
  6. Exported variables:

    • defaultPrompt
    • defaultStyle
    • finalPrompt
  7. Data schemas:

    • storePageContent action data
    • getPageContent action data
  8. ID names of DOM elements:

    • loadingIndicator
    • userPrompt
    • stylePrompt
    • sendButton
    • content
  9. Message names:

    • storePageContent
    • getPageContent
  10. Function names:

    • requestAnthropicSummary 2032 tokens in prompt: You are an AI developer who is trying to write a p... 1952 tokens in prompt: We have broken up the program into per-file g... 2032 tokens in prompt: You are an AI developer who is trying to write a p... 1952 tokens in prompt: We have broken up the program into per-file g... 2032 tokens in prompt: You are an AI developer who is trying to write a p... 1954 tokens in prompt: We have broken up the program into per-file g... 2032 tokens in prompt: You are an AI developer who is trying to write a p... 1952 tokens in prompt: We have broken up the program into per-file g... 2032 tokens in prompt: You are an AI developer who is trying to write a p... 1952 tokens in prompt: We have broken up the program into per-file g... content_script.js // content_script.js

function getPageTitleAndContent() { const pageTitle = document.title; const pageContent = document.body.innerText; return { pageTitle, pageContent }; }

chrome.runtime.sendMessage( { action: 'storePageContent', ...getPageTitleAndContent() }, (response) => { if (response.success) { console.log('Page content stored successfully'); } else { console.error('Failed to store page content'); } } ); 2032 tokens in prompt: You are an AI developer who is trying to write a p... 1952 tokens in prompt: We have broken up the program into per-file g... background.js chrome.runtime.onInstalled.addListener(() => { chrome.action.onClicked.addListener((tab) => { chrome.scripting.executeScript({ target: { tabId: tab.id }, files: ['content_script.js'], }); }); });

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { if (request.action === 'storePageContent') { chrome.storage.local.set({ pageContent: request }, () => { sendResponse({ success: true }); chrome.action.setPopup({ popup: 'popup.html' }, () => { chrome.action.openPopup(); }); }); } else if (request.action === 'getPageContent') { chrome.storage.local.get(['pageContent'], (result) => { sendResponse(result); }); } return true; }); manifest.json { "manifest_version": 3, "name": "Anthropic Claude Summarizer", "version": "1.0.0", "description": "A Chrome extension that summarizes web pages using the Anthropic Claude API.", "permissions": ["activeTab", "storage"], "action": { "default_popup": "popup.html", "default_icon": { "16": "icon16.png", "48": "icon48.png", "128": "icon128.png" } }, "background": { "service_worker": "background.js" }, "content_scripts": [ { "matches": [""], "js": ["content_script.js"], "run_at": "document_idle" } ], "icons": { "16": "icon16.png", "48": "icon48.png", "128": "icon128.png" } } popup.html <!DOCTYPE html>

Anthropic Claude Summary

styles.css body { margin: 16px; min-width: 400px; min-height: 600px; }

loadingIndicator {

position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 100%; height: 10px; overflow: hidden; background-color: #f0f0f0; border-radius: 5px; }

loadingIndicator:before {

content: ""; position: absolute; top: 0; left: 0; width: 50%; height: 100%; background: linear-gradient(45deg, #f06, transparent); animation: loading 1s infinite; }

@keyframes loading { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

textarea { resize: vertical; }

sendButton {

background-color: #4CAF50; border: none; color: white; padding: 8px 16px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 4px; transition: background-color 0.3s, transform 0.3s; }

sendButton:hover {

background-color: #45a049; }

sendButton:active {

transform: translateY(2px); } popup.js document.addEventListener('DOMContentLoaded', () => { const loadingIndicator = document.getElementById('loadingIndicator'); const userPrompt = document.getElementById('userPrompt'); const stylePrompt = document.getElementById('stylePrompt'); const sendButton = document.getElementById('sendButton'); const content = document.getElementById('content');

const defaultPrompt = 'Please provide a detailed, easy to read HTML summary of the given content'; const defaultStyle = `Respond with 3-4 highlights per section with important keywords, people, numbers, and facts bolded in this HTML format:

{title here}

{section title here}

{summary of the section with important keywords, people, numbers, and facts bolded and key quotes repeated}
  • {first point}: {short explanation with important keywords, people, numbers, and facts bolded}
  • {second point}: {same as above}
  • {third point}: {same as above}

{second section here}

{summary of the section with important keywords, people, numbers, and facts bolded and key quotes repeated}

{summary of the section with important keywords, people, numbers, and facts bolded and key quotes repeated}

{third section here}

With all the words in brackets replaced by the summary of the content. sanitize non visual HTML tags with HTML entities, so