This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |