Skip to content

Instantly share code, notes, and snippets.

@kordless
kordless / README.md
Last active January 1, 2024 11:19
Example of using OpenAI functions in completions with Python decorators.

Example of using OpenAI functions in completions with Python decorators

This example illustrates a way to utilize a function dynamically while querying an OpenAI GPT model. It uses the newly released functions support in the completion endpoints OpenAI provides.

The general concept is based on using a decorator to extract information from a function so it can be presented to the language model for use, and then pass the result of that function back to the completion endpoint for language augmentation.

In general, a wide variety of functions can be swapped in for use by the model. By changing the get_top_stories function, plus the prompt in run_conversation, you should be able to get the model to run your function without changing any of the other code.

Configuration

To use this, create a config.py file and add a variable with your OpenAI token:

@odashi
odashi / jax_dataclass.py
Last active February 19, 2021 23:47
Augmented dataclass for JAX pytree.
import dataclasses as dc
from jax import tree_util as jt
def register_jax_dataclass(cls):
"""Registers a dataclass as a JAX pytree."""
if not dc.is_dataclass(cls):
raise TypeError('%s is not a dataclass.' % cls)
keys = [field.name for field in dc.fields(cls)]
@devjj
devjj / ffmpeg-hevc-encode-nvenc.md
Last active April 28, 2022 18:36
This gist shows you how to encode specifically to HEVC with ffmpeg's NVENC on supported hardware, with an optional CUVID-based hardware-accelerated decoder.

Encoding high-quality HEVC content with FFmpeg - based NVENC encoder on supported hardware:

tl;dr

ffmpeg -hide_banner -i input -c:v hevc_nvenc -preset hq -rc constqp -global_quality 21 -c:a libfdk_aac -ar:a 48000 -channel_layout:a 5.1 -ab:a 640k output

ffmpeg -hide_banner -i input -c:v hevc_nvenc -preset hq -rc vbr_hq -b:v 30000k -qmin 17 -qmax 21 -c:a libfdk_aac -ar:a 48000 -channel_layout:a 5.1 -ab:a 640k output

@sile
sile / README.md
Last active April 1, 2024 07:33
Optunaを使ってFFmpegのエンコードパラメータを最適化してみる

概要

  • Optunaというハイパーパラメータ最適化ツールを使って、FFmpegでの動画エンコードパラメータの最適化を試してみた結果のメモ
  • 具体的には、決められた制約(後述)下で、画質(SSIM)を最大化するようなパラメータ群を自動で見つけ出すのが目的
  • 結果としては、
    • 画質的には、FFmpegが提供しているプリセットの中で二番目に重いもの(slower)より若干良い程度のパラメータ群が見つかった
    • また、Optunaが見つけたパラメータ群の方がslowerに比べて、CPU負荷が小さかった

方針

@tomrunia
tomrunia / tensorflow_log_loader.py
Created March 2, 2016 09:11
Reading out binary TensorFlow log file and plotting process using MatplotLib
import numpy as np
from tensorflow.python.summary.event_accumulator import EventAccumulator
import matplotlib as mpl
import matplotlib.pyplot as plt
def plot_tensorflow_log(path):
# Loading too much data is slow...
tf_size_guidance = {