Use Azure OpenAI, Python and OpenAPI to create a PlantUML relationship diagram

This is not my first attempt at getting Azure OpenAI to tell me something about the relationship between OpenAPI entities, but it is the first time I have opened local files to get at the JSON. I have started with the smallest of the JSON files for Azure Media Services because I haven’t yet broken a larger file into acceptable token limit chunks. The paragraph I asked for didn’t turn out quite like I wanted it to…but that is for a different iteration of this experiment.

Python Code

import asyncio
import os
import json
import openai

from dotenv import load_dotenv
# Get environment variables
openai.api_type = "azure"
openai.api_base = os.getenv("OPENAI_API_BASE")
openai.api_version = "2022-12-01"
openai.api_key = os.getenv("OPENAI_API_KEY")

# Read the JSON files
async def readJSON():
     with open('ams_api/AccountFilters.json') as f:
          data = json.load(f)
     return data

async def main():
     data = await readJSON()

response = openai.Completion.create(
prompt=f"<|im_start|>system\nYou are a developer who wants to understand the relationship between entities in several OpenAPI files.\n<|im_end|>\n<|im_start|>user\nRead the JSON in {data}. First return a markdown table of the entities under 'definitions' with the entity name in the left column and the description in the right column. If the entity has properties, concatenate the entity name and property with a period delimiter. Put the concatenated name in the left column and the property description in the right column. Then return a paragraph that describes the parent/child relationships of the entities. Then return a PlantUML diagram that shows the relationships between entities. Make sure you include the properties of each entity.\n\n<|im_end|>\n<|im_start|>assistant",


if __name__ == '__main__':


Markdown Table

| Entity Name | Description |
| PresentationTimeRange | The presentation time range, this is asset related and not recommended for Account Filter. |
| PresentationTimeRange.startTimestamp | The absolute start time boundary. |
| PresentationTimeRange.endTimestamp | The absolute end time boundary. |
| PresentationTimeRange.presentationWindowDuration | The relative to end sliding window.|
| PresentationTimeRange.liveBackoffDuration | The relative to end right edge.|
| PresentationTimeRange.timescale | The time scale of time stamps.|
| PresentationTimeRange.forceEndTimestamp | The indicator of forcing existing of end time stamp.|
| FilterTrackPropertyCondition | The class to specify one track property condition.|
| | The track property type.|
| FilterTrackPropertyCondition.value | The track property value.|
| FilterTrackPropertyCondition.operation | The track property condition operation.|
| FirstQuality | Filter First Quality|
| FirstQuality.bitrate | The first quality bitrate.|
| FilterTrackSelection | Representing a list of FilterTrackPropertyConditions to select a track. The filters are combined using a logical AND operation. |
| FilterTrackSelection.trackSelections | The track selections.|
| MediaFilterProperties | The Media Filter properties.|
| MediaFilterProperties.presentationTimeRange | The presentation time range.|
| MediaFilterProperties.firstQuality | The first quality.|
| MediaFilterProperties.tracks | The tracks selection conditions. |
| AccountFilter | An Account Filter.|
| | The Media Filter properties. |
| AccountFilter.systemData | The system metadata relating to this resource.|
| AccountFilterCollection | A collection of AccountFilter items.|
| AccountFilterCollection.value | A collection of AccountFilter items.|
| AccountFilterCollection.@odata.nextLink | A link to the next page of the collection (when the collection contains too many results to return in one response).|


Kinda meh…I think this will turn out better when I am using the Accounts.json file rather than the AccountFilters.json file. What I asked for was probably too literal.

“The entities have a parent-child relationship. The `AccountFilter` entity has a property called `properties` which is of type `MediaFilterProperties`. The `MediaFilterProperties` entity has properties called `presentationTimeRange`, `firstQuality`, and `tracks`. The `tracks` property is an array of `FilterTrackSelection` entities. The `FilterTrackSelection` entity has a property called `trackSelections` which is an array of `FilterTrackPropertyCondition` entities.”

PlantUML Diagram

PlantUML Syntax:</p>
<p>@startuml<br />
class AccountFilter {<br />
+ properties: MediaFilterProperties<br />
+ systemData: systemData<br />
<p>class MediaFilterProperties {<br />
+ presentationTimeRange: PresentationTimeRange<br />
+ firstQuality: FirstQuality<br />
+ tracks: FilterTrackSelection[]<br />
<p>class PresentationTimeRange {<br />
+ startTimestamp: integer<br />
+ endTimestamp: integer<br />
+ presentationWindowDuration: integer<br />
+ liveBackoffDuration: integer<br />
+ timescale: integer<br />
+ forceEndTimestamp: boolean<br />
<p>class FirstQuality {<br />
+ bitrate: integer<br />
<p>class FilterTrackSelection {<br />
+ trackSelections: FilterTrackPropertyCondition[]<br />
<p>class FilterTrackPropertyCondition {<br />
+ property: string<br />
+ value: string<br />
+ operation: string<br />
<p>AccountFilter –> MediaFilterProperties<br />
MediaFilterProperties –> PresentationTimeRange<br />
MediaFilterProperties –> FirstQuality<br />
MediaFilterProperties –> FilterTrackSelection<br />
FilterTrackSelection –> FilterTrackPropertyCondition<br />