Skip to content

Instantly share code, notes, and snippets.

View snopoke's full-sized avatar

Simon Kelly snopoke

View GitHub Profile
@snopoke
snopoke / remote_tool.py
Last active August 29, 2025 13:15
POC to illustrate remote tool calling in Langgraph using interrupts.
"""POC to illustrate remote tool calling in Langgraph using interrupts.
Based on the example at https://langchain-ai.github.io/langgraph/how-tos/human_in_the_loop/add-human-in-the-loop/#add-interrupts-to-any-tool
export ANTHROPIC_API_KEY="..."
export PG_CONNECTON_URL="postgres://postgres:postgres@localhost:5432/langgraph"
python remote_tool.py "Book me a room at the Sheraton Hotel"
python remote_tool.py --thread-id xxx --tool-response 'Hotel booking confirmed'
"""
import argparse
@snopoke
snopoke / upgrade.md
Last active April 3, 2024 09:20
docker pg-upgrade / migrate
@snopoke
snopoke / runnable_config.py
Created March 20, 2024 15:25
Langchain runnable configuration POC
import uuid
from typing import Generic, TypeVar
from langchain_core.callbacks import CallbackManagerForChainRun
from langchain_core.runnables import RunnableConfig
from langchain_core.runnables.base import RunnableSerializable
from langchain_core.runnables.utils import ConfigurableField
T = TypeVar("T")
@snopoke
snopoke / pipe_split_merge.py
Created March 20, 2024 15:24
Langchain runnable split / merge POC
"""
Demonstrate a method to create a pipeline that can handle dynamic splits in the pipeline based on the input type.
"""
import functools
import operator
from typing import Any
from langchain_core.callbacks import CallbackManagerForChainRun
from langchain_core.runnables import Runnable, RunnableConfig, RunnableLambda, RunnableSerializable, patch_config
from langchain_core.runnables.base import RunnableEach
@snopoke
snopoke / capability.json
Created March 10, 2023 14:56
FHIR capability statement
{
"resourceType": "CapabilityStatement",
"url": "https://www.commcarehq.org/a/<domain>/fhir/capability.json",
"name": "CommCare <domain>",
"title": "CommCare FHIR capability statement",
"status": "draft",
"date": "<dateTime>",
"publisher": "Dimagi",
"kind": "capability",
"implementation": {
import os
import csv
import shutil
import gzip
from datetime import datetime, timedelta
from collections import Counter
from elasticsearch.exceptions import ConnectionTimeout
from corehq.util.timezones.utils import parse_date
from corehq.apps.es import FormES
import csv
import shutil
import gzip
from collections import Counter
from elasticsearch.exceptions import ConnectionTimeout
from corehq.util.timezones.utils import parse_date
path = '/home/cchq/form_dates'
try:
@snopoke
snopoke / logstash.conf
Last active January 7, 2020 11:36
Logstash config example for parsing nginx-timing logs
##
# {{ ansible_managed }}
# See https://github.com/dimagi/commcare-cloud/compare/sk/logstash?expand=1
filter {
if [type] == "nginx-timing" {
grok {
match => [
"message", "\[%{HTTPDATE:http_timestamp}\] (?<cache_status>[-\w]+) %{WORD:http_method} %{DATA:request} HTTP/%{NUMBER:httpversion} %{NUMBER:status_code} %{NUMBER:request_time}"
]
@snopoke
snopoke / nginx.conf
Created August 15, 2019 18:30
Example syslog-ng configuration for parsing nginx-timing logs
@module mod-python
@define logpath "/home/cchq/www/{{ deploy_env }}/logs"
@define environment "{{ env_monitoring_id }}"
@define statsd_host "{{ datadog_statsd_host|default('localhost') }}"
@define statsd_port "{{ datadog_statsd_port|default(8125) }}"
source src {
file("`logpath`/{{ deploy_env }}-timing.log" follow-freq(1) flags(no-parse));
};
@snopoke
snopoke / pg_log_loader.py
Created June 13, 2019 11:41
PostgreSQL log parsing into SQL
# Load and parse CSV logs from PostgreSQL
import os
import re
import sys
import postgres_copy
import six
import sqlalchemy