Skip to content

Instantly share code, notes, and snippets.

View roh26it's full-sized avatar
📺

Rohit Agarwal roh26it

📺
View GitHub Profile
@roh26it
roh26it / portkey-openaiv2.js
Created November 21, 2023 07:59
OpenAI v4 with Portkey AI (For SiteGPT) - Node
import OpenAI from 'openai'; // We're using the v4 SDK
const openai = new OpenAI({
apiKey: 'OPENAI_API_KEY', // defaults to process.env["OPENAI_API_KEY"],
baseURL: "https://api.portkey.ai",
defaultHeaders: {
"x-portkey-mode": "proxy openai",
"x-portkey-api-key": "PORTKEY_API_KEY",
"x-portkey-config": "CONFIG SLUG" // Optional to implement fallbacks, etc through a simple UI
}
@roh26it
roh26it / anthropic-portkey.py
Created October 19, 2023 14:55
Anthropic / Portkey
import portkey
from portkey import Config, LLMOptions
portkey.api_key = "<YOUR PORTKEY API KEY>"
llm = LLMOptions(provider="anthropic", virtual_key="<YOUR VIRTUAL KEY>")
portkey.config = Config(llms=[llm], mode="single")
response = portkey.ChatCompletions.create(
model="claude-instant-1.2",
messages=[{"role":"user", "content": "What is the meaning of life, universe & everything?"}],

Portkey Integration

Portkey.ai is a full-stack LLMOps platform to monitor & log all anyscale requests for latency, costs and accuracy. It also provides capabilities to use multiple models from different providers and setup load balancer, fallbacks and a/b tests between them.

To use Portkey with Anyscale endpoints, use the python SDK.

!pip install portkey-ai
import requests
import fitz # PyMuPDF
from io import BytesIO
import re
def download_pdf(url):
response = requests.get(url)
if response.status_code == 200:
return BytesIO(response.content)
else:
@roh26it
roh26it / multielo-demo.py
Created March 22, 2023 13:19
A demo to showcase Elo ratings for a multiplayer use case
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from multielo import MultiElo
# Initialize the Elo ratings and history
recipes = ['Recipe 1', 'Recipe 2', 'Recipe 3']
elo_ratings = np.array([1500, 1500, 1500])
elo_history = [np.array([1500]), np.array([1500]), np.array([1500])]