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
load_dotenv()
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()
print(data.keys())
response = openai.Completion.create(
engine="gpt-35-turbo-0301",
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",
temperature=1,
max_tokens=5500,
top_p=0.5,
frequency_penalty=0,
presence_penalty=0,
stop=None)
print(response['choices'][0]['text'])
if __name__ == '__main__':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(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.|
| FilterTrackPropertyCondition.property | 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.|
| AccountFilter.properties | 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).|
Paragraph
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.”