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 / prompt-maker.py
Created September 19, 2023 14:17
prompt maker from the langchain hub
from langchain import hub, LLMChain
from langchain.chat_models import ChatOpenAI
from keys import OPENAI_API_KEY
import os
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
prompt_maker_template = hub.pull("hardkothari/prompt-maker")
llm = ChatOpenAI()
@fsndzomga
fsndzomga / text-to-sql.py
Created September 19, 2023 14:26
text to sql prompt
from langchain.utilities import SQLDatabase
from langchain.chat_models import ChatOpenAI
from langchain.schema.output_parser import StrOutputParser
from langchain import hub
from keys import OPENAI_API_KEY
import os
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
# Initialize database
@fsndzomga
fsndzomga / kg_from_text.py
Created September 21, 2023 00:12
knowledge graph from text using spacy
import spacy
import networkx as nx
import matplotlib.pyplot as plt
# Initialize spaCy model
nlp = spacy.load("en_core_web_sm")
# Define the function for simple Semantic Role Labeling (SRL)
def simple_srl(sentence, nlp):
doc = nlp(sentence)
@fsndzomga
fsndzomga / tool.py
Created September 23, 2023 03:20
Tool class for the AI agent
class Tool():
_all_tools = []
def __init__(self, name, description, call_function: Callable[..., Any]) -> None:
self.name = name
self.description = description
self._call_function = call_function
Tool._all_tools.append(self)
@fsndzomga
fsndzomga / agent.py
Last active September 23, 2023 03:35
AI agent class
class Agent():
def __init__(self) -> None:
self.llm = OpenaiLanguageModel(anonymize=False)
self.memory = {}
# Define standard tools
calc_tool = Tool("Calculator", "Performs basic mathematical operations", Agent.calculator) # noqa
self.tools = Tool.all()
agent = Agent()
response = agent("What is the square root of 44494949494949494")
# Response
""" What is the square root of 44494949494949494
Thinking...
The first step is to use the Calculator tool to calculate the square root of 44494949494949494.
from __future__ import annotations
from typing import Any, List, Callable, Optional, Union
from mytoken import apikey
import os
from anonLLM.llm import OpenaiLanguageModel
from pydantic import BaseModel, create_model
import inspect
import json
os.environ["OPENAI_API_KEY"] = apikey
@fsndzomga
fsndzomga / gpt4_agent.py
Created September 25, 2023 08:31
GPT4 Agent
from __future__ import annotations
from typing import Any, List, Callable, Optional, Union
from mytoken import apikey
import os
from anonLLM.llm import OpenaiLanguageModel
from pydantic import BaseModel, create_model
import inspect
import json
import wikipedia
from datetime import datetime
@fsndzomga
fsndzomga / loading_dataset.py
Created September 25, 2023 21:13
Code to load the dataset into a pandas data frame
import openpyxl
import pandas as pd
# Load the Excel file
workbook = openpyxl.load_workbook('online_retail_II.xlsx')
# Create an empty list to store data from all sheets
all_data = []
# Iterate through all sheets in the workbook
@fsndzomga
fsndzomga / market_basket_analysis.py
Created September 25, 2023 21:33
Code for market basket analysis
import pyfpgrowth
import pandas as pd
# Assuming df is your existing DataFrame
transactions = combined_data.groupby('Invoice')['Description'].apply(list).reset_index(name='items')
# Convert the 'items' column into a list of itemsets
transactions['items'] = transactions['items'].apply(lambda x: list(set(x)))
# Create a list of transactions as lists