Skip to content

Commit

Permalink
Improve AOAI authentication code (remove duplicate code, add comments…
Browse files Browse the repository at this point in the history
…, move API version to constant) (#11)

Remove key and add comments, move API version to constant
  • Loading branch information
iMicknl authored Oct 24, 2024
1 parent a53d8fd commit 2ad64a0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/utils/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from openai.types import CompletionUsage
from utils.identity import get_token_provider

AZURE_OPENAI_API_VERSION = "2024-09-01-preview"

PROMPT = """
Create a highly engaging podcast script between two people based on the input text. Use informal language to enhance the human-like quality of the conversation, including expressions like \"wow,\" laughter, and pauses such as \"uhm.\"
Expand Down Expand Up @@ -104,16 +106,17 @@ def document_to_podcast_script(
) -> PodcastScriptResponse:
"""Get LLM response."""

# Authenticate via API key (not advised for production)
if os.getenv("AZURE_OPENAI_KEY"):
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_KEY"),
api_version="2024-09-01-preview",
api_version=AZURE_OPENAI_API_VERSION,
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
)
# Authenticate via DefaultAzureCredential (e.g. managed identity or Azure CLI)
else:
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_KEY"),
api_version="2024-09-01-preview",
api_version=AZURE_OPENAI_API_VERSION,
azure_ad_token_provider=get_token_provider(),
)

Expand Down

0 comments on commit 2ad64a0

Please sign in to comment.