Use ChatGPT for data analysis: make your AnyLogic model talk

Model scheme with ChatGPT interface

This guest blog post by Felipe Haro and Joaquin Guzman, of Noorjax Consulting, shares their innovative methodology for seamlessly integrating ChatGPT into the data collection process within AnyLogic models.

Building a model and generating graphs with the simulation results is just the beginning. How about understanding the model and collecting the data that it was built for? Having a well-built model in front of your eyes might not be enough.

Today, we have multiple approaches to improving our experience using smart solutions. ChatGPT is a multi-functional tool that can help you read data and generate conclusions as you run the model. In this blog post, we will reveal several techniques for ChatGPT integration and teach you how to make use of this integration for data analysis.


  1. ChatGPT for data analysis
  2. An example of ChatGPT integration in an AnyLogic model
  3. ChatGPT data analyst installation
  4. Final opinion on ChatGPT usage for data analysis

ChatGPT for data analysis

ChatGPT excels at handling massive amounts of data quickly and effectively. Compared with humans, AI needs way less time to process information and draw conclusions. Imagine integrating a sophisticated tool like ChatGPT into your simulation model to simplify this process.

It can be compared with having a co-pilot that helps you navigate the model's behavior more intuitively. Using natural language processing (NLP), AI facilitates seamless communication between analysts or decision-makers and the simulation model. This approach streamlines tasks such as exploring, summarizing, and interpreting data.

The Data Analyst Co-Pilot

The solution that makes your life easier is an AnyLogic library with a chat agent. This agent connects to the OpenAI platform and allows you to benefit from AI capacity right in your model. You can send messages and read responses with the agent, letting ChatGPT do all the work for data analysis.

Interface of ChatGPT integrated in AnyLogic software

View of the AnyLogic and OpenAI chat agent

Before we get into the installation process and functions, let's go through an example model to see how the chat works.

An example of ChatGPT integration in an AnyLogic model

The video above demonstrates the flow of communication with the model via the ChatGPT agent, so let's go through the example step-by-step. In this model, users can adjust the birth rate, while the death rate varies based on population growth to limit excessive growth.

Structure of the birth rate model in AnyLogic

The model structure

The specifics of the model aren't crucial for demonstration purposes, but imagine it initially follows an exponential growth pattern, leveling off into an S-curve due to the imposed limitations. Running this model shows the population evolving accordingly.

Chart of population dynamics

Population growth dynamics

Now, we can begin interacting with ChatGPT. We can ask general behavioral questions or inquire about specific data points.

Chat with ChatGPT agent

Example of ChatGPT data analysis in the AnyLogic model’s chat agent

Let’s get into some specific situations. For example, tweak the birth rate mid-simulation and observe the resulting population changes.

Birth rate change chart

Change in the model dynamics after several months

We can ask ChatGPT to draw conclusions based on the new results without providing additional context. The responses may sometimes infer or assume details, yet they often lead to correct conclusions.

Dialogue interface

Example of communication with ChatGPT in the model

For example, while ChatGPT might inaccurately describe the timing of a change, it correctly identifies the cause of population decline – in this case, a reduction in birth rates. However, it is essential to approach these responses with caution. Remember that ChatGPT serves as a helpful tool rather than a perfect data science expert.

ChatGPT data analyst installation

The ChatGPT integration process is pretty simple and straightforward; just follow these three steps:

  1. Go to GitHub and install the Pypeline library. It enables Python queries, which is essential for utilizing OpenAI.
  2. Install the ChatGPT library designed by Noorjax developers. If you're new to adding libraries to AnyLogic, check out the help documentation for guidance.
  3. Once installed, you'll find the two added libraries at the bottom of the palette. Simply drag and drop the chat agent into your model.

When you are done with the installation stage, let's get familiar with the parameters of the chat agent.

Text font and Python setup for chat agent

Text font and Python sections for the ChatGPT agent in the AnyLogic model

Text font section

Here, you can customize the text font for the title and chat messages. Feel free to experiment to find the best option for your needs.

Python parameters

Python Path: Here, you can specify the path to your Python executable on your computer. If you're new to Python installation, check out the guide.

API Key: The unique identifier used to access OpenAI services. You can find your API key on the OpenAI platform by logging in or signing up.

Assistant Key:

  • Go to the OpenAI Assistants page and click on + Create.
  • Name your assistant, write instructions on how you want the chat to behave, and provide context on your model's purpose. Include a data format to communicate with OpenAI effectively.
  • For example: “Answer questions in a maximum of 80 words as an expert in epidemiology and an expert in data science and statistics. Only provide conclusions and answers related to the data. The data has this format: NameOfStat:{{Time:Value}}”.

    The format is crucial for seamless ChatGPT data analysis and communication. It helps the agent understand in what format the data is received.

  • Select the large language model from the available options, considering both performance and cost. The library works with GPT3.5 by default; for better performance, you can choose GPT4. If you choose GPT4, be sure to set up a payment method.
  • Important Note: Ensure you have sufficient credit on your OpenAI platform to receive responses from the chat. Initial credits may be available for GPT-3.5 but not for GPT-4.0 or higher.

  • Copy the generated assistant key and paste it into the Assistant key parameter of the chat agent in AnyLogic.

Data Time Unit: This setting determines the time units ChatGPT uses for its responses. Ensure consistency with these units when providing data to the chat.

Response Update Time (Seconds): This parameter determines how often the API checks for response readiness. You can leave it as default.

Chat presentation

You can modify the chat image with the parameters below. Feel free to experiment to find what works best for you.

Chat interface setup

Settings for the chat presentation in AnyLogic

Chat width: Adjust the chat width in pixels to fit your interface.

Space between text: Set the space in pixels between each line of text for better readability.

Number of chat lines to show: Specify the maximum number of lines displayed to control its size.

TextBox height: Define the height of the textbox where the prompt is written for comfortable typing.

Button height: Determine the height of buttons, such as reset and run responses, for easy interaction.

Max characters per line: Limit the maximum number of characters per line to maintain clarity and prevent text overflow.

Communicate data to the chat

Now that we've set everything up, our next step is to tell ChatGPT what information we're interested in. In the example we've been using, this would be when the birth rate changes. Additionally, we want to track how births, population, and deaths change over time. To do this, we can set up an event to generate this data once every month.

The method addStat takes three arguments:

  • The name of the data.
  • The time when it was collected.
  • The data is converted to a String.

Settings to add new parameters

AnyLogic interface for adding new parameters

If you also want to collect information on the initial birth rate in the event above, you can add this at time t=0:

chat.addStat("birth rate", time(), Double.toString(birthRate));

We can then use this same code to collect information on when the user changes the birth rate, as illustrated below.

AnyLogic interface with code to track changes in birth rate

Collect information about birth rate changes

Finally, if you want to reset your data, you can use the function resetStats().

Final opinion on ChatGPT usage for data analysis

In simulation modeling, ChatGPT integration provides analysts and decision-makers with remarkable capabilities to glean insights from complex systems. Its capacity to process extensive data and offer predictive insights enhances the scenario analysis. However, it's crucial to acknowledge that ChatGPT isn't flawless and should be regarded as a supportive tool rather than a sole determinant in your analytical endeavors.

Stay tuned for the latest and most effective techniques to enhance your interaction with simulation models. Subscribe to our newsletter now to stay updated!

Subscribe to our newsletter

Related posts