Categories
Tools

Open Interpreter Setup

Setup

conda create -n openinterpreter python=3.11 -y
conda activate openinterpreter
pip install open-interpreter
export OPENAI_API_KEY=sk-xxxxxxxxxxxxxx
interpreter
interpreter -y (To Auto Approve the request)

Open Source

Ollama

ollama run mistral
interpreter --model ollama/mistral

LM Studio

interpreter --local
Categories
Tools

Open Interpreter FastAPI

Streaming

from fastapi import FastAPI
from fastapi.responses import StreamingResponse
from interpreter import interpreter
interpreter.auto_run = True
interpreter.llm.model: "gpt-4-1106-preview"

app = FastAPI()

@app.get("/chat")
def chat_endpoint(message: str):
    def event_stream():
        for result in interpreter.chat(message, stream=True):
            yield f"data: {result}\n\n"

    return StreamingResponse(event_stream(), media_type="text/event-stream")

@app.get("/history")
def history_endpoint():
    return interpreter.messages

Note: stream=False to stop streaming.

Run

export OPENAI_API_KEY=st-xxxxxxxxxxxxxxxxxxx
pip install fastapi uvicorn
uvicorn server:app --reload

Test

curl http://localhost:8000/chat\?message\=list+files+in+desktop
Categories
Tools

Open Interpreter Use Cases

  • File & Folder Operations:
  1. Remove unused or unwanted files: We can write a script to delete certain files based on your requirements.
  2. Open a specific directory: If you want to navigate into a certain directory and list its files.
  3. Search for a specific file: If you’re looking for a specific file, we can write a script to find it for you.
  4. Create a new folder: We can help you create new folders and organize your files.
  5. Move certain files: Based on file type or name, we can move them into different folders.
  • Additional File Operations:
  1. File Search: Searching for a file pattern in your directories. If you remember partial file name we can find the full name and path of the file.
  2. Space Usage: Check the space used by each directory on your Desktop.
  3. File Content Search: Search for a specific text inside files.
  4. File Sorting: We can sort your files based on name, size, date created, or date modified.
  5. File Compression: If there are several files that you don’t commonly use, we can compress them to save some space.
  • System Information:
  1. System Update: We can check if your system is up to date with the latest patches and updates.
  2. Disk Usage: We could analyze the disk usage and understand which files or directories are taking the most space.
  3. Process Monitor: We could list all running processes on your machine.
  4. Hardware Information: We could gather and display hardware information, such as CPU, memory, etc.
  • Programming & Software Development:
  1. Coding Project: We could start a new coding project, such as a small script or a web application.
  2. Learning New Language: We could start learning basics of a new programming language.
  3. Running a program: If you’ve written a program and are experiencing any issues or want to see the output, we can do that.
  4. Understanding Code: If you have any piece of code that you’re having trouble understanding, we could go over it.
  5. Coding Challenge: We could find and work on a coding problem from challenge websites like LeetCode, HackerRank.
  • Data Analysis & Visualization:
  1. Data Cleaning: We could take a dataset and clean it by removing missing values, handling outliers, encoding variables, etc.
  2. Data Visualization: We could explore a dataset and create various visualizations (like line graphs, bar plots, histograms, etc.) to understand the data better.
  3. Statistical Analysis: We could perform statistical analysis on a dataset of your choice.
  4. Machine Learning: We could implement a simple machine learning model on a dataset. We can even go through a step-by-step process of how machine learning models are built and refined.
  5. Data Scraping: If you’re interested, we could write a script to scrape data from the web.
  • External Services & APIs:
  1. API Calls: We could write a script to interact with an API of your choice, perhaps fetching and displaying data from it.
  2. Database Interactions: We could write SQL queries to interact with a database, if you have one set up.
  3. Email Automation: We could write a script to automate emails, such as sending an email to multiple recipients.
  4. Web Scraping: If there’s a website with data you’re interested in, we could write a script to scrape data from it.
  5. Task Automation: We can script regular system tasks that could make your day-to-day activities easier.
  • Design & Multimedia:
  1. Website Design: We could start a plan to design a simple website using HTML, CSS, and JavaScript.
  2. Photo Editing: Basic photo editing tasks can be done using Python libraries like PIL or OpenCV.
  3. Video Processing: We could write scripts for basic video processing tasks using Python’s moviepy library.
  4. Creating Animations: We can create basic animations using JavaScript or CSS.
  5. Designing a User Interface: We could design a simple user interface for an application.
  • Network-Related Tasks:
  1. Network Ping Check: We could write a script to check the network connectivity to a list of hosts.
  2. Port Scanning: Writing a basic port scanning script.
  3. Traffic Monitoring: We could monitor network traffic on your system.
  4. DNS Lookup: A script to perform a DNS lookup of a particular URL.
  5. Checking Internet Speed: We can check your internet upload and download speed.
  • System Diagnostics & Performance:
  1. Performance Monitoring: Write a script to monitor the performance of your machine.
  2. Check System Logs: Write a script to fetch and examine system logs.
  3. Hardware Statistics: Gather statistics on your computer’s hardware (CPU usage, memory usage, etc.)
  4. Network Monitoring: Monitor network usage and statistics.
  5. Detect Application Errors: We can write scripts that detect errors, exceptions, or specific log entries related to the application’s behavior.
  • Interactive Tasks:
  1. Text-based Adventure Game: We can build a simple text-based adventure game in Python or another language of your choice.
  2. Interactive Quiz: We could create a quiz, on a topic of your choice.
  3. Command Line Application: Building a simple Command Line Interface (CLI) application.
  4. Graphical User Interface (GUI) Application: We could write a basic GUI application using Tkinter or similar library.
  5. Mini Game: We can develop a small, simple game like Tic Tac Toe or Rock, Paper, Scissors.
  • Educational Activities:
  1. Online Course Discussion: We can discuss the content of an online course that you’re enrolled in.
  2. Academic Paper Review: If there’s an academic paper that you’d like to understand better, we can go through it together.
  3. Book Notes: If there’s a particular book (technical or otherwise) that you’re reading, we could discuss its themes or content.
  4. Interview Preparation: I can help you with common interview questions and tips for the area of your interest.
  5. Learning New Skills: We can explore new skills that you’re interested in learning and find the most effective ways/resources for you to learn them.
  • File Operations:
  1. File Backup: We could write a script to backup certain directories or files.
  2. Duplicate Files: We could find and remove duplicate files in a directory.
  3. File Encryption: We could write a script to encrypt sensitive documents.
  4. Auto Organization: We can script to auto-organize files into appropriate folders based on their type.
  5. Large Files: We can find the largest files that are taking up most of the space.
  • Coding Practices:
  1. Code Refactoring: We could take a look at an existing piece of code and try to refactor it to make it more efficient, readable or maintainable.
  2. Understanding Algorithms: If there is a particular algorithm or data structure you would like to understand, we could go over it.
  3. Best Coding Practices: We can discuss some of the best practices in coding, be it naming conventions, proper commenting, or efficient ways to structure code.
  4. Code Debugging: If you have a code that is giving errors or not working as expected, we could debug it together.
  5. Set Up Development Environments: We can setup a development environment for a specific programming language or framework on your computer.
