Skip to content

Instantly share code, notes, and snippets.

View ColeMurray's full-sized avatar

Cole Murray ColeMurray

View GitHub Profile
@ColeMurray
ColeMurray / basic-completion-decorator.py
Created December 10, 2024 06:37
A basic openai completion decorator with structured outputs
import functools
from typing import Type, TypeVar, Callable, Any
from pydantic import BaseModel
from openai import OpenAI
T = TypeVar('T', bound=BaseModel)
def openai_call(_model: str, response_model: Type[T]) -> Callable:
"""
Decorator that handles OpenAI API calls using structured output parsing.
@ColeMurray
ColeMurray / video-transcriber.py
Last active December 2, 2024 05:24
Video Transcription with Deepgram
import os
from pathlib import Path
from datetime import datetime
import logging
from typing import Optional
from dotenv import load_dotenv
from moviepy.editor import VideoFileClip
import httpx
from deepgram import (
DeepgramClient,
@ColeMurray
ColeMurray / crawler.js
Created November 18, 2024 02:12
script for crawling a webpage and following links
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const fs = require('fs').promises;
const path = require('path');
const { URL } = require('url');
const crypto = require('crypto');
const argparse = require('argparse');
puppeteer.use(StealthPlugin());
@ColeMurray
ColeMurray / rateLimiter.ts
Created October 31, 2024 19:57
A rate limiter made with Dynamodb
// 1. Interface Definition
interface RateLimitOptions {
identifier: string; // e.g., IP address or user ID
points: number; // max number of requests
duration: number; // time window in seconds
}
// 2. Core Rate Limit Check Function
export const checkRateLimit = async ({
identifier,
@ColeMurray
ColeMurray / calculator.html
Created October 13, 2024 03:34
AI Chatbot Cost Calculator Using Deepgram and Twilio
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Chatbot Cost Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
@ColeMurray
ColeMurray / basic_text_to_sql_engine.py
Created October 10, 2024 00:08
A basic text to SQL implementation using LLMs. OpenAI, SQL
import openai
from sqlalchemy import create_engine, inspect
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy import text
import re
import json
class LLMSQLQueryEngine:
def __init__(self, db_path):
self.engine = create_engine(f'sqlite:///{db_path}')
@ColeMurray
ColeMurray / copy-files-to-clipboard.sh
Created September 26, 2024 17:41
Script for copying files in a directory into clipboard
#!/bin/bash
# Check for required arguments
if [ $# -lt 2 ]; then
echo "Usage: $0 <directory> <delimiter> [--include=<pattern>] [--exclude=<pattern>]"
exit 1
fi
# Assign the first argument as the directory
DIRECTORY=$1
@ColeMurray
ColeMurray / open-hands-demo-faiss-server.py
Created September 8, 2024 01:22
Example using OpenHands to create a vector database server
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import List, Optional, Dict
import faiss
import numpy as np
import os
app = FastAPI()
@ColeMurray
ColeMurray / prompt_caching_conversation_demo.py
Created September 5, 2024 06:50
Demo testing of anthropic's prompt caching for conversations
import asyncio
import aiohttp
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
API_KEY = os.getenv("ANTHROPIC_API_KEY")
API_URL = "https://api.anthropic.com/v1/messages"
@ColeMurray
ColeMurray / groq-transcribe.py
Created September 3, 2024 22:36
Transcription of video using groq
import os
import subprocess
from pydub import AudioSegment
from groq import Groq
import argparse
# Initialize the Groq client
client = Groq()
def convert_video_to_audio(video_path, audio_path):