Skip to content

Instantly share code, notes, and snippets.

View fsndzomga's full-sized avatar

Franck Stéphane Ndzomga fsndzomga

View GitHub Profile
@fsndzomga
fsndzomga / simple_pipeline.py
Created September 2, 2023 20:41
Simple pipeline to explain the LangChain Expression Language
from langchain.prompts import ChatPromptTemplate
from langchain.chat_models import ChatOpenAI
from apikey import OPENAI_API_KEY
import os
os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY
model = ChatOpenAI()
prompt = ChatPromptTemplate.from_template("In 2016, who was the president of {country}")
@fsndzomga
fsndzomga / complex_pipeline.py
Created September 2, 2023 22:26
This script creates a multilingual, context-aware question-answering system using LangChain and the OpenAI API, capable of responding to queries based on a given biography of Barack Obama.
from langchain.vectorstores import Chroma
from langchain.embeddings import OpenAIEmbeddings
from langchain.schema.runnable import RunnablePassthrough
from langchain.schema.output_parser import StrOutputParser
from langchain.prompts import ChatPromptTemplate
from langchain.chat_models import ChatOpenAI
from operator import itemgetter
from apikey import OPENAI_API_KEY
import os
@fsndzomga
fsndzomga / routes.py
Created September 3, 2023 21:29
Serializing and Deserializing a bot instance created using Embedchain
from flask import render_template, redirect, url_for, request, flash, session
from app import app
from app.forms import EmptyForm
from pdf_bot_class import PdfBot
from io import BytesIO
from uuid import uuid4
@app.route('/')
@app.route('/index')
@fsndzomga
fsndzomga / bot.py
Created September 3, 2023 21:58
Pdf bot created using EmbedChain
import os
import PyPDF2
from embedchain import App
from config import Config
from embedchain.config import ChunkerConfig, AddConfig
OPENAI_KEY = Config.OPENAI_KEY
chunker_config = ChunkerConfig(chunk_size=500, chunk_overlap=100)
@fsndzomga
fsndzomga / config.cfg
Created September 4, 2023 13:14
Config file for the Spacy LLM pipeline
[nlp]
lang = "en"
pipeline = ["llm"]
[components]
[components.llm]
factory = "llm"
[components.llm.task]
@fsndzomga
fsndzomga / spacy_llm.py
Created September 4, 2023 13:16
Simple usage of Spacy LLM
from keys import OPENAI_API_KEY
import os
from spacy_llm.util import assemble
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
nlp = assemble("config.cfg")
doc = nlp("You are an idiot !")
print(doc.cats)
@fsndzomga
fsndzomga / email_classification.py
Last active September 4, 2023 20:48
Email classification spacy llm
import pandas as pd
from keys import OPENAI_API_KEY
import os
from spacy_llm.util import assemble
import pandas as pd
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
nlp = assemble("email_config.cfg")
@fsndzomga
fsndzomga / email_config.cfg
Created September 4, 2023 16:13
Email config file
[nlp]
lang = "en"
pipeline = ["llm"]
[components]
[components.llm]
factory = "llm"
[components.llm.task]
@fsndzomga
fsndzomga / corpus.py
Created September 7, 2023 11:44
corpus
# Example of a simple corpus
corpus = [
"Natural Language Processing is fascinating.",
"ChatGPT is based on GPT-3.",
"Machine learning is an application of artificial intelligence."
]
@fsndzomga
fsndzomga / nltk-tokenize.py
Created September 7, 2023 11:46
Tokenisation using NLTK
from nltk.tokenize import word_tokenize
sentence = "Natural Language Processing is fascinating."
tokens = word_tokenize(sentence)
print(tokens)
# Output: ['Natural', 'Language', 'Processing', 'is', 'fascinating', '.']