Posts

Showing posts with the label SQL Server

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...