Skip to content

🫧 A one-stop hub, like a sample library 🪂 Azure OpenAI 100+ Sample Code 🧪 Organized by topic for quick reference.

Notifications You must be signed in to change notification settings

kimtth/azure-openai-llm-cookbook

Repository files navigation

Azure OpenAI LLM Cookbook

Static Badge GitHub Created At

📌 Quick Reference: Curated Sample Collection

A one-stop hub, like a sample library. This repository is organized by topic to help reduce the time spent searching for and reviewing sample code. It offers a curated collection of minimal implementations and sample code from various sources.

Important

🔹For more details and the latest code updates, please refer to the original link provided in the README.app.md file within each directory.
🔹Disclaimer: Some examples are created for OpenAI-based APIs.

💡How to switch between OpenAI and Azure OpenAI endpoints with Python

  • Programming Languages
    • Python:🐍
    • Jupyter Notebook:📔
    • JavaScript/TypeScript:🟦
    • Extra:🔴
  • Status & Action
    • Created:✨ (A unique example found only in this repository)
    • Modified:🎡 (An example that has been modified from a referenced source)
    • Copied:🧲 (When created or modified emojis are not following)
    • See the details at the URL:🔗
  • Microsoft libraries or products:🪟

⭐ If you find this repository useful, please consider giving it a star!

📖 Repository structure

📁 agent

📁 azure

📁 cookbook

📁 data

📁 dev

📁 eval

📁 framework

📁 industry

📁 llm

📁 llmops

  • azure_prompt_flow🔗🪟: Azure AI Foundry - Prompt flow: E2E development tools for creating LLM flows and evaluation
  • mlflow📔: OSS platform managing ML workflows

📁 multimodal

📁 nlp

📁 rag

📁 research

🛠️ Comparing Local with Remote Repository

You can use the git_cmp.py script (and related files) to compare your local project directories with their corresponding remote GitHub repositories.

Typical Workflow

  1. Index all projects and their GitHub URLs:

    python git_cmp.py --index --root <root_dir> --csv git_cmp_index.csv

    This creates a CSV file listing all projects and their remote URLs.

  2. Compare local and remote repositories:

    python git_cmp.py --compare --root <root_dir> --csv git_cmp_index.csv --report git_cmp_report.txt --update_csv git_cmp_needs_update.csv

    This generates a report and a CSV of projects needing updates. It also copies changed files into .cache/ for review.

  3. Update local files from cache (optional, use with care):

    python git_cmp.py --manipulate --root <root_dir> --update_csv git_cmp_needs_update.csv

    This copies files from .cache/ back into your project directories, optionally deleting files if flagged.

Mode & Command

  • SUBDIR Mode
    target_remote_path refers to a path in a remote repository that should be used as the starting point for comparison.
    When the mode is set to SUBDIR, a directory with the same name as project_name is expected to exist under that path. The comparison should target all files and directories within that SUBDIR.
    If there are files or directories that exist only in the remote (excluding readme.app.md, .url, and any folder—including its subdirectories—that contains a DONOTCMP file), they should all be copied into the SUBDIR.

  • FILE Mode
    When the mode is set to FILE, target_remote_path is not provided. A file with the same name is expected to exist at the specified GitHub URL. The comparison should target only that specific file, excluding readme.app.md, .url, and any folder—including its subdirectories—that contains a DONOTCMP file.

  • ROOT Mode
    When the mode is set to ROOT, target_remote_path is also not provided. All files and directories under project_name (excluding readme.app.md, .url, and any folder—including its subdirectories—that contains a DONOTCMP file) should be compared with those in the specified GitHub URL. Files or directories that exist only in the remote should be copied into the project_name.

  • Compare Command
    In compare mode, for files and directories that exist only in the remote, zero-size placeholder files will be created locally.
    Remote files and directories are treated as the source of truth.

  • Manipulation Command
    In manipulation mode, the remote repository for project_name should be updated. It is first cloned using the git clone command into the .repo_cache directory. After cloning, the actual file copying process to the local directories begins.
    All local files and directories should be deleted first—excluding readme.app.md, .url, and any folder—including its subdirectories—that contains a DONOTCMP file—and then replaced with the corresponding remote versions. However, this local wipe will only be triggered when allow_delete == 'DELETE' to ensure safety.

  • DONOTCMP is a marker file used to explicitly indicate that a directory is local-only and should be excluded from comparison.

