feat(azure): Added necessary azure components to app

Using respective credentials for both local development as well as
deployment. When deployed on azure, the app authenticates with the SQL
database via Entra ID (formerly active directory) and accesses other
credentials via key vault as a system managed identity.
This commit is contained in:
Tobias Quadfasel
2024-09-03 21:51:12 +02:00
parent 22000f1b0e
commit 02f1b41cb9
3 changed files with 104 additions and 16 deletions

View File

@@ -4,22 +4,6 @@ from openai import OpenAI
# from openai import AzureOpenAI
# Set up credentials
# NOTE: Usually I would use AzureOpenAI, but due to heavy rate
# limitations on azure trial accounts, I am using OpenAI directly
# for this project. However, this is how it would look like for
# AzureOpenAI (credentials must be provided to environment):
# client = AzureOpenAI(
# azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
# api_key=os.getenv("AZURE_OPENAI_KEY"),
# api_version="2024-02-01",
# )
# MODEL = "sqlai" # deployment name
# Set up the OpenAI client
MODEL = "gpt-4o"
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def send_message(message: str) -> str:
"""Send a message to the openai chat completion API and return the response.
@@ -103,6 +87,22 @@ def send_message(message: str) -> str:
Formatiere den Output bestmöglich.
"""
# Set up credentials
# NOTE: Usually I would use AzureOpenAI, but due to heavy rate
# limitations on azure trial accounts, I am using OpenAI directly
# for this project. However, this is how it would look like for
# AzureOpenAI (credentials must be provided to environment):
# client = AzureOpenAI(
# azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
# api_key=os.getenv("AZURE_OPENAI_KEY"),
# api_version="2024-02-01",
# )
# MODEL = "sqlai" # deployment name
# Set up the OpenAI client
MODEL = "gpt-4o"
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
response = client.chat.completions.create(
model=MODEL,
messages=[