Skip to content

Instantly share code, notes, and snippets.

@mikery
mikery / generate_openai_functions.py
Last active June 13, 2023 19:45
Generating OpenAI Function Calling definitions with Python introspection
import inspect
import json
import re
from typing import get_args, get_origin, Literal, Callable
def generate_json(function: Callable) -> str:
""" Generate a JSON document describing a Python function, suitable for use with OpenAI's Function Calling.
:param function A Python function with docstrings for the function itself and its parameters.
function requestFlightStatus(address _oracle, string _jobId, string _flightId)
 public
 onlyOwner
 {
 Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(_jobId), this, this.fulfillFlightStatus.selector);
 req.add("flightId", _flightId);
 sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
 }
 
 function fulfillFlightStatus(bytes32 _requestId, uint256 _status)
{
"initiators": [
{
"type": "runlog",
"params": {
"address": "0x123"
}
}
],
"tasks": [
@mikery
mikery / schiphol_external_adaptor.py
Created June 29, 2019 12:24
schiphol-external-adaptor
import json
import requests
from flask import Flask, request, jsonify
app = Flask(__name__)
SCHIPHOL_API_ID = 'x'
SCHIPHOL_API_KEY = 'y'
SCHIPHOL_API_URL = 'https://api.schiphol.nl/public-flights/'
kind: Service
apiVersion: v1
metadata:
name: my-service
annotations:
service.beta.kubernetes.io/aws-load-balancer-security-groups: sg-123
spec:
type: LoadBalancer
selector:
app: my-app
package kubernetes.admission
import data.kubernetes.namespaces
import input.request.object.metadata.annotations as annotations
deny[msg] {
input.request.kind.kind = "Service"
input.request.operation = "CREATE"
input.request.object.spec.type = "LoadBalancer"
apiVersion: v1
kind: Namespace
metadata:
annotations:
elb-security-group: sg-123
name: dev
---
apiVersion: v1
kind: Namespace
metadata:
kind: Service
apiVersion: v1
metadata:
name: my-service
annotations:
foo: bar
spec:
type: LoadBalancer
selector:
app: my-app
package kubernetes.admission
import data.kubernetes.namespaces
import input.request.object.metadata.annotations as annotations
deny[msg] {
input.request.kind.kind = "Service"
input.request.operation = "CREATE"
input.request.object.spec.type = "LoadBalancer"
kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
type: LoadBalancer
selector:
app: my-app
ports:
- protocol: TCP