Posts

Query builder using LangChain, LangSmith using gpt-4o-mini LLM

Image
Open AI model gpt-4o-mini is one my favourite because of it's low cost and less effective time to get the job done.  Below code is to analyze question/query and transform them into meaning full SQL statement through LangSmith and LangChain. I'm not using Pydantic directly here and let the Lang team to handle the query builder part. One simple quetion - how many employee do we have? Let's see, how the below code act and what exactly SQL is able to generate: import os from langchain_openai import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate from typing_extensions import Annotated, TypedDict from langchain_community.utilities import SQLDatabase from langchain_community.tools.sql_database.tool import QuerySQLDatabaseTool from langgraph.graph import START, StateGraph os.environ[ "LANGSMITH_TRACING" ] = "true" os.environ[ "LANGSMITH_API_KEY" ] = "Your key" if not os.environ.get( "OPENAI_API_KEY" ...

Using Open AI and LangSmith connect to SQL Server

Image
This post is self explanotory where using Open AI api and LangSmith, I connected to my local SQL server and get the data from my local SQL table and finally print the data in command prompt. You need to have one Open API and LangSmith key to get this work. Just replace the keys on the respective code block. Commented lines represents different ways to connect SQL server using Open AI and LangSmith. import os import pyodbc os.environ[ "LANGSMITH_TRACING" ] = "true" os.environ[ "LANGSMITH_API_KEY" ] = " YOUR LANGSMITH KEY GOES HERE " if not os.environ.get( "OPENAI_API_KEY" ):   os.environ[ "OPENAI_API_KEY" ] = " YOUR OPENAI KEY GOES HERE " #from langchain_community.utilities import SQLDatabase #conn_str = "mssql+pyodbc:///?odbc_connect=DRIVER={SQL Server};SERVER=TUKAI\MSSQLSERVER01;DATABASE=EASY_DATE;Trusted_Connection=yes;" #db = SQLDatabase.from_uri(conn_str) #print(db.dialect) #print(db.get_usable_tabl...

Windows command prompt display Good Morning in my native language using OpenAI

Image
Great things to see first time using OpenAI - I can see Good Morning message in my native Bengali language in Windows Command prompt! Below the artifacts you need to install before run the code pip install langchain pip install langchain-openai pip install langgraph And, you need a key from  https://smith.langchain.com /  Finally, the code goes below... import getpass import os from langchain_openai import ChatOpenAI from langchain.schema import HumanMessage from langchain_core.prompts import ChatPromptTemplate if not os.environ.get( "OPENAI_API_KEY" ):   os.environ[ "OPENAI_API_KEY" ] = getpass.getpass( "YOUR OPENAPI KEY GOES HERE" ) chat = ChatOpenAI(model= "gpt-4o-mini" , temperature= 0.7 ) system_template = "Translate the following from English into {language}" prompt_template = ChatPromptTemplate.from_messages(     [( "system" , system_template), ( "user" , "{text}" )] ) #You can change lan...

Simple ChatBot using Open AI and LangChain, LangSmith

Image
This post is about simple chatbot one liner for understanding the flow. How the API coommunicate, how to structure the code, and what to call.  Open AI api and LangChain and LangSmith have been used here. Please note, you need to install LangChain, Open AI related chat model interfaces -  pip install -qU "langchain[openai]" Next step is to create one API key in LangSmith, and put your API keys in the below code. Replace your keys in the respective position: ( YOUR SANGSMITH KEY GOES HERE) and ( YOUR OPENAI KEY GOES HERE ). This is simple chat application which read your name and understand your first name. The reading and understanding is made through LangChain schema. Here the code goes... import getpass import os from langchain_openai import ChatOpenAI from langchain.schema import HumanMessage from langchain_core.messages import AIMessage os.environ[ "LANGSMITH_TRACING" ] = "true" os.environ[ "LANGSMITH_API_KEY" ] = "YOUR SANGSMITH...

Flying Parrot Over a Pond while Sun is in the sky - AI

Image
Using gpt-5 model , Open AI share this wonderful image....Lovethis one :) from openai import OpenAI import base64 from dotenv import load_dotenv load_dotenv() client = OpenAI() response = client.responses.create(     model= "gpt-5" ,     input= "Generate an image of white parrot flying over a pond while sun is in the sky" ,     tools=[{ "type" : "image_generation" }], ) # Save the image to a file image_data = [     output.result     for output in response.output     if output.type == "image_generation_call" ]     if image_data:     image_base64 = image_data[ 0 ]     with open( "fyingparrot.png" , "wb" ) as f:         f.write(base64.b64decode(image_base64))

