Repository: smol-ai/developer Branch: main Commit: a6747d1a6ccd Files: 48 Total size: 117.2 KB Directory structure: gitextract_dy16cnbs/ ├── .devcontainer/ │ ├── devcontainer.json │ └── dockerfile ├── .example.env ├── .gitignore ├── LICENSE ├── Makefile ├── dist/ │ └── smol_dev-0.0.3-py3-none-any.whl ├── examples/ │ └── v1_pong_game/ │ ├── ai.js │ ├── index.html │ ├── main.js │ ├── shared_deps.md │ └── style.css ├── main.py ├── prompt.md ├── pyproject.toml ├── readme.md ├── smol_dev/ │ ├── __init__.py │ ├── api.py │ ├── main.py │ ├── prompts.py │ └── utils.py └── v0/ ├── code2prompt/ │ ├── code2prompt-gpt3.md │ └── code2prompt-gpt4.md ├── code2prompt.py ├── code2prompt2code/ │ ├── background.js │ ├── content_script.js │ ├── manifest.json │ ├── popup.html │ ├── popup.js │ ├── shared_dependencies.md │ └── styles.css ├── constants.py ├── debugger.py ├── debugger_no_modal.py ├── exampleChromeExtension/ │ ├── background.js │ ├── content_script.js │ ├── manifest.json │ ├── popup.html │ ├── popup.js │ ├── prompt used for this extension.md │ ├── shared_dependencies.md │ └── styles.css ├── main.py ├── main_no_modal.py ├── readme.md ├── static/ │ └── readme.md ├── utils.py └── v0_readme.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: .devcontainer/devcontainer.json ================================================ { "name": "Python Project", // The name of your dev container setup, can be anything you choose. "dockerFile": "Dockerfile", // The path to the Dockerfile that describes your development environment. "settings": { "terminal.integrated.shell.linux": "/bin/bash", // Specifies the shell to be used in the integrated terminal in VS Code. "python.pythonPath": "/usr/local/bin/python", // Specifies the path to the Python interpreter. "python.linting.pylintEnabled": true, // Enables linting using pylint for Python files. "python.linting.enabled": true // Enables linting for Python files in general. }, "extensions": ["ms-python.python"], // Specifies VS Code extensions that should be installed in the dev container when it is created, in this case, the Microsoft Python extension. "forwardPorts": [], // Specifies any ports that should be forwarded from the dev container to the host. "postCreateCommand": "pip install -r requirements.txt" // Specifies a command or series of commands to run after the dev container is created. } ================================================ FILE: .devcontainer/dockerfile ================================================ # syntax=docker/dockerfile:1 # Specifies Dockerfile version to use. In this case, version 1. FROM python:3.9-slim-buster # Defines the base image to use for your Docker image. Here, it's the slim-buster version of the official Python 3.9 image. WORKDIR /app # Sets the working directory in the Docker container. Any command that follows in the Dockerfile will be run in this directory. COPY requirements.txt . # Copies the requirements.txt file from your project to the working directory in the Docker image. RUN pip install -r requirements.txt # Runs pip install command in your Docker image to install Python dependencies listed in your requirements.txt file. COPY . . # Copies everything else in your project (denoted by '.') to the working directory in the Docker image. ================================================ FILE: .example.env ================================================ OPENAI_API_KEY=sk-xxxxxx ================================================ FILE: .gitignore ================================================ .env env __pycache__ .vscode .idea /.idea/ venv/ # Ignore everything in the generated directory /generated/* # Don't ignore .gitkeep files in the generated directory !/generated/.gitkeep workspace ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2023 swyx Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: Makefile ================================================ .PHONY: clean build publish build: clean python -m pip install --upgrade --quiet setuptools wheel twine python3 -m build # python setup.py --quiet sdist bdist_wheel publish: build python -m twine check dist/* # python -m twine upload dist/* python3 -m twine upload dist/* clean: rm -r build dist *.egg-info || true ================================================ FILE: examples/v1_pong_game/ai.js ================================================ // Define AI's paddle speed var aiSpeed = 2; // Define AI's error rate var aiError = 0.05; /** * Function to make a decision on the direction to move the AI paddle based on the ball's position and the error factor. * @param {object} ball - The ball object * @param {object} aiPaddle - The AI paddle object */ function aiDecision(ball, aiPaddle) { // If ball is above the AI paddle and random number is greater than error rate, move the paddle up if (ball.y < aiPaddle.y && Math.random() > aiError) { aiPaddle.y -= aiSpeed; } // If ball is below the AI paddle and random number is greater than error rate, move the paddle down else if (ball.y > aiPaddle.y && Math.random() > aiError) { aiPaddle.y += aiSpeed; } } ================================================ FILE: examples/v1_pong_game/index.html ================================================ Pong Game
================================================ FILE: examples/v1_pong_game/main.js ================================================ // Define the canvas, paddles, ball and score const canvas = document.getElementById("gameArea"); const ctx = canvas.getContext("2d"); let playerPaddle = { x: 0, y: 200, width: 10, height: 100 }; let aiPaddle = { x: 390, y: 200, width: 10, height: 100 }; let ball = { x: 200, y: 200, radius: 5, dx: 2, dy: 2 }; let score = { player: 0, ai: 0 }; // Initialize the game state function startGame() { playerPaddle.y = 200; aiPaddle.y = 200; ball.x = 200; ball.y = 200; ball.dx = 2; ball.dy = 2; score.player = 0; score.ai = 0; } // Listen for mouse movement to control the player's paddle canvas.addEventListener("mousemove", playerMove); // Control the player's paddle based on mouse movement function playerMove(event) { let rect = canvas.getBoundingClientRect(); playerPaddle.y = event.clientY - rect.top - playerPaddle.height / 2; } // Control the AI paddle based on the ball's position function aiMove() { let targetY = ball.y - (aiPaddle.height - ball.radius) / 2; aiPaddle.y += (targetY - aiPaddle.y) * 0.1; } // Check for collisions between the ball and the paddles or the boundaries of the canvas function checkCollision() { // Ball and player paddle if (ball.y + ball.radius > playerPaddle.y && ball.y - ball.radius < playerPaddle.y + playerPaddle.height && ball.dx < 0) { if (ball.x - ball.radius < playerPaddle.x + playerPaddle.width) { ball.dx *= -1; increaseBallSpeed(); } } // Ball and AI paddle if (ball.y + ball.radius > aiPaddle.y && ball.y - ball.radius < aiPaddle.y + aiPaddle.height && ball.dx > 0) { if (ball.x + ball.radius > aiPaddle.x) { ball.dx *= -1; increaseBallSpeed(); } } // Ball and top or bottom if (ball.y + ball.radius > canvas.height || ball.y - ball.radius < 0) { ball.dy *= -1; } } // Update the score based on ball-paddle collisions function updateScore() { if (ball.x + ball.radius > canvas.width) { score.player++; startGame(); } else if (ball.x - ball.radius < 0) { score.ai++; startGame(); } } // Increase the ball's speed every time it bounces off a paddle function increaseBallSpeed() { ball.dx *= 1.1; ball.dy *= 1.1; } // Update the game state at every frame function updateGame() { // Move the ball ball.x += ball.dx; ball.y += ball.dy; // Move the AI paddle aiMove(); // Check for collisions checkCollision(); // Update the score updateScore(); // Render the game state drawGame(); // Schedule the next update requestAnimationFrame(updateGame); } // Render the game state function drawGame() { // Clear the canvas ctx.clearRect(0, 0, canvas.width, canvas.height); // Draw the paddles ctx.fillStyle = "yellow"; ctx.fillRect(playerPaddle.x, playerPaddle.y, playerPaddle.width, playerPaddle.height); ctx.fillRect(aiPaddle.x, aiPaddle.y, aiPaddle.width, aiPaddle.height); // Draw the ball ctx.beginPath(); ctx.arc(ball.x, ball.y, ball.radius, 0, Math.PI*2); ctx.fillStyle = "red"; ctx.fill(); // Draw the score ctx.font = "30px Arial"; ctx.fillText(score.player, 50, 50); ctx.fillText(score.ai, canvas.width - 50, 50); } // Start the game startGame(); updateGame(); ================================================ FILE: examples/v1_pong_game/shared_deps.md ================================================ Here is a breakdown of the structure of the Pong Game app: 1. **index.html**: This is the main HTML file that creates the structure of the webpage. It includes a canvas for the game area, and two div elements for the player and AI paddles. - *DOM Elements:* - `id="gameArea"` for the canvas. - `id="playerPaddle"` for the player's paddle. - `id="aiPaddle"` for the AI's paddle. 2. **style.css**: This file contains the CSS styles for the canvas and paddles. It sets the canvas to a 400x400 black square and centers it in the page. The paddles are made 100px long and yellow, and the ball small and red. 3. **main.js**: This is the main JavaScript file that controls the functionality of the game. It includes functions to control the player's paddle following the mouse, the AI paddle following the ball, collision detection between the ball and the paddles, and scoring. - *Variables*: - `playerPaddle` and `aiPaddle` objects that represent the player and AI paddles. - `ball` object represents the ball. - `score` object keeps track of the player's and AI's scores. - *Functions*: - `startGame()`: Initializes the game state. - `updateGame()`: Updates the game state at every frame, including moving the paddles and ball and checking for collisions. - `drawGame()`: Renders the game state on the canvas. - `playerMove(event)`: Controls the player's paddle based on mouse movement. - `aiMove()`: Controls the AI paddle based on the ball's position. - `checkCollision()`: Checks for collisions between the ball and the paddles or the boundaries of the canvas. - `updateScore()`: Updates the score based on ball-paddle collisions. - `increaseBallSpeed()`: Increases the ball's speed every time it bounces off a paddle. 4. **ai.js**: This file contains a simple AI algorithm to control the movement of the AI paddle. It slowly moves the paddle toward the ball at every frame, with some probability of error. - *Variables*: - `aiSpeed` determines the speed of the AI paddle. - `aiError` determines the probability of error in the AI's movement. - *Functions*: - `aiDecision()`: Makes a decision on the direction to move the AI paddle based on the ball's position and the error factor. All these files will be linked together in the `index.html` file. The JavaScript files are written in a manner that doesn't use the import/export keywords and only uses features supported by the Chrome browser to ensure compatibility. Each JavaScript function uses the DOM API to interact with the HTML elements based on their id names. ================================================ FILE: examples/v1_pong_game/style.css ================================================ /* CSS Styles for the Pong Game App */ body { display: flex; justify-content: center; align-items: center; height: 100vh; background-color: black; } #gameArea { background-color: black; height: 400px; width: 400px; position: relative; } #playerPaddle, #aiPaddle { position: absolute; background-color: yellow; width: 10px; height: 100px; } #playerPaddle { left: 0; } #aiPaddle { right: 0; } .ball { position: absolute; background-color: red; height: 10px; width: 10px; border-radius: 50%; } ================================================ FILE: main.py ================================================ import sys from smol_dev.prompts import plan, specify_file_paths, generate_code_sync from smol_dev.utils import generate_folder, write_file from smol_dev.main import main import argparse # for local testing # python main.py --prompt "a simple JavaScript/HTML/CSS/Canvas app that is a one player game of PONG..." --generate_folder_path "generated" --debug True if __name__ == "__main__": prompt = """ a simple JavaScript/HTML/CSS/Canvas app that is a one player game of PONG. The left paddle is controlled by the player, following where the mouse goes. The right paddle is controlled by a simple AI algorithm, which slowly moves the paddle toward the ball at every frame, with some probability of error. Make the canvas a 400 x 400 black square and center it in the app. Make the paddles 100px long, yellow and the ball small and red. Make sure to render the paddles and name them so they can controlled in javascript. Implement the collision detection and scoring as well. Every time the ball bouncess off a paddle, the ball should move faster. It is meant to run in Chrome browser, so dont use anything that is not supported by Chrome, and don't use the import and export keywords. """ if len(sys.argv) == 2: prompt = sys.argv[1] args = None else: parser = argparse.ArgumentParser() parser.add_argument("--prompt", type=str, help="Prompt for the app to be created.") parser.add_argument("--model", type=str, default="gpt-4-0613", help="model to use. can also use gpt-3.5-turbo-0613") parser.add_argument("--generate_folder_path", type=str, default="generated", help="Path of the folder for generated code.") parser.add_argument("--debug", type=bool, default=False, help="Enable or disable debug mode.") args = parser.parse_args() if args.prompt: prompt = args.prompt # read file from prompt if it ends in a .md filetype if len(prompt) < 100 and prompt.endswith(".md"): with open(prompt, "r") as promptfile: prompt = promptfile.read() print(prompt) if args is None: # This is in case we're just calling the main function directly with a prompt main(prompt=prompt) else: main(prompt=prompt, generate_folder_path=args.generate_folder_path, debug=args.debug, model=args.model) ================================================ FILE: prompt.md ================================================ 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. - Only when clicked: - it injects a content script `content_script.js` on the currently open tab, and accesses the title `pageTitle` and main content (innerText) `pageContent` of the currently open page (extracted via an injected content script, and sent over using a `storePageContent` action) - in the background, receives the `storePageContent` data and stores it - only once the new page content is stored, then it pops up a full height window with a minimalistic styled html popup - in the popup script - the popup should display a 10px tall rounded css animated red and white candy stripe loading indicator `loadingIndicator`, while waiting for the anthropic api to return - with the currently fetching page title and a running timer in the center showing time elapsed since call started - do not show it until the api call begins, and hide it when it ends. - retrieves the page content data using a `getPageContent` action (and the background listens for the `getPageContent` action and retrieves that data) and displays the title at the top of the popup - check extension storage for an `apiKey`, and if it isn't stored, asks for an API key to Anthropic Claude and stores it. - at the bottom of the popup, show a vertically resizable form that has: - a 2 line textarea with an id and label of `userPrompt` - `userPrompt` has a default value of ```js defaultPrompt = `Please provide a detailed, easy to read HTML summary of the given content`; ```js - a 4 line textarea with an id and label of `stylePrompt` - `stylePrompt` has a default value of ```js 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}

{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