Skip to content

Instantly share code, notes, and snippets.

View tricktreat's full-sized avatar
🌴
On vacation

Yongliang Shen tricktreat

🌴
On vacation
View GitHub Profile
@oneryalcin
oneryalcin / sse_fast_api.py
Last active June 3, 2024 12:34
Server Side Events (SSE) with FastAPi and (partially) Langchain
# I couldn't get return generators from chains so I had to do a bit of low level SSE, Hope this is useful
# Probably you'll use another Vector Store instead of OpenSearch, but if you want to mimic what I did here,
# please use the fork of `OpenSearchVectorSearch` in https://github.com/oneryalcin/langchain
import json
import os
import logging
from typing import List, Generator
@HarshTrivedi
HarshTrivedi / pad_packed_demo.py
Last active July 5, 2024 22:47 — forked from Tushar-N/pad_packed_demo.py
Minimal tutorial on packing (pack_padded_sequence) and unpacking (pad_packed_sequence) sequences in pytorch.
import torch
from torch import LongTensor
from torch.nn import Embedding, LSTM
from torch.autograd import Variable
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
## We want to run LSTM on a batch of 3 character sequences ['long_str', 'tiny', 'medium']
#
# Step 1: Construct Vocabulary
# Step 2: Load indexed data (list of instances, where each instance is list of character indices)