Skip to content

Instantly share code, notes, and snippets.

View lukestanley's full-sized avatar

Luke Stanley lukestanley

View GitHub Profile
@lukestanley
lukestanley / be_nice_with_langchain_decorators.py
Last active June 12, 2023 14:52
I rewrote my script to use a new langchain_decorators lib.
# pylint: disable=too-few-public-methods,unused-argument,line-too-long,no-name-in-module
from typing import List
import logging
from pydantic import BaseModel, Field
from langchain.chat_models import ChatAnthropic
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain_decorators import llm_prompt, PromptTypes, GlobalSettings
@lukestanley
lukestanley / anthropic_fixing_langchain_decorators.txt
Created June 11, 2023 10:05
I used Anthropic to suggest code for fixing langchain-decorators. Here is the prompt. I didn't use all of it's suggestions but it had a working idea.
Human:
<file path=setup.py>
import setuptools
with open("src/langchain_decorators/__init__.py", "rt") as f:
for line in f.readlines():
if line.startswith("__version__"):
__version__ = line.split("=")[1].strip(" \n\"")
@lukestanley
lukestanley / be_nice.py
Last active February 13, 2024 07:20
LangChain spicy comment detox loop using Anthropic
import json
import time
from langchain.chat_models import ChatAnthropic
from langchain.schema import HumanMessage
FAST = "claude-instant-1"
GOOD = "claude-1.3"
model = GOOD
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lukestanley
lukestanley / alpaca.py
Created March 23, 2023 20:33
WIP Alpaca LangChain Python LLM Class with streaming
# Credit to https://github.com/nsarrazin/serge - this is heavily copied from the API there and not very well yet but it might work.w
from typing import List, Optional
from uuid import UUID, uuid4
from pydantic import BaseModel, Field
from datetime import datetime
import subprocess, os
import asyncio
@lukestanley
lukestanley / kendraio_flow_with_graphql_for_local-loop_mutations.txt
Last active November 30, 2022 12:38
Kendraio Flows doing GraphQL queries and mutations for DSP-1 and Local-Loop, prompts for GPT-3
A database of transactions between organisations was made with this SQL:
<code>
CREATE TABLE organisations ( id SERIAL PRIMARY KEY , name VARCHAR ( 255 ) NOT NULL );
CREATE TABLE transactions ( id SERIAL PRIMARY KEY , amount INT NOT NULL , from_organisation_id INT NOT NULL REFERENCES organisations ( id ), to_organisation_id INT NOT NULL REFERENCES organisations ( id ) );
INSERT INTO organisations ( name ) VALUES ( 'Acme' ), ( 'Widgets Inc' ), ( 'Foo Bar' );
INSERT INTO transactions ( amount , from_organisation_id , to_organisation_id ) VALUES ( 100 , 1 , 2 ), ( 200 , 2 , 3 ), ( 300 , 3 , 1 );
SELECT * FROM organisations ;
@lukestanley
lukestanley / echo_server.py
Created November 29, 2022 11:11
A Flask server to echo HTTP request headers as JSON to investigate issues with a CORS proxy
# A Flask server to echo HTTP request headers as JSON to investigate issues with a CORS proxy.
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/')
def index():
return jsonify(dict(request.headers))
@lukestanley
lukestanley / browser_with_thumbs_on_top.py
Last active September 26, 2022 06:29
A tabbed browser with thumbnails of each site in the tab bar on Linux using PySide2 with basic easylist adblocking
import sys
import time
import json
import os
import hashlib
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import (
QApplication,
QTabWidget,
@lukestanley
lukestanley / xuuid.py
Last active March 26, 2023 14:56
xuuid 0.1.1 -- Extended Universally Unique Identifiers Extremely large UUIDs that are more certainly unique, descriptive, supported by tooling for short local reference. There is a distinction made between "hard" and "soft" data for an identifier.
# xuuid.py
"""
xuuid 0.1.1 -- Extended Universally Unique Identifiers
Extremely large UUIDs that are:
more certainly unique,
descriptive,
supported by tooling for short local reference.
There is a distinction made between "hard" and "soft" data for an identifier.
@lukestanley
lukestanley / convert.js
Last active July 21, 2022 19:00
WIP, Somewhat generic functions to converts a Kendraio App JSON "website template" to a JSON Schema that can be filled in
// We already have a system that allows creating templates with empty placeholder sections for pages of sites as JSON.
// We need to take JSON that looks like this and turn it into editable real JSON Schema:
template = {
"name": "Great Example",
"domain": "great.example",
"websitemodel": [
{
"uuid": "44c2f597-79ef-49ed-9769-681f72f6b15e",
"name": "About and 404 pages",
"pagemodel": [