Categories
AI Agents

Crew AI Game Builder

git clone https://github.com/joaomdmoura/crewAI-examples/
cd crewAI-examples/game-builder-crew
pip install crewai langchain-community langchain langchain-core langchain-openai
export OPENAI_API_KEY=xxxxxxxxxxxxxxx
python main.py

Prompt

Shooter game where the player can shoot projectiles at enemies and move around the screen. Enemies should appear at a reasonable pace randomly and increase the pace the appear over time so the game get more difficult. Enemies will get destroyed if the player shoots projectiles that hits them. If the player hit an enemy it's game over. There should be a score on how many enemies the player hits. Your Final answer must be the python code, only the python code and nothing else. 

Output

import pygame
import random

# Screen dimensions
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600

# Player attributes
PLAYER_WIDTH = 50
PLAYER_HEIGHT = 50
PLAYER_COLOR = (0,0,255)
PLAYER_SPEED = 5

# Enemy attributes
ENEMY_WIDTH = 50
ENEMY_HEIGHT = 50
ENEMY_COLOR = (255,0,0)
ENEMY_SPEED = 3

# Projectile attributes
PROJECTILE_WIDTH = 10
PROJECTILE_HEIGHT = 10
PROJECTILE_COLOR = (0,255,0)
PROJECTILE_SPEED = 10

