Coder Social home page Coder Social logo

python-azure-open-ai-sample's Introduction

Azure ML Python sample with Azure Open AI

This repository provides very simple sample to use a notebook with Azure ML to connect and use Azure Open AI.

sample_mi.py uses a managed identity to authenticate to Open AI directly.

sample_mi_kv.py uses a managed identity to connect to a KeyVault to retrieve a secret.
This secret stores the api token of your Azure Open AI resource. This api key is used to connect to Azure OpenAI

Getting Started

1. Azure deployment

  • Create an Azure ML Workspace and the compute
  • Choose Python 3.8 Azure ML as kernel
  • Assign an identity to the compute (system or managed)
  • Add the Role Assignement to the Azure Open AI and/or KeyVault targeted resources
    • For Azure Open AI, use "Cognitive Service User" as Role
    • For KeyVault "Keyvault Secrets User" as Role
    • With System Assigned Identity, you need to use the principal named <azure_ml_workspace_name>/compute/<vm_name> for the role assignment

2. Python dependencies

Install dependencies in the notebook :

  • !pip install openai
  • !pip install azure-identity
  • !pip install azure-keyvault-secrets

3. Set up the variables

In the notebook, please provide those informations :

  • openai.api_base = "<URL of Azure OpenAI instance>"
  • openai.api_version = "<API version for Azure Open AI>"
  • engine = "<Name of your model deployment>"
  • KVUri = "<KeyVault URL>"
  • retrieved_secret = client.get_secret("<Secret name in KeyVault for azure open ai key>")

python-azure-open-ai-sample's People

Contributors

deuch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.