Skip to content

Instantly share code, notes, and snippets.

View velotiotech's full-sized avatar

Velotio Technologies velotiotech

View GitHub Profile
@velotiotech
velotiotech / .c
Created September 28, 2023 11:18
View .c
#include <stdio.h>
void print_string(char *str) {
int i = 0;
while (str[i]) {
printf("%c",str[i]);
i++;
}
}
int main() {
char location[20] = "The 1st location\n";
View .swift
GeometryReader { geometry in
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .leading) {
let rectangleHeight = geometry.size.height - contentSize.height
if contentSize != .zero, rectangleHeight > 0 {
Rectangle()
.frame(height: rectangleHeight)
.foregroundColor(.clear)
}
if let imageURL = viewModel.getImageURL() {
View .js
const marvel = {};
const ironMan = { key: 'arcReactor' };
const captainAmerica = { key: 'superSoldierSerum' };
marvel[ironMan] = 2008;
marvel[captainAmerica] = 2011;
console.log(marvel[ironMan]);
View .py
def summarize_pdf(file_path):
split_docs = text_splitter.split_documents(chunks(file_path))
return map_reduce_chain.run(split_docs)
result_sumary=summarize_pdf(file_path)
print(result_summary)
View .py
map_reduce_chain = MapReduceDocumentsChain(
llm_chain=map_chain,
reduce_documents_chain=reduce_documents_chain,
document_variable_name="docs",
return_intermediate_steps=False,
)
View .py
combine_documents_chain = StuffDocumentsChain(
llm_chain=reduce_chain, document_variable_name="doc_summaries"
)
reduce_documents_chain = ReduceDocumentsChain(
combine_documents_chain=combine_documents_chain,
collapse_documents_chain=combine_documents_chain,
token_max=5000,
)
View .py
map_template = """The following is a set of documents
{docs}
Based on this list of docs, summarised into meaningful
Helpful Answer:"""
map_prompt = PromptTemplate.from_template(map_template)
map_chain = LLMChain(llm=llm, prompt=map_prompt)
reduce_template = """The following is set of summaries:
{doc_summaries}
View .py
from langchain.chains.mapreduce import MapReduceChain
from langchain.text_splitter import CharacterTextSplitter
from langchain.chains import ReduceDocumentsChain, MapReduceDocumentsChain
from langchain import PromptTemplate
from langchain.chains import LLMChain
from langchain.chains.combine_documents.stuff import StuffDocumentsChain
View .py
from langchain.document_loaders import PyPDFLoader
def chunks(pdf_file_path):
loader = PyPDFLoader(pdf_file_path)
docs = loader.load_and_split()
return docs
View .py
from langchain.text_splitter import CharacterTextSplitter
text_splitter = CharacterTextSplitter.from_tiktoken_encoder(
chunk_size=1000, chunk_overlap=120
)