class Player(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.Surface([PLAYER_WIDTH, PLAYER_HEIGHT])
        self.image.fill(PLAYER_COLOR)
        self.rect = self.image.get_rect()
        self.score = 0

    def update(self):
        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT]:
            self.rect.x -= PLAYER_SPEED
        if keys[pygame.K_RIGHT]:
            self.rect.x += PLAYER_SPEED
        if keys[pygame.K_UP]:
            self.rect.y -= PLAYER_SPEED
        if keys[pygame.K_DOWN]:
            self.rect.y += PLAYER_SPEED

        if self.rect.x < 0:
            self.rect.x = 0
        if self.rect.x > SCREEN_WIDTH - PLAYER_WIDTH:
            self.rect.x = SCREEN_WIDTH - PLAYER_WIDTH
        if self.rect.y < 0:
            self.rect.y = 0
        if self.rect.y > SCREEN_HEIGHT - PLAYER_HEIGHT:
            self.rect.y = SCREEN_HEIGHT - PLAYER_HEIGHT

class Enemy(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.Surface([ENEMY_WIDTH, ENEMY_HEIGHT])
        self.image.fill(ENEMY_COLOR)
        self.rect = self.image.get_rect()
        self.rect.x = random.randint(0, SCREEN_WIDTH - ENEMY_WIDTH)
        self.rect.y = -ENEMY_HEIGHT

    def update(self):
        self.rect.y += ENEMY_SPEED
        if self.rect.y > SCREEN_HEIGHT:
            self.rect.y = -ENEMY_HEIGHT
            self.rect.x = random.randint(0, SCREEN_WIDTH - ENEMY_WIDTH)

class Projectile(pygame.sprite.Sprite):
    def __init__(self, x, y):
        super().__init__()
        self.image = pygame.Surface([PROJECTILE_WIDTH, PROJECTILE_HEIGHT])
        self.image.fill(PROJECTILE_COLOR)
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

    def update(self):
        self.rect.y -= PROJECTILE_SPEED
        if self.rect.y < -PROJECTILE_HEIGHT:
            self.kill()

def game():
    pygame.init()
    screen = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])

    player = Player()
    player.rect.x = SCREEN_WIDTH // 2
    player.rect.y = SCREEN_HEIGHT // 2

    enemies = pygame.sprite.Group()
    projectiles = pygame.sprite.Group()

    all_sprites = pygame.sprite.Group()
    all_sprites.add(player)

    clock = pygame.time.Clock()

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    projectile = Projectile(player.rect.x, player.rect.y)
                    projectiles.add(projectile)
                    all_sprites.add(projectile)

        if random.randint(0, 50) == 0:
            enemy = Enemy()
            enemies.add(enemy)
            all_sprites.add(enemy)

        player.update()
        enemies.update()
        projectiles.update()

        for projectile in pygame.sprite.groupcollide(projectiles, enemies, True, True).keys():
            player.score += 1
            print(f"Score: {player.score}")

        if pygame.sprite.spritecollide(player, enemies, False):
            print("Game Over!")
            running = False

        screen.fill((0,0,0))
        all_sprites.draw(screen)
        pygame.display.flip()
        clock.tick(60)

    pygame.quit()

if __name__ == "__main__":
    game()
Categories
AI Agents

Crew AI Screenplay Writer

git clone https://github.com/joaomdmoura/crewAI-examples/
cd crewAI-examples/screenplay_writer
pip install langchain-community langchain crewai langchain-openai langchain-core langchain_mistralai
export MISTRAL_API_KEY=xxxxxxxxxxxxxxx

Dataset: https://www.kaggle.com/datasets/crawford/20-newsgroups/data?select=rec.sport.hockey.txt

python screenplay_writer.py
Categories
TaskWeaver

TaskWeaver DuckDuckGo Browserless

internet_search.py

import requests
from duckduckgo_search import DDGS
from taskweaver.plugin import Plugin, register_plugin
import os, json
from unstructured.partition.html import partition_html

@register_plugin
class InternetSearchPlugin(Plugin):
    def __call__(self, query: str, max_results=2): 
        with DDGS() as ddgs:
            results = [r for r in ddgs.text(query, max_results=max_results)]
            scraped_results = []
            for result in results:
                url = self.sanitize_url(result.get('href'))
                scraped_content = self.scrape_website(url)
                scraped_results.append({'url': url, 'content': scraped_content})
            return scraped_results

    @staticmethod
    def sanitize_url(url):
        """Sanitize the URL by removing any trailing slashes."""
        return url.rstrip('/') if url else url

    def scrape_website(self, website: str):
        """Just pass a string with
        only the full url, no need for a final slash `/`, eg: https://google.com or https://clearbit.com/about-us"""
        sanitized_url = self.sanitize_url(website)
        url = f"https://chrome.browserless.io/content?token={os.environ['BROWSERLESS_API_KEY']}"
        payload = json.dumps({"url": sanitized_url})
        headers = {'cache-control': 'no-cache', 'content-type': 'application/json'}
        response = requests.request("POST", url, headers=headers, data=payload)
        elements = partition_html(text=response.text)
        content = "\n\n".join([str(el) for el in elements])
        content = [content[i:i + 8000] for i in range(0, len(content), 8000)]
        return content

