Hi, I've faced same issues with a python script calling a resource, on my environment, the following helped me to deploy in python, but, when using Langchain as the Agent to massage my skills.
# Loading Azure Open AI Resource environment and keys in non-secure way expose solution to security risk as variables from ".env" file outside the code under the same project directory
# Recommended to replace with Azure Key Valt if aiming for production, current solution is not secure but good enough for a short-term learning and early testing
#System Variables
import os
from dotenv import load_dotenv
load_dotenv()
# Accessing environment variables
os.environ["OPENAI_API_TYPE"]
os.environ["OPENAI_API_VERSION"]
os.environ["AZURE_OPENAI_ENDPOINT"]
os.environ["OPENAI_API_KEY"]
os.environ["AZURE_COGS_KEY"]
os.environ["AZURE_COGS_ENDPOINT"]
os.environ["AZURE_COGS_REGION"]
# Importing AzureChatOpenAI from langchain_openai
from langchain_openai import AzureChatOpenAI
# Creating an instance of AzureChatOpenAI
llm = AzureChatOpenAI(
deployment_name='gpt-4-deployment', #Replace with the name given for your GTP-4 deployment
openai_api_type="azure",
temperature = 0
)
# Importing necessary modules for creating SQL agent from langchain
from langchain.agents import create_sql_agent
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
from langchain.sql_database import SQLDatabase
from langchain.llms.openai import OpenAI
from langchain.agents import AgentExecutor
from langchain.agents.agent_types import AgentType
from langchain.chat_models import ChatOpenAI
# Creating an instance of SQLDatabase pointing to a local database on the same resource location where application also exist.
db = SQLDatabase.from_uri('sqlite:///chinook.db')
# Creating an instance of SQLDatabaseToolkit
toolkit = SQLDatabaseToolkit(db=db, llm=llm)
# Creating an instance of AgentExecutor
agent_executor = create_sql_agent(
llm=llm,
toolkit=toolkit,
verbose=True,
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
)
# Interacting with the SQL database and learning from the data
agent_executor.invoke("Describe the playlisttrack table")