Options

  • --delay_sec <seconds>: Add a delay between GitHub API calls to avoid rate limits.
  • --index: Index projects and write a CSV.
  • --compare: Compare projects and write a report.
  • --manipulate: Update local files from the cache based on the update CSV.

Example

python git_cmp.py --index --root . --csv git_cmp_index.csv
python git_cmp.py --compare --root . --csv git_cmp_index.csv --report git_cmp_report.txt --update_csv git_cmp_needs_update.csv
python git_cmp.py --manipulate --root . --update_csv git_cmp_needs_update.csv

Note:

  • Create .env file. Set the GITHUB_TOKEN. e.g.,GITHUB_TOKEN=<your_key>
  • Review .cache/ and the generated report before running --manipulate.
  • See comments and docstrings in git_cmp.py for more details.

➡️ Convert ipynb to Python

  • To convert a Jupyter notebook (.ipynb) into a runnable Python scrip
pip install nbformat nbconvert
import nbformat
from nbconvert import PythonExporter

# Load the notebook
notebook_filename = 'your_notebook.ipynb'
with open(notebook_filename, 'r', encoding='utf-8') as notebook_file:
notebook_content = nbformat.read(notebook_file, as_version=4)

# Convert the notebook to a Python script
python_exporter = PythonExporter()
python_code, _ = python_exporter.from_notebook_node(notebook_content)

# Save the converted Python code to a .py file
python_filename = notebook_filename.replace('.ipynb', '.py')
with open(python_filename, 'w', encoding='utf-8') as python_file:
python_file.write(python_code)

print(f"Notebook converted to Python script: {python_filename}")

💻 Microsoft Frameworks and Libraries

  1. Semantic Kernel (Feb 2023): An open-source SDK for integrating AI services like OpenAI, Azure OpenAI, and Hugging Face with conventional programming languages such as C# and Python. It's an LLM orchestrator, similar to LangChain. / git GitHub Repo stars
  2. Azure ML Prompt Flow (Jun 2023): A visual designer for prompt crafting using Jinja as a prompt template language. / ref / git GitHub Repo stars
  3. SAMMO (Apr 2024): A general-purpose framework for prompt optimization. / ref GitHub Repo stars
  4. guidance (Nov 2022): A domain-specific language (DSL) for controlling large language models, focusing on model interaction and implementing the "Chain of Thought" technique. GitHub Repo stars
  5. Autogen (Mar 2023): A customizable and conversable agent framework. / ref / Autogen Studio (June 2024) GitHub Repo stars
  6. UFO (Mar 2024): A UI-focused agent for Windows OS interaction. GitHub Repo stars
  7. Prompty (Apr 2024): A template language for integrating prompts with LLMs and frameworks, enhancing prompt management and evaluation. GitHub Repo stars
  8. OmniParser (Sep 2024): A simple screen parsing tool towards pure vision based GUI agent. GitHub Repo stars
  9. TinyTroupe: LLM-powered multiagent persona simulation for imagination enhancement and business insights. [Mar 2024] GitHub Repo stars
  10. RD-Agent: open source R&D automation tool ref [Apr 2024] GitHub Repo stars
  11. Magentic-One: Built on AutoGen. A Generalist Multi-Agent System for Solving Complex Tasks [Nov 2024]
  12. PyRIT (Dec 2023): Python Risk Identification Tool for generative AI, focusing on LLM robustness against issues like hallucination, bias, and harassment. GitHub Repo stars
  13. Presidio: Presidio (Origin from Latin praesidium ‘protection, garrison’). Context aware, pluggable and customizable data protection and de-identification SDK for text and images. [Oct 2019]
  14. Microsoft Fabric: Fabric integrates technologies like Azure Data Factory, Azure Synapse Analytics, and Power BI into a single unified product [May 2023]

📚 References & Sources

Contributor 👀

https://github.com/kimtth all rights reserved.

About

🫧 A one-stop hub, like a sample library 🪂 Azure OpenAI 100+ Sample Code 🧪 Organized by topic for quick reference.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published