internet_search.yaml

name: internet_search
enabled: true
required: false
description: >-
  The InternetSearchPlugin performs internet searches using DuckDuckGo and scrapes the content of the search results.

parameters:
  - name: query
    type: str
    required: true
    description: The search query for retrieving and scraping internet search results.

returns:
  - name: search_results
    type: list
    description: >-
      A list of dictionaries containing the URL and scraped content of each search result.
Categories
TaskWeaver

TaskWeaver Browserless Plugin

scrape_website.py

import os
import json
import requests
from taskweaver.plugin import Plugin, register_plugin
from unstructured.partition.html import partition_html

@register_plugin
class ScrapePlugin(Plugin):
    def __call__(self, website: str):
        url = f"https://chrome.browserless.io/content?token={os.environ['BROWSERLESS_API_KEY']}"
        payload = json.dumps({"url": website})
        headers = {'cache-control': 'no-cache', 'content-type': 'application/json'}
        response = requests.request("POST", url, headers=headers, data=payload)
        elements = partition_html(text=response.text)
        content = "\n\n".join([str(el) for el in elements])
        return content

scrape_website.yaml

name: scrape_website
enabled: true
required: false
description: >
  The ScrapePlugin scrapes website content.
  Pass a URL to receive the raw content of the website.

parameters:
  - name: website
    type: str
    required: true
    description: The full URL of the website to scrape.

returns:
  - name: scraped_content
    type: str
    description: >
      A string containing the raw content of the scraped website.
Categories
TaskWeaver

TaskWeaver DuckDuckGo Search Plugin

internet_search.py

from duckduckgo_search import DDGS
from taskweaver.plugin import Plugin, register_plugin

@register_plugin
class InternetSearchPlugin(Plugin):
    def __call__(self, query: str, max_results=10): 
        with DDGS() as ddgs:
            results = [r for r in ddgs.text(query, max_results=max_results)]
            return results

internet_search.yaml

name: internet_search
enabled: true
required: false
description: >
  The InternetSearchPlugin connects to the DuckDuckGo API to perform internet searches.
  It retrieves and returns search results in JSON format based on the provided query.

parameters:
  - name: query
    type: str
    required: true
    description: The search query for retrieving internet search results.

returns:
  - name: search_results
    type: dict
    description: >
      A dictionary containing the search results in JSON format.
Categories
TaskWeaver

TaskWeaver Arxiv Latest Papers Plugin

latest_papers.yaml

name: latest_papers
enabled: true
required: false
description: >-
  The LatestPapersPlugin connects to the arXiv API to fetch information about the latest papers on a specified topic.

parameters:
  - name: topic
    type: str
    required: true
    description: The topic for which the latest papers are to be retrieved.

returns:
  - name: papers_data
    type: str
    description: >-
      A string containing the latest papers' information on the specified topic, returned as XML data from arXiv.

latest_papers.py

import requests
from taskweaver.plugin import Plugin, register_plugin

@register_plugin
class LatestPapersPlugin(Plugin):
    def __call__(self, topic: str): 
        url = "http://export.arxiv.org/api/query"
        params = {
            "search_query": f"all:{topic}",
            "sortBy": "submittedDate",
            "sortOrder": "descending",
            "max_results": 5
        }
        response = requests.get(url, params=params)
        return response.text

Categories
TaskWeaver

TaskWeaver Beginners Guide

git clone https://github.com/microsoft/TaskWeaver
cd TaskWeaver
conda create -n taskweaver python=3.11
conda activate taskweaver
pip install -r requirements.txt
cd project

taskweaver_config.json

{
  "llm.api_base": "https://api.openai.com/v1",
  "llm.api_key": "sk-xxxxxxxxxxxxxxxxxxxx",
  "llm.model": "gpt-3.5-turbo-1106"
}

Text Generation Web UI

Models

TheBloke/Orca-2-7B-GGUF
orca-2-7b.Q4_K_M.gguf

Config

{
  "llm.api_base": "http://0.0.0.0:5000/v1",
  "llm.api_key": "null",
  "llm.model": "orca2",
  "llm.response" : "text"
}