Skip to content

Instantly share code, notes, and snippets.

View morganmcg1's full-sized avatar
💭
Trying to ML

Morgan McGuire morganmcg1

💭
Trying to ML
View GitHub Profile
@morganmcg1
morganmcg1 / moe_non_determinism.py
Created January 23, 2024 16:50
Non-determinism in GPT-3.5, GPT-4 and Mixtral
import os
import json
import tqdm
import wandb
from openai import OpenAI
from time import sleep
from pathlib import Path
import openai
import wandb
openai.api_key = "sk-..." # supply your API key however you choose
# https://platform.openai.com/docs/models
tbl = wandb.Table("my_table", columns=["input", "output", "temperature"])
query = "hello world"
systemp_prompts = "you are friendly"
@morganmcg1
morganmcg1 / expert_prompt
Last active July 11, 2023 19:32
chatgpt expert prompt
"Recently, this problem was solved correctly. Here is the answer which turned out to be perfectly correct.
Note how the answer is documented step-by-step in a way that uses complex reasoning.
The person who discovered this solution always showed how they arrived on the decision to
execute the most efficient possible choice about what to do next, and clearly relied on
error-free code, calculators & fact-checked outside data sources to provide perfectly accurate answers at every step."
---------------
Here's a prompt that works really well to get GPT-4 to shorten text: I often use it to make my tweets fit in 280 characters:
```
#!/usr/bin/env python
# coding: utf-8
# In this notebook we will automatically generate a set of evaluation questions based on wandb docs
import random
import wandb
import re
import openai
import os
@morganmcg1
morganmcg1 / wandb_prompts_lanarky_patch.py
Created May 19, 2023 12:15
Monkey patching Lanarky for WandbTracer
import langchain
import wandb
from typing import Any, Awaitable, Callable, Dict, Optional, Union
from fastapi.responses import StreamingResponse as _StreamingResponse
from langchain.chains.base import Chain
from starlette.background import BackgroundTask
from starlette.types import Send
from dotenv import load_dotenv
@morganmcg1
morganmcg1 / synthetic_wandbot_data.ipynb
Created May 15, 2023 19:00
Generating synthetic questions and answers for wandbot
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@morganmcg1
morganmcg1 / fastapi_prompts.py
Created May 15, 2023 15:38
Using prompts and fastapi
from typing import Callable, Dict, Any, List
from fastapi import Depends, FastAPI
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from lanarky.responses import StreamingResponse
from langchain.callbacks.manager import AsyncCallbackManager
from langchain.callbacks.base import AsyncCallbackHandler
from langchain.chat_models import ChatOpenAI
from langchain.chains import LLMChain, SequentialChain, ConversationChain
from pydantic import BaseModel
@morganmcg1
morganmcg1 / async_langchain_wandb.py
Created May 15, 2023 14:41
Async langchain with streaming
from typing import Callable, Dict, Any, List
from fastapi import Depends, FastAPI
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from lanarky.responses import StreamingResponse
from langchain.callbacks.manager import AsyncCallbackManager
from langchain.callbacks.base import AsyncCallbackHandler
from langchain.chat_models import ChatOpenAI
from langchain.chains import LLMChain, SequentialChain, ConversationChain
from pydantic import BaseModel
# Needs datasets, albumentations
from PIL import Image
from datasets import load_dataset
from datasets.download.download_manager import DownloadMode #, REUSE_DATASET_IF_EXISTS, REUSE_CACHE_IF_EXISTS
import albumentations as A
from albumentations.pytorch.transforms import ToTensorV2
from albumentations.augmentations.transforms import Normalize
@morganmcg1
morganmcg1 / DBPlot.py
Created June 21, 2022 17:57
Code for DBPlot
# Decision Boundary Utils
-# Modified from https://github.com/tmadl/highdimensional-decision-boundary-plot
-class DBPlot(BaseEstimator):
- def __init__(
- self,
- estimator=KNeighborsClassifier(n_neighbors=10),
- acceptance_threshold=0.03,
- n_decision_boundary_keypoints=60,
- n_connecting_keypoints=None,
- n_interpolated_keypoints=None,