Skip to content

Instantly share code, notes, and snippets.

View jeffmylife's full-sized avatar
🌊
building

Jeffrey Lemoine jeffmylife

🌊
building
View GitHub Profile
@jeffmylife
jeffmylife / langchain-get-and-set-history-with-tools.md
Created January 17, 2025 20:02
LangChain with Tools and Chat History Guide

LangChain with Tools and Chat History: A Guide

Welcome to this guide on using LangChain with tools and chat history management. This guide will explain how to set up and use tools with LangChain, manage chat history, and handle tool interactions within your conversation flow.

Table of Contents

  1. Overview
  2. Setting Up Your Environment
  3. Tools Overview
  4. Handling Chat History
  5. Message Flow with Tools
@jeffmylife
jeffmylife / compare_llm_latency.py
Created January 2, 2025 21:13
Latency comparison command line tool between LLM's
import argparse
import json
import os
import statistics
import time
from statistics import mean, stdev
from typing import List, Dict
import plotext as plt
from litellm import completion
@jeffmylife
jeffmylife / desc.md
Last active December 17, 2024 03:46
Convert natural language dates and time expressions (like "next Tuesday", "in 2 weeks", "next summer") into Python datetime objects using Claude/LLM. Parse relative dates, fuzzy time expressions, and human language into structured timestamps.

Natural Language Time Parser using LLM

A Python utility that converts natural language time expressions into structured datetime objects using LLMs. Perfect for parsing user inputs like "next Tuesday", "in a few months", or "sometime next summer".

Features:

  • Converts natural language to precise dates
  • Handles relative time expressions
  • Season awareness
  • Configurable word translations (e.g., "few" = 3-4, "several" = 5-6)
  • Returns structured output with confidence indicators
@jeffmylife
jeffmylife / equity_sampler.py
Created January 4, 2024 21:20
Sampling without replacement to acheive the most balanced representation across skewed distributions
import pandas as pd
def sample_dataframe(df, date_column, N):
"""
Samples a pandas DataFrame to achieve a balanced representation across different date groups.
This function ensures that smaller date groups (those with counts less than an average size)
are fully represented in the sample. Larger date groups are sampled uniformly to contribute
towards a total sample size of N. If the initial sampling process results in a total sample size
@jeffmylife
jeffmylife / Makefile
Created May 20, 2023 23:14
Makefile with yaml configuration for AWS Batch Job project. Defines variables in Makefile based on a target's dependencies.
.phony: all
all: push
# configuration setup
PROJECT_FILE_NAME=project.yml
CONFIG := python3 -c "import yaml; import json; from pathlib import Path; print(json.dumps(yaml.safe_load(Path(\"$(PROJECT_FILE_NAME)\").read_text())))"
OS := $(shell python3 -c "import platform; print(platform.system())")
# defaults
@jeffmylife
jeffmylife / async_download_images.py
Last active May 12, 2023 19:28
Async GET request for images using aiohttp
import re
import asyncio
from io import BytesIO
import time
from pathlib import Path
from PIL import Image
import aiohttp
import requests
@jeffmylife
jeffmylife / autodockvina_steps.sh
Last active June 28, 2021 17:51
Getting autodock vina to work in MacOS 11 Big Sur
## NOTE: I wouldn't run this script by itself.
# install vina
tar xzvf autodock_vina_1_1_2_mac_64bit.tar.gz
cd autodock_vina_1_1_2_mac_catalina_64bit
./installer.sh
mv bin/vina /usr/local/bin
# test
@jeffmylife
jeffmylife / aliasinate.py
Created March 16, 2021 23:51
Standardizes duplicate id's with different equivalent names, aka aliases, to an easier object.
import itertools
from operator import itemgetter
def aliasinate(lst, sep=';') -> dict:
'''
Parameters
----------
lst : list
List of strings containing aliases in any order or combination.
@jeffmylife
jeffmylife / s3_to_rds.py
Last active November 18, 2020 23:26
Transfer a large csv file on S3 to RDS Serverless through lambda function.
import csv
import json
import os
import boto3
import botocore.response
from pprint import pprint
MINIMUN_REMAINING_TIME_MS = int(os.getenv('MINIMUM_REMAINING_TIME_MS') or 10000)
@jeffmylife
jeffmylife / routes.py
Last active October 6, 2020 00:19
Python dict to Javascipt JSON object with Jinja templating
@app.route("/testing")
def test_json():
some_dict = {
's':"some_stringy",
'bool':True,
'lst':[1,2,3],
}
return render_template("some.html", python_dict=some_dict)