Member-only story

Azure Open AI Assistant using Code interpreter and Functions — Plot charts

Balamurugan Balakreshnan
5 min readApr 13, 2024

--

Use Case

  • Using assistant api to create charts using python code
  • Only for dev purposes
  • Using GPT 4 turbo
  • using api version = 2024–02–15-preview

Pre-requisites

  • Azure Open AI GPT 4 turbo
  • Azure subscription
  • Azure machine learning workspace
  • Azure open ai key

Code

  • First install libraries needed
%pip install openai
%pip install python-dotenv
  • Import open ai library
import openai
import json
from typing import Optional
  • Load the environment variables
from dotenv import dotenv_values
config = dotenv_values("env.env")
  • Configure open ai
import os
from openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint = config["AZURE_OPENAI_ENDPOINT"],
api_key=config["AZURE_OPENAI_KEY"],
api_version="2024-02-15-preview"
)
  • json display function
import json
def show_json(obj):
display(json.loads(obj.model_dump_json()))
  • Create a function to plot the graph and save as image

--

--

No responses yet