Happy July 4th!

Image
 May your day be filled with delicious food, dazzling fireworks, and quality time with loved ones. Update on 9/16/25 : Surprised to see, model able to recognize the bridge :)

About Flex Consumtion Plan and enable Managed Identity in Azure Function

Image
Micrsoft bring a new plan for Azure Function - Flex Consumtion Plan for hosting. It is Linux based Azure Functions hosting plan. Below a quick sneek preview of the plan. And here is more details . Pretty simple way to create Azure Function. Created by a minute, and below my Azure Function is up and running. Let's try to enable managed identity in Azure Function. 1. Click on your Azure Function and bring the Function dashborad 2. Click on Identity under Settings 3. On the System assigned tab, switch the status to On and click save Next, you need to assign the roles to he Managed identity. To do so, first you browse to the respective Azure resources like Azure Storage/SQL DB/key Vault and assign the necesarry role-based-access-control (RBAC). Let's create a key Vault first and assign the  Afterwards, select the subscription and search your RBAC role and assigned the sale. Click on Save. Now, go back to Functon dashboard and then Settings >> Identity and then Azure Role ...

Hug in April

Image
  Hug in April Love U All  

How to enable/disable Multi-Factor Authentication(MFA) in M365 suite

Image
Multi-factor authentication (MFA) is an advanced security feature that strengthens account or application protection by requiring users to verify their identity through two or more factors—such as a password and a phone-generated code—instead of relying solely on a password.  Its is a security protocol that adds an extra layer of protection by requiring users to verify their identity through multiple channels.  MFA significantly strengthens security by making it harder for unauthorized individuals to gain access, even if one factor is compromised. So, if your password is hacked or leak, no-one able to login in your system as code generated by your mobile app during login through MFA is inaccessible to them.  Let's see how easy it is for you to setup.  1. First-step-first - Sign in to M365 Admin Center, then click on ..show all 2. Click on Users and then click on Active users - and then and then click on Multi-factor authentication -    It might ask you to...

How to bring on-premise SQL Server data into Azure Fabric Lakehouse

Image
On-premise data gateway - one of the important feature/service Azure Fabric platform is using to bring your on-premise data into Azure cloud. The data movement is secure and encrypted. You can review my my earlier post  https://splaha.blogspot.com/2025/03/use-on-premise-gateway-in-fabric-and.html   where I explain how to configure On-premise data gateway using Step 1 and Step 2. In this exaple, I'm going to use the same data conenction to pull my on-premise SQL tables using custom join SQL into Lakehouse. The entire post is self explanatory with step-by-step snapshot. I hope this will help you to understand each and individual steps as well as to execute the same at your end. Let's start with my on-premise SQL server details. As you can see the below picture, it talks about the database Employee where there are two tables EMP and DEPT. I'm going to use the same SQL into Fabric to pull the data. I assume you already created the on-premise data gateway using my earlier post...

SharePoint Framework (SPFx) - SharePoint Hackathon 2025

Image
 

Use On-Premise-Gateway In Fabric and copy data from On-prem to Azure Fabric

Image
On-Premise data gateway is an application which is required to be installed in your laptop/computer/server which connect to cloud and uses cloud services to send data back-and-forth from on-prem to cloud. This is secure data connection and data encryption is in place. Here is more about on-premise data gateway - https://learn.microsoft.com/en-us/data-integration/gateway/service-gateway-onprem?toc=%2Ffabric%2Fdata-factory%2Ftoc.json https://learn.microsoft.com/en-us/data-integration/gateway/service-gateway-onprem?toc=%2Ffabric%2Fdata-factory%2Ftoc.json Architecture of it - https://learn.microsoft.com/en-us/data-integration/gateway/service-gateway-onprem-indepth?toc=%2Ffabric%2Fdata-factory%2Ftoc.json https://learn.microsoft.com/en-us/data-integration/gateway/service-gateway-onprem-indepth?toc=%2Ffabric%2Fdata-factory%2Ftoc.json Step 1 First thing first - You need to install on-premise data gateway in your lcoal. Second thing is to open the on-premise data gateway and ensure th...