Simple Steps to a Generative AI Prototype

Using OpenAI Assistants

Posted by dave on September 29, 2024

The AI train is rolling fast. AI models are getting smarter and more capable at an exponential rate. No time like the present to explore the capabilities of AI to assist with your business use cases. The best approach is to prototype fast and often. If you don't, your competitors will!

The explosion of generative AI models has carried with it an explosion of "application programming interfaces" (APIs). I hope the industry will, at some point, focus on interoperability and develop a standard API for rich access to generative AI models, but I'm afraid that's further down the road. In the meantime, it's "pick your poison".

After reviewing the AI API menu, I landed on the OpenAI API. OpenAI has been leading the charge and their latest models are very capable at coding and data analysis. In addition, I was looking for the fastest and cheapest path to a minimum viable demonstration.

The AI terrain is very fluid and the common thread through all of them is the application-specific prompt sequence. This is just a text prompt (or stream) with relevant data interspersed. This prompt sequence should be separated from the underlying transport mechanism for future portability.

The OpenAI API is client-server and broken down into a Chat Completion API, where the client maintains state and an Assistants API, where the server maintains state in the form of an Assistant.

Chat Completion offers fine-grained control and the most flexibility along with the need for low-level plumbing and coordination.

OpenAI Assistants provide a model that abstracts away a lot of the details of thread and state management which is a great thing. Although I personally love plumbing, I'd rather just focus on application functionality. Assistants wrap up a lot of low-level features and functions into a neat little package that's hard to resist.

The GPT-4o model is very functional and fully supported by the Assistant API. It provides a good baseline. The newest o1 model is tuned for math and science and can think and reason before coming to a conclusion. It's a very powerful model indeed! O1 is in preview and should be supported by the Assistant API soon. No need to wait though. One line of code specifies which model to use.

An AI Starter Recipe

Spec out minimum viable demonstration functionality

  • What function will the AI perform? Run statistical analysis, regressions, peak detectors, linear programs, non-linear programs, etc.?
  • What data do I want the agent to work on? Forecast data, historical data or current data?
  • What actions do I want the agent to perform? Send notifications, alerts, future supervisory control actions?
  • What business docs are needed for the AI to provide the best answers? Proprietary data, specs, custom data models?
  • What systems need to be alerted by the AI? How are they accessed? Texting, email, MQTT, etc.?
  • Additional data that, may or may not, be needed to help define the context of the chat. Is this data independent of the prompt (e.g. real-time temperature)?

Create and test application prompts using an OpenAI Web UI Plus account

Define the application prompt that consists of a text prompt with appended data prompt. The text prompt describes in detail what you want the AI model to do. The data prompt consists of the "data of interest" using a supported text encoding (CSV,JSON). Generate this text using text tools you are comfortable with.

Submit to AI

Rinse and repeat until "results are promising"

Code and test assistant creation/deletion, server, and client apps

https://platform.openai.com/docs/assistants/overview

Download the OpenAI Python Library

https://platform.openai.com/docs/libraries

Study the QuickStart to learn about Assistants

https://platform.openai.com/docs/assistants/quickstart

An Example

An open-source sample Python toolkit to build an assistant can act as a template for a set of apps that support OpenAI Assistants. It has functions that can be modified as desired. The GridLoadManV2 agent is a good place to start.

https://upperbay.com/v1/blogs/beachblogs/openai-agent-toolkit

Remember: Prototype fast and often!

Have Fun With AI!

Dave Hardin