Skip to content

Instantly share code, notes, and snippets.

@csiebler
csiebler / openai_prompts.md
Last active July 10, 2025 23:23
Azure OpenAI Service prompt examples

GPT-3 examples (using mostly text-davinci-003)

Information extraction from claim phone conversations

  • Engine: text-davinci-003 (also works in text-davinci-002, but might require more instructions to get a correct JSON back)
  • Temperature: 0.7
You must extract the following information from the phone conversation below:
@csiebler
csiebler / gptindex_with_azure_openai_service.py
Last active July 10, 2025 22:07
Using LlamaIndex (GPT Index) with Azure OpenAI Service
import os
import openai
from dotenv import load_dotenv
from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader, LLMPredictor, PromptHelper
from langchain.llms import AzureOpenAI
from langchain.embeddings import OpenAIEmbeddings
from llama_index import LangchainEmbedding
# Load env variables (create .env with OPENAI_API_KEY and OPENAI_API_BASE)
load_dotenv()
@csiebler
csiebler / ssml_generation_with_openai.md
Last active July 10, 2025 11:14
This gist shows how to use OpenAI ChatGPT model to create SSML for Azure Speech to Text

Model: gpt-35-turbo

System message:

You are a bot that generates SSML for Text-to-Speech for Azure Speech. The text is in German, but contains English words. You should create a proper SSML, but for all English words, use the English voice. Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:emo="http://www.w3.org/2009/10/emotionml" xmlns:mstts="http://www.w3.org/2001/mstts" version="1.0" xml:lang="en-US">
   <voice name="en-US-JennyMultilingualNeural">
 Hallo, ich arbeite bei
@csiebler
csiebler / policy.txt
Created August 28, 2024 09:49
Azure Policy to disallow provisioning of "Provisioned-Mangaged" in Azure OpenAI (AOAI)
policyRule: {
if: {
field: 'Microsoft.CognitiveServices/accounts/deployments/sku.name'
equals: 'ProvisionedManaged'
}
then: {
effect: 'deny'
}
}
@csiebler
csiebler / instructions.md
Last active August 6, 2024 17:53
APIM Golden Template for Azure OpenAI Load Balance and Usage Tracking

Load balancing multiple AOAI resources and tracking usage for one or more use cases

Decision points

  • Which PTU deployments (models, regions)
  • Which PAYGO deployments (models, regions)
  • Token tracking level (use case, teams, etc.)

Load Balancing Strategy

@csiebler
csiebler / apim-policy-with-version-forwarding.xml
Last active June 28, 2024 11:17
APIM policy for AOAI for version forwarding
<policies>
<inbound>
<base />
<!-- Re-add the api-version query parameter, so the backends know which version we want -->
<set-query-parameter name="api-version" exists-action="override">
<value>@(context.Request.OriginalUrl.Query.GetValueOrDefault("api-version"))</value>
</set-query-parameter>
<!-- Getting the main variable where we keep the list of backends -->
<cache-lookup-value key="listBackends" variable-name="listBackends" />
@csiebler
csiebler / azure_openai_aad_access.py
Created November 23, 2023 08:09
Example to use a single AAD token for multiple Azure OpenAI resources
import os
import requests
from datetime import datetime
from azure.identity import DefaultAzureCredential, ChainedTokenCredential, ManagedIdentityCredential
# see https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication-on-premises-apps?tabs=azure-portal
# this Service Principal has the Cognitive Services OpenAI User role on the AOAI resources
os.environ["AZURE_CLIENT_ID"] = "xxxxx"
os.environ["AZURE_TENANT_ID"] = "xxxxx"
os.environ["AZURE_CLIENT_SECRET"] = "xxxxx"
@csiebler
csiebler / mount_dataset.py
Last active January 23, 2024 11:03
Mount Dataset to Azure Machine Learning Compute Instance
import os
import pandas as pd
from azureml.core import Workspace, Dataset
# Connect to Workspace and reference Dataset
ws = Workspace.from_config()
dataset = ws.datasets["german-credit-train-tutorial"]
# Create mountcontext and mount the dataset
mount_ctx = dataset.mount()
@csiebler
csiebler / news.jsonl
Last active October 27, 2023 17:35
RAG for current information access in real-time using AOAI and Azure Cognitive Search
{"title": "JPMorgan Chase’s Jamie Dimon and his family to sell $141 million of stock in 2024", "content": "JPMorgan Chase chief executive Jamie Dimon and his family plan to sell one million of their shares in the bank starting next year, according to a new securities filing.\n\nDimon — who will use his stock trading plans to offload his shares — and his family currently own roughly 8.6 million shares in the company. The move marks Dimon’s first stock sale during his 17 years at the company’s helm.\n\nJPMorgan Chase shares closed at $140.76 on Thursday, putting the transaction’s worth at roughly $141 million.\n\n“Mr. Dimon continues to believe the company’s prospects are very strong and his stake in the company will remain very significant,” JPMorgan Chase said in the filing.\n\nCNN has reached out to the company for comment.\n\nShares of JPMorgan Chase have climbed roughly 5% this year during what’s been a tough environment for banks. The Federal Reserve’s aggressive pace of interest rate hikes, which began i
@csiebler
csiebler / llama-index-chatgpt-azure-openai-service.py
Last active September 19, 2023 04:41
Using Llama-index with gpt-35-turbo for QNA with Azure OpenAI Service
import os
import openai
from dotenv import load_dotenv
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader, PromptHelper, LangchainEmbedding, ServiceContext
from llama_index.llms import AzureOpenAI
from langchain.embeddings import OpenAIEmbeddings
# Load environment variables (set OPENAI_API_KEY and OPENAI_API_BASE in .env)
load_dotenv()