Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@peterroelants
peterroelants / compose.py
Created January 26, 2024 19:20
Python Function composition
from functools import partial
from typing import Protocol
class Callable(Protocol):
def __call__(self, *args, **kwargs):
...
class Params:
@peterroelants
peterroelants / fastapi_static_nocache.py
Created October 11, 2023 18:34
FastAPI Cache-Control : no-cache
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
class StaticNoCache(StaticFiles):
"""Disable caching of static files serverd"""
def is_not_modified(self, *args, **kwargs) -> bool:
return False
def file_response(self, *args, **kwargs):
@peterroelants
peterroelants / wiki_search_trace_tree.html
Created September 24, 2023 11:05
Wikipedia search agent tracing visualisation.
This file has been truncated, but you can view the full file.
<html>
<head>
<style>.tree {
position: relative;
}
/* Define variables used in tree-node */
:root {
--indent: 1em;
--border-width: 2px;
@peterroelants
peterroelants / main.py
Created September 22, 2023 19:08
FastAPI example web app for OAuth2 Authorization Code Flow
"""
FastAPI example web app for OAuth2 Authorization Code Flow.
Run with:
```
uvicorn main:app --reload --log-config=log_conf.yaml
```
"""
import logging
@peterroelants
peterroelants / openai_function_calling_react_loop.py
Last active October 4, 2023 07:38
Simple example of OpenAI Function Calling in ReAct Loop
"""
Simple example of OpenAI Function Calling in ReAct Loop.
Functions are described in JSON with each parameter the function accepts described as a JSON Schema object.
More info:
- OpenAI Function Calling
- https://openai.com/blog/function-calling-and-other-api-updates
- https://platform.openai.com/docs/guides/gpt/function-calling
- https://platform.openai.com/docs/api-reference/chat/create#chat/create-functions
@peterroelants
peterroelants / nvidia-smi.py
Last active August 27, 2022 09:29
Run nvidia-smi in notebook cell that keeps updating while other cells do their work
from datetime import timedelta
import multiprocessing
import subprocess
import time
from IPython.display import clear_output
def nvidia_smi_call():
"""
@peterroelants
peterroelants / linear_regression_SVI.ipynb
Last active October 12, 2021 07:08
NumPyro SVI linear regression
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@peterroelants
peterroelants / GMM-discrete.ipynb
Last active August 13, 2021 10:01
Numpyro AssertionError sample(key=None)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.