Search

Sunday 22 October 2023

Car Care Tips for Long Term Parking

Battery Care: Start the vehicle and keep the engine running in "ON" position once in a month for minimum 15 mins to keep the battery in good condition 

For cars with Smart Hybrid tech & Lithium-ion battery: Start vehicle and keep the engine running with Head Lights in "ON" position, for at least 30 minutes once in a month 

Car does not start at the first or second attempt: Don't crank the engine for more than 12 secs 

Keep the engine running at idle rpm for some time. It will allow the engine oil to spread for improved lubrication 

Operate your car AC for atleast 1 min; open all windows for faster cooling 

Don't drive with low tyre pressure: Inflate tyres to correct air pressure 

Don't immediately race the engine vigorously. It can damage the engine 

Check the fan and A/C belts: Rubber parts can get hard and may crack 

Remember to switch off all lights and accessories after engine is switched off to prevent any loss of battery charge 

There may be initial brake noise: Drive slowly with intermittent brake usage 

Check the levels of engine oil, coolant, brake and clutch fluids for any leakage

Park the car in gear. Do not engage the Hand Brake.

Use Wheel wedges/wooden block to avoid rolling.

Clean the interiors and do not leave any items in the car.

Upon your return, make sure to open the engine bay to inspect for any animals that might be resting inside. Additionally, check if there are any displaced belts, hoses, or wires caused by animals entering and exiting the area. If everything appears to be in order, proceed to clean the interior.


Wednesday 11 October 2023

Using Pandas Agent with OpenAI and Langchain for reading CSV

 import pandas as pd

from langchain.chat_models import ChatOpenAI
from langchain.agents import create_pandas_dataframe_agent, AgentType
#Load the .env file
from dotenv import load_dotenv,find_dotenv
load_dotenv(find_dotenv())

customersDf = pd.read_csv('Customers.csv')
salesDf = pd.read_csv('sales.csv')

chat = ChatOpenAI(model_name="gpt-3.5-turbo",temperature=0.0)
#Initialize pandas dataframe agent
agent = create_pandas_dataframe_agent(agent_type=AgentType.OPENAI_FUNCTIONS,
                                      llm=chat,
                                      df=[customersDf,salesDf],
                                      verbose=True)

agent.run("What is the name of the first customer?  using tool python_repl_ast")


agent.run("Has JON placed any orders?")

Read from Postgres DB using langchain and OpenAI

 from langchain import OpenAI, SQLDatabase

from langchain.chat_models import ChatOpenAI
from langchain_experimental.sql import SQLDatabaseChain, SQLDatabaseSequentialChain
import psycopg2
import os
from langchain import PromptTemplate
#Load the .env file
from dotenv import load_dotenv,find_dotenv
load_dotenv(find_dotenv())

# reference https://github.com/bhattbhavesh91/langchain-crashcourse/blob/main/sql-agent-notebook.ipynb
username = "postgres"
password = "postgres"
host = "localhost"
port = "5432"
mydatabase = "adventureworks"

pg_uri = f"postgresql+psycopg2://{username}:{password}@{host}:{port}/{mydatabase}"
input_db = SQLDatabase.from_uri(pg_uri)
# llm = ChatOpenAI(temperature=0, openai_api_key=API_KEY, model_name='gpt-3.5-turbo')
chat = ChatOpenAI(model_name="gpt-3.5-turbo",temperature=0.0, openai_api_key=os.getenv("OPENAI_API_KEY"))

db_agent = SQLDatabaseChain(llm = chat,
                            database = input_db,
                            verbose=True)

db_agent


temmplate = """You are generating queries and results from Postgres Database. The humanresources schema contains employee table. {question}"""

prompt = PromptTemplate(
    input_variables=["question"],
    template = temmplate,
)

db_agent(prompt.format(question ="How many employees are there?"))


# Another method using sql chain:
PROMPT = """
Given an input question, first create a syntactically correct postgresql query to run,  
then look at the results of the query and return the answer.  
The question: {question}
"""
db_chain = SQLDatabaseSequentialChain(llm=llm, database=db_agent, verbose=True, top_k=3)
question = "what is the average rent price in chicago in nov 2022 according to redfin?"
# use db_chain.run(question) instead if you don't have a prompt
db_chain.run(PROMPT.format(question=question))

#https://medium.com/dataherald/how-to-connect-llm-to-sql-database-with-langchain-sqlagent-48635fddaa74
#https://coinsbench.com/chat-with-your-databases-using-langchain-bb7d31ed2e76

Microsoft Autogen with a single agent

Prerequisites:

 pip install pyautogen


Code:

import autogen

config_list =[
    {
        'model': 'gpt-3.5-turbo',
        'api_key': 'XXXXXXXXXXXXX'
    }
]

llm_config = {
    "request_timeout":600,
    "seed": 42,
    "config_list": config_list,
    "temperature": 0
}

assistant = autogen.AssistantAgent(name="assistant",llm_config=llm_config)

user_proxy = autogen.UserProxyAgent(
    name="user_proxy",
    human_input_mode="TERMINATE",
    max_consecutive_auto_reply=10,
    is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
    code_execution_config={"work_dir": "coding"},
    llm_config=llm_config,
    system_message="""Reply TERMINATE if the task has been solved at full satisfaction.
Otherwise, reply CONTINUE, or the reason why the task is not solved yet."""
)

task = """"
Write a python code to find leap year
"""

user_proxy.initiate_chat(assistant,message=task)