Skip to content

Instantly share code, notes, and snippets.

View samirsaci's full-sized avatar

Samir Saci samirsaci

View GitHub Profile
@samirsaci
samirsaci / context_1.py
Created November 14, 2023 09:02
LangChain SQL - Context 1
context_explanation = """
As a supply chain control tower manager, my role involves overseeing the logistics network and ensuring that shipments are processed efficiently and delivered on time. The 'shipments' table in our database is crucial for monitoring these processes. It contains several columns that track the progress and timeliness of each shipment throughout various stages:
- 'Order_Date' and 'Expected_Loading_Date' provide timestamps for when an order was placed and when it was expected to be loaded for departure.
- 'Expected_Delivery_Time' is a timpestamp defining when the shipment is expected to be delivered
- 'Loading_OnTime', 'Airport_OnTime', 'Landing_OnTime', 'Transmission_OnTime' are boolean values indicating whether the shipment was processed on time at various stages. If any of these are False, it implies a delay occurred, potentially causing the shipment to miss its cut-off time and be postponed to the next day.
- 'Store_Open' indicates if the truck arrived at the store before closing tim
@samirsaci
samirsaci / template.py
Created November 14, 2023 08:46
LangChain SQL - Template
# Create the prompt template
template = PromptTemplate(
input_variables=["input_question", "context_explanation"],
template="""{context_explanation}
Question: {input_question}
"""
)
# Agent
agent_executor = create_sql_agent(
@samirsaci
samirsaci / test_1.py
Created November 14, 2023 08:20
LangChain SQL - Test 1
user_input = "How many shipments were delayed in the first seven days of May?"
try:
print("Question: ", user_input)
result = agent_executor.run(user_input)
print("Result: ", result)
except Exception as e:
print(f"An error occurred: {e}")
@samirsaci
samirsaci / agent.py
Created November 14, 2023 08:12
LangChain SQL - Agent Setup
from langchain.chat_models import ChatOpenAI
from langchain.agents import create_sql_agent
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
from langchain.sql_database import SQLDatabase
from langchain.agents.agent_types import AgentType
# Set up the OpenAI LLM
llm = ChatOpenAI(openai_api_key=OPENAI_API_KEY, model_name = "gpt-3.5-turbo")
# Set up the SQL database connection
@samirsaci
samirsaci / sample.csv
Created November 13, 2023 16:19
LangChain SQL - Sample data
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 38 columns, instead of 33. in line 1.
,Test,Order Time,Order Date,City,Store,ShipmentID,Order Amount,Transmission OnTime,Transmission,Start PickPack,Pickpack,Loading,Expected Loading Date,Loading OnTime,Loading Date,Loading Date+1,Airport Arrival,Airport OnTime,Airport Arrival Date,Airport Arrival Date+1,Takeoff,Landing,Landing Date,Landing Date+1,Landing Date+2,Landing OnTime,Start Clearance,End Clearance,Leaving Airport,City Arrival,City Arrival Date,City Arrival Date+1,Store Open,Delivery Time,Delivery Date,Expected Delivery Time,On Time Delivery
0,1,2021-05-02 17:00:00.000000,2021-05-02,CITY2,CITY2/ST8,2021-05-02/CITY2/ST8/1,5445,False,2021-05-03 17:00:00.000000,2021-05-04 07:00:00.000000,2021-05-04 13:31:48.042144,2021-05-04 19:00:00.000000,2021-05-04,True,2021-05-04,2021-05-05,2021-05-04 21:59:12.658318,True,2021-05-04,2021-05-05,2021-05-05 06:00:00.000000,2021-05-05 19:11:16.791315,2021-05-05,2021-05-06,2021-05-07,True,2021-05-06 09:00:00.000000,2021-05-06 11:32:50.282538,2021-05-06 12:19:46.058471,2021-05-06 17:08:54.687496,2021-05-06,202
@samirsaci
samirsaci / store.py
Created December 13, 2022 23:01
Digital Twin
# Define a Store class to represent a store
class Store:
def __init__(self, location, inventory):
self.location = location
self.inventory = inventory
def place_order(self, item, quantity):
if item in self.inventory and self.inventory[item] >= quantity:
self.inventory[item] -= quantity
print("Order fulfilled.")
@samirsaci
samirsaci / transportation.py
Created December 13, 2022 22:52
Digital Twin
# Define a Truck class to represent a truck
class Truck:
def __init__(self, location, capacity):
self.location = location
self.capacity = capacity
self.cargo = {}
def load_cargo(self, item, quantity):
if sum(self.cargo.values()) + quantity <= self.capacity:
@samirsaci
samirsaci / warehouse.py
Created December 13, 2022 22:39
Digital Twin
# Define a Warehouse class to represent a warehouse
class Warehouse:
def __init__(self, location, capacity):
self.location = location
self.capacity = capacity
self.inventory = {}
def add_inventory(self, item, quantity):
if item in self.inventory:
self.inventory[item] += quantity
@samirsaci
samirsaci / add_TTS.py
Created November 1, 2022 14:20
Automate Video Editing - TTS
# Add the TTS
audio_clip = AudioFileClip("Comment.mp3")
video_unload7 = video_unload1.set_audio(audio_clip)
video_unload7.write_videofile("step_1_audio.mp4")
@samirsaci
samirsaci / stacking_lag.py
Created November 1, 2022 14:07
Automate Video Editing - Stacking Lag
# Stacking with lag
final_clip_lag = clips_array([[video_unload1, video_unload3.set_start(5)],
[video_unload5.set_start(10), video_unload6.set_start(15)]])
final_clip_lag = final_clip_lag.volumex(0)
final_clip_lag.write_videofile("stack_lag.mp4")