Skip to content

Instantly share code, notes, and snippets.

View pamelafox's full-sized avatar

Pamela Fox pamelafox

View GitHub Profile
@pamelafox
pamelafox / ai-environment.bicep
Last active February 24, 2025 21:49
Azure AI Project/Hub (start with main.bicep)
@minLength(1)
@description('Primary location for all resources')
param location string
@description('The AI Hub resource name.')
param hubName string
@description('The AI Project resource name.')
param projectName string
@description('The Storage Account resource ID.')
param storageAccountId string = ''
@pamelafox
pamelafox / azure_token.py
Last active February 19, 2025 13:16
Pydantic AI with Azure or GitHub Models
# pip install azure-identity
# pip install pydantic-ai
from openai import AsyncAzureOpenAI
from azure.identity.aio import (
AzureCliCredential,
get_bearer_token_provider,
)
from pydantic_ai import Agent
@pamelafox
pamelafox / tutor_eval.py
Last active March 5, 2025 16:12
tutor_eval.py
---
name: Tutorness
description: Evaluates how well the responses simulate a tutor
model:
api: chat
parameters:
temperature: 0.0
max_tokens: 800
top_p: 1.0
presence_penalty: 0
@pamelafox
pamelafox / prompty_safety.py
Created February 13, 2025 21:01
Prompty with Content Safety Error Handling
import openai
import prompty
import prompty.azure
# execute the prompt
try:
response = prompty.execute("approaches/prompts/chat_answer_question.prompty",
configuration={
"api_version": "2024-06-01",
"azure_endpoint": "https://cog-xxk4qzq3tahic.openai.azure.com",
@pamelafox
pamelafox / generate_simulations.py
Created February 6, 2025 23:24
Using Azure AI Evaluations simulator with Azure AI Search
import asyncio
import json
import logging
import os
from pathlib import Path
from typing import Any, Dict, List, Optional
import requests
from azure.ai.evaluation.simulator import Simulator
from azure.identity import AzureDeveloperCliCredential
@pamelafox
pamelafox / deepseek_azure_openai.py
Last active March 12, 2025 16:45
Using Azure AI SDK and OpenAI SDK with AIServices deepseek deployment
import logging
import os
from azure.identity import AzureDeveloperCliCredential, get_bearer_token_provider
from dotenv import load_dotenv
from openai import AzureOpenAI
load_dotenv(override=True)
logging.basicConfig(level=logging.DEBUG)
@pamelafox
pamelafox / python_instructions.json
Created January 17, 2025 21:15
python_instructions.json from Python Pulse stream
{
"github.copilot.chat.codeGeneration.instructions": [
{
"text": "Always add a comment: 'Generated by Copilot'."
},
{
"text": "In Python always adhere to PEP8. Prefer pandas over polars. Prefer argparse over click."
},
{
"text": "Use type annotations when writing python function signatures and classes."
@pamelafox
pamelafox / raghack_blogpost.py
Created December 19, 2024 21:07
raghack_blogpost.py
import json
import os
import requests
from datetime import datetime
import urllib.parse
from bs4 import BeautifulSoup
from rich import print
import openai
from pydantic import BaseModel
from azure.identity import AzureDeveloperCliCredential, get_bearer_token_provider
@pamelafox
pamelafox / extract_npr_article.py
Created December 2, 2024 21:39
Extract entities from NPR article with gpt-4o structured outputs
import os
import bs4
import requests
import rich
from openai import OpenAI
from pydantic import BaseModel
client = OpenAI(
base_url="https://models.inference.ai.azure.com",
@pamelafox
pamelafox / fstrings.py
Created September 21, 2024 22:18
Python 3.12 f strings
# print python version
import sys
print(sys.version)
import math
if True:
wow = f"""this is a multiline f string with triple quotes {math.pi:0.2f} :
1. Line 1
2. Line 3 {math.pi:0.2f}"""