Skip to main content

Azure GenAI utils

Project description

Azure GenAI Utils

This repository contains a set of utilities for working with Azure GenAI. The utilities are written in Python and are designed to be used for Hackathons, Workshops, and other events where you need to quickly get started with Azure GenAI.

Requirements

  • Azure Subscription
  • Azure AI Foundry
  • Bing Search API Key
  • Python 3.8 or later
  • .env file: Please do not forget to modify the .env file to match your account. Rename .env.sample to .env or copy and use it

Installation

pip install azure-genai-utils

Usage

Azure OpenAI Test

from azure_genai_utils.aoai_test import AOAI
aoai = AOAI()
aoai.simple_test()

Bing Search

Expand
from azure_genai_utils.tools import BingSearch
from dotenv import load_dotenv

# You need to add BING_SUBSCRIPTION_KEY=xxxx in .env file
load_dotenv()

# Basic usage
bing = BingSearch(max_results=2, locale="ko-KR")
results = bing.invoke("마이크로소프트 오토젠")
print(results)

## Include news search results and format output
bing = BingSearch(
    max_results=2,
    locale="ko-KR",
    include_news=True,
    include_entity=False,
    format_output=True,
)
results = bing.invoke("마이크로소프트 오토젠")
print(results)

Synthetic Data Generation

Expand
from azure_genai_utils.synthetic.qa_generator import (
    QADataGenerator,
    CustomQADataGenerator,
    QAType,
    generate_qas,
)

input_batch = [
    "The quick brown fox jumps over the lazy dog.",
    "What is the capital of France?",
]

model_config = {
    "deployment": "gpt-4o-mini",
    "model": "gpt-4o-mini",
    "max_tokens": 256,
}

try:
    qa_generator = QADataGenerator(model_config=model_config)
    # qa_generator = CustomQADataGenerator(
    #     model_config=model_config, templates_dir=f"./azure_genai_utils/synthetic/prompt_templates/ko"
    # )
    task = generate_qas(
        input_texts=input_batch,
        qa_generator=qa_generator,
        qa_type=QAType.LONG_ANSWER,
        num_questions=2,
        concurrency=3,
    )
except Exception as e:
    print(f"Error generating QAs: {e}")

License Summary

This sample code is provided under the Apache 2.0 license. See the LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure_genai_utils-0.0.2.3.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

azure_genai_utils-0.0.2.3-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file azure_genai_utils-0.0.2.3.tar.gz.

File metadata

  • Download URL: azure_genai_utils-0.0.2.3.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.2

File hashes

Hashes for azure_genai_utils-0.0.2.3.tar.gz
Algorithm Hash digest
SHA256 bf125079a93fa8bc55a5b6fdf056549e7d23d7e763e6cd5a5b9739b4ea6efaa3
MD5 d98198675facf1507409f00355f86df0
BLAKE2b-256 3b367e97b4301e546951f24b92f7726ed39053766b41ecb1ef7b4e585effc32a

See more details on using hashes here.

File details

Details for the file azure_genai_utils-0.0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for azure_genai_utils-0.0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6e5c5c00fb3c11292bdd84bcb067b079c9852abefd7b5a374e0c66e7be2a82c4
MD5 321347291ef0ea14f52cb56848a7368d
BLAKE2b-256 714287be80a4b32e4c85eb29fdfc8bcf069617256b92f8863d2476b90daa1975

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page