Skip to content

Instantly share code, notes, and snippets.

View vatsalsaglani's full-sized avatar
🎯
Focusing

Vatsal Saglani vatsalsaglani

🎯
Focusing
View GitHub Profile
@vatsalsaglani
vatsalsaglani / mistral_ctx.py
Last active September 20, 2024 14:31
Token counting and message token management for MistralAI
from typing import List, Dict, Literal, Union
from transformers import AutoTokenizer
class MistralAICtx:
def __init__(self, model_name: str):
assert "mistral" in model_name, "MistralCtx only available for Mistral models"
self.tokenizer = AutoTokenizer.from_pretrained(
"mistralai/Mistral-7B-Instruct-v0.2")
@vatsalsaglani
vatsalsaglani / vision_token_count.py
Created January 10, 2024 08:06
OpenAI GPT Vision Token Counting
import math
import re
from urllib import request
from io import BytesIO
import base64
from PIL import Image
from typing import Literal
def getImageDimensions(image: str): # base64 or url
<script>
// @ts-nocheck
import mermaid from "mermaid";
import { onMount } from "svelte";
import { browser } from "$app/environment";
import MarkdownRenderer from "../components/MarkdownRenderer.svelte";
import Spinner from "../components/Spinner.svelte";
$: inputText = ``;
$: thoughtProcess = ``;
import torch as T
import torch.nn.functional as F
import torch.nn as nn
import numpy as np
import os
import re
from bert4rec_model import RecommendationTransformer
from constants import TRAIN_CONSTANTS
from typing import List, Dict, Tuple
import random
from train_pipeline import trainer
from constants import TRAIN_CONSTANTS
from rich.table import Column, Table
from rich import box
from rich.console import Console
console = Console(record=True)
training_logger = Table(
import os
import re
import pandas as pd
from tqdm import trange, tnrange
import torch as T
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
from bert4rec_dataset import Bert4RecDataset
from bert4rec_model import RecommendationModel, RecommendationTransformer
import os
from requests import head
import torch as T
import torch.nn as nn
import torch.nn.functional as F
from modules import Encoder, Decoder
class RecommendationTransformer(nn.Module):
"""Sequential recommendation model architecture
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vatsalsaglani
vatsalsaglani / app.py
Last active June 7, 2022 16:26
FastAPI WebSocket & JS WS with headers
from typing import List
from fastapi import FastAPI, Header, WebSocket, WebSocketDisconnect
import uvicorn
app = FastAPI()
class ConnectionManager:
def __init__(self):
self.active_connections: List[WebSocket] = []
async def connect(self, websocket: WebSocket):
@vatsalsaglani
vatsalsaglani / Dockerfile
Created June 6, 2022 07:08
Dockerfile and requirements for Lambda OpenCV
# Define function directory
ARG FUNCTION_DIR="/function"
FROM python:3.7 as build-image
RUN apt-get update
RUN apt-get install -y