Skip to content

Instantly share code, notes, and snippets.

View theoknock's full-sized avatar

James Alan Bush theoknock

View GitHub Profile
@theoknock
theoknock / Add Agent Guardrails.py
Last active November 27, 2025 04:24
Build with AI: Create Agents with the OpenAI Agents SDK
"""
Build with AI: Create Agents with the OpenAI Agents SDK
All examples use Python and the OpenAI client.
Prereqs:
pip install -r requirements.txt
export API_KEY = os.environ[...] or set the api_key to the client
"""
import os
@theoknock
theoknock / DOMWebKitElements.swift
Last active November 15, 2025 02:48
Lists all DOM elements from page loaded with WebKit.
import SwiftUI
import WebKit
import Combine
import Observation
@Observable class MyWebViewModel {
var webPage = WebPage()
func load(url: URL) async {
webPage.load(URLRequest(url: url))
@theoknock
theoknock / ChatGPT_Web_to_Desktop_App.swift
Last active November 4, 2025 04:45
Use the more fully featured ChatGPT web app on the macOS desktop.
//
// ContentView.swift
// WebBrowser2025-iPhone
//
// Created by Xcode Developer on 11/3/25.
//
import SwiftUI
import WebKit
@theoknock
theoknock / ContentView.swift
Last active October 30, 2025 13:04
A Swift/SwiftUI app that calculates planetary hour data.
//
// TempSwiftUIView.swift
// PlanetaryHours2025-Claude
//
// Created by Xcode Developer on 10/30/25.
//
import SwiftUI
import WeatherKit
import CoreLocation
@theoknock
theoknock / ContentView.swift
Last active October 12, 2025 05:34
A SwiftUI text-to-speech app that parses SSML-like markup (e.g., <prosody>, etc.) to read text with dynamic pacing, pitch, and volume controls using AVSpeechSynthesizer. Features play/pause/stop controls and real-time adjustment sliders for speech rate, pitch, and volume.
//
// ContentView.swift
// DesiderataReader
//
// Created by Xcode Developer on 10/11/25.
//
import SwiftUI
import AVFoundation
import Combine
@theoknock
theoknock / SystemLanguageModel.swift
Last active November 22, 2025 07:49
A workaround to the overly cautious guardrail violations policy used by the default SystemLanguageModel.
import Foundation
import FoundationModels // Docs: https://developer.apple.com/documentation/foundationmodels
import Playgrounds // #Playground macro: https://developer.apple.com/documentation/xcode/running-code-snippets-using-the-playground-macro
#Playground {
do {
let instructions = """
You are an interactive thesaurus. Task: Given a word and a starting letter, return a synonym of the word that starts with the letter.
"""
@theoknock
theoknock / ChatGPT 5 Simple Prompt and Response via curl
Created July 29, 2025 20:39
A simple prompt and response via curl using ChatGPT 5
# Save in "payload.json"
{
"model": "chatgpt-5",
"messages": [
{
"role": "system",
"content": "Your instructions:\n When prompted with a specific psalm (e.g., \"Psalm 23\" or \"23\"), you will write a six-paragraph abstract of psalm \\(abstract.psalmNumber) by following the $
},
{
@theoknock
theoknock / Run a Local Chat Completion with System Instructions Using DeepSeek.sh
Last active July 29, 2025 20:21
A prompt to a locally hosted deepseek-coder-v2-lite-instruct-mlx and ChatGPT 5 models via LM Studio’s OpenAI-compatible API.
# Prompt
curl http://localhost:1234/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-coder-v2-lite-instruct-mlx",
"messages": [
{ "role": "system", "content": "Answer all English questions in Spanish" },
{ "role": "user", "content": "How are you?" }
],
@theoknock
theoknock / Query OpenAI Chat Model and Print Clean Assistant Reply (Python).swift
Created July 29, 2025 19:29
Sends a user prompt to the GPT-4 API with a system role defining assistant behavior. It extracts and prints only the assistant’s response, omitting all metadata and token usage details. Clean and ready for direct terminal output or integration into larger apps.
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4-1106-preview",
messages=[
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "List 3 countries and their capitals."}
],
@theoknock
theoknock / Stream and Assemble OpenAI Chat Response in Python.swift
Last active July 29, 2025 19:14
Sends a chat prompt to the OpenAI API using streaming mode and reconstructs the full response by concatenating incoming chunks.
from openai import OpenAI
client = OpenAI()
stream = client.chat.completions.create(
model="gpt-4-1106-preview", # or "gpt-4.1" if that's valid in your setup
messages=[
{
"role": "user",
"content": "Say 'double bubble bath' ten times fast.",