This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mirascope import llm, Messages | |
from mirascope.mcp import sse_client | |
import lilypad | |
from pydantic import BaseModel, Field, ValidationError | |
from tenacity import retry, stop_after_attempt | |
from fastmcp import FastMCP | |
from dotenv import load_dotenv | |
import asyncio | |
load_dotenv() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /// script | |
# requires-python = ">=3.11" | |
# dependencies = [ | |
# "humanlayer==0.7.9", | |
# "pydantic==2.11.5", | |
# ] | |
# /// | |
import humanlayer | |
from datetime import date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Script for generating queries for a recipe search engine. | |
This script can be used to generate synthetic queries for a recipe search engine. | |
Following best practices from Hamel and Shreya's AI Evals course, we: | |
- Generate a set of dimensions that can be used to generate queries; these are attributes that significantly change what the query is about or how it is written. | |
- For each set of attributes ("Dimensions") we generate a query that matches those attributes. | |
To ensure that the synthetic generation is better aligned, we first try handwriting the queries using the --manual flag. | |
This gives us labeled examples to use few shot in our synthetic generation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Agents can fail in fantastic ways, and stacktraces are unfortunately not always helpful enough. | |
# Fortunately, Pydantic AI agents keep track of messages, so as long as you save them you can view them and aid your debugging! | |
# This gist shows a simple `try_run` implementation which will log out the messages on error. | |
# You can imagine any number of things to do with the messages: send to logfire, store in a database, write to file, etc | |
# Pro tip: these form a helpful subset of data input/outputs to help refine your agent! Taking some time to store them | |
# appropriately for review (and possibly fine tuning / use in prompts / etc in the future) will pay off!! | |
These are examples where your agent actually failed! | |
from __future__ import annotations | |
import asyncio |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I found it surprising that tools had to return a JSON-like type; but didn't support Pydantic BaseModels! | |
# Perhaps that's by design. However, this simple decorator allows you to implement tools with structured output | |
# and slap a simple decorator to convert to JSON which the Pydantic AI tool format accepts. | |
# This is a minimal example | |
from __future__ import annotations | |
import asyncio | |
from collections.abc import Coroutine | |
from dataclasses import dataclass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a modification of the Pydantic AI weather example from: | |
# https://ai.pydantic.dev/examples/weather-agent/ | |
# It has been modified to add rate limiting, since the required APIs have tiny rate limits! | |
# I am using asynciolimiter: uv add asynciolimiter with a custom decorator to apply the rate limits | |
# Let me know if you know of a better/cleaner way! | |
# This means we can easily rate limit tools! | |
from __future__ import annotations as _annotations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 'Smart Revert' | |
# Uses git reset to perform a revert such that: | |
# - Git history stays intact | |
# - Works across merge commits | |
# See this stack overflow answer for information on the solution: | |
# https://stackoverflow.com/a/1470452 | |
# This takes a single argument: a git commit. Note: this can be either |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taken from the book: "Kubeflow for Machine Learning: From Lab to Production" | |
# Provided as-is | |
PLATFORM=$(uname) | |
export PLATFORM | |
mkdir -p ~/bin | |
export KF_TAG=1.0.1 | |
KF_BASE="https://api.github.com/repos/kubeflow/kfctl/releases" | |
KFCTL_URL=$(curl -s ${KF_BASE} |\ | |
grep http |\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h: \[\033[1;31m\]\w\[\033[m\]\$ " | |
export CLICOLOR=1 | |
export LSCOLORS=ExFxBxDxCxegedabagacad |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" This must be first, because it changes other options as side effect | |
set nocompatible | |
" To make compatible with vundle | |
filetype off | |
" Use pathogen to easily modify the runtime path to include all | |
" plugins under the ~/.vim/bundle directory | |
call pathogen#helptags() | |
call pathogen#infect() |