Skip to content

Instantly share code, notes, and snippets.

View jxnl's full-sized avatar

Jason Liu jxnl

View GitHub Profile
@jxnl
jxnl / _openai_pydantic_function_call.md
Last active June 14, 2023 10:25
Both the blog post and the code

Seamless Integration with OpenAI and Pydantic: A Powerful Duo for Output Parsing

Today, OpenAI introduced a Function Call API so we're going to dive into a much more structured and efficient way of handling output parsing when interacting with OpenAI. This method leverages the robustness of the Pydantic library in tandem with the recent improvements in OpenAI's API.

Historically, dealing with output parsing, especially with JSON responses, has been fraught with complexities. Ensuring the extracted data adheres to a specific schema or matches certain function calls often involves writing intricate and cumbersome error-checking code. Add to this the vagaries of AI and you often end up reasking and hoping it does a better job.

However, Pydantic, a Python library that provides data validation through Python type annotations, comes to the rescue! And when combined with OpenAI's new function call capabilities, it allows us to handle output parsing in a much more structured and reliable way with a much better d

@jxnl
jxnl / openai_schema.py
Last active June 14, 2023 09:19
Creating objects using Pydantic
import openai
from pydantic import BaseModel, Field
class OpenAISchema(BaseModel):
@classmethod
@property
def openai_schema(cls):
schema = cls.schema()
return {
@jxnl
jxnl / example_args.py
Last active June 23, 2023 09:51
Power of pydantic
import openai
import openai_function
@openai_function
def sum(a:int, b:int) -> int:
"""Sum description adds a + b"""
return a + b
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
curl --no-buffer -X 'POST' \
'https://youtube-markdown.fly.dev/youtube_markdown'\
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer (openai-api-key)' \
-d '{
"use_cache": false,
"url": "https://www.youtube.com/watch?v=QmOF0crdyRU&t=2s",
"use_sse": false

00:00:00 Introduction

Overview: Andrew Huberman, a professor of neurobiology and ophthalmology at Stanford School of Medicine, introduces the topic of dopamine and its relation to motivation, desire, craving, satisfaction, wellbeing, and addiction. He promises to dispel common myths about dopamine and provide tools for leveraging it to sustain energy, drive, and motivation.

00:01:02 Dispelling Myths About Dopamine

Overview: Andrew Huberman discusses common myths about dopamine and how it actually works. He covers the biology and psychology of dopamine as well as neural circuits and dopamine schedules. He explains how various things like food, drugs, caffeine, pornography, and plant-based compounds can change our baseline levels of dopamine.

00:02:10 Achieving High Increases in Dopamine Through Behaviors

00:00:00 Harry's Introduction to Kathy

Overview: Harry introduces Kathy and her background in finance.

Kathy's Background

  • Kathy was introduced to Capital Group at the tender age of 20.
  • She was fascinated by economics and the way the world was going to work in the future.
  • She has been running from indexed based investing and benchmarks in the traditional Asset Management world.
@jxnl
jxnl / exploit_math.py
Last active June 2, 2023 13:49
Prompt injections in LLM tools and potential solutions.
from dotenv import load_dotenv
load_dotenv()
from langchain import OpenAI
from langchain.agents import initialize_agent, tool
from langchain.chains import LLMMathChain
llm = OpenAI()
jobs:
build:
docker:
- image: 'docker.vertigo.stitchfix.com:5000/z-khan:latest'
steps:
- checkout
- restore_cache:
key: 'deps1-{{ checksum "app/requirements.txt" }}-1'
- run:
name: Install Dependencies
@jxnl
jxnl / stuff.py
Last active September 10, 2020 18:56
@flight.expose("/pdp/carousel/")
async def carousels_from_category(
client_id: int,
anchor_class: str = "shirt",
anchor_department: str = "Tops",
num_results: int = 9,
filter_type: str = "[match|pair]",
debug_mode: bool = False,
verbose: bool = False,
):
{'breadcrump': ['Home',
'Wiring Devices',
'AFCI Devices',
'AFCI Switches',
'SmartlockPro® Outlet Branch Circuit Combination AFCI/Switch '
'With LED Indicator'],
'long_description': ['Use of TEST and RESET Buttons is Similar to Traditional '
'GFCI Receptacles of Which Consumers Have Become '
'Familiar, Translating Into Greater Acceptance of the '
'Technology and a More User-Friendly Platform',