Skip to content

Instantly share code, notes, and snippets.

View csiebler's full-sized avatar
😊

Clemens Siebler csiebler

😊
View GitHub Profile
@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 / 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 / 00_extract_calls.ipynb
Last active August 4, 2023 08:40
Quick sample notebooks for using Azure OpenAI for call transcription insights, and then subsequent topic clustering and naming
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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()
@csiebler
csiebler / azure_openai_service_turbo_langchain.py
Last active July 25, 2023 15:12
Short snippet on how to use gpt-35-turbo (ChatGPT model) with LangChain in Azure OpenAI Service
# Make sure you have the latest openai and langchain versions running:
# pip install openai --upgrade
# pip install langchain --upgrade
# This code was tested with openai==0.27.8 and langchain==0.0.240
import os
import openai
from dotenv import load_dotenv
from langchain.chat_models import AzureChatOpenAI
from langchain import LLMChain
@csiebler
csiebler / ssml_generation_with_openai.md
Last active April 24, 2023 07:45
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
import os
import openai
from dotenv import load_dotenv
from langchain.llms import AzureOpenAI
from langchain.embeddings import OpenAIEmbeddings
# Load environment variables (set OPENAI_API_KEY and OPENAI_API_BASE in .env)
load_dotenv()
# Configure OpenAI API
@csiebler
csiebler / langchain_with_azure_openai.py
Last active July 25, 2023 15:12
Short example for using LangChain with Azure OpenAI Service
import os
import openai
from dotenv import load_dotenv
from langchain.llms import AzureOpenAI
from langchain.embeddings import OpenAIEmbeddings
# Load environment variables (set OPENAI_API_KEY, OPENAI_API_BASE, and OPENAI_API_VERSION in .env)
load_dotenv()
# Configure OpenAI API
@csiebler
csiebler / gptindex_with_azure_openai_service.py
Last active November 20, 2023 13:59
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 / openai_prompts.md
Last active November 23, 2023 14:28
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: