🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
SysOpenAI Package
This page was created by Charles on 2025-01-16. Last edited by Wikiadmin on 2026-07-29.

You can use the SysOpenAI package to model chat-based OpenAI interactions in an MDriven application, including the AI endpoint configuration, chat sessions, and individual messages.

What the package contains

SysOpenAI is a package model pattern for integrating OpenAI functionality into your application. Merge the pattern into your model from TK Live View, then use its classes to store the endpoint reference, create chat sessions, and record the conversation between a person and the AI.

Typical uses include:

  • Processing application data.
  • Analysing data.
  • Searching through data.
  • Automating tasks in an information system or app.

Merge the package

  1. Open TK Live View.
  2. Merge the SysOpenAI model pattern into your model.
  3. Review the imported classes and their associations before connecting them to your own application classes.

A package is a container for a section of your model. See Documentation:Package for package concepts and Documentation:Referenced package for the difference between a referenced package and an adopted copy that you can edit.

Core classes

Class Purpose Example use
SysOpenAISingleton Points to the Azure instance where ChatGPT is deployed. Store the application-level reference to the Azure-hosted ChatGPT instance that chat sessions use.
SysOpenAIChatSession Represents a new AI session and is used when making requests to the AI instance. Create one session for a user working through a support task so its messages remain part of the same conversation.
SysOpenAIMessage Represents one interaction between the AI and the user. Create a user message containing a question, then retain the AI response as another message in the same session.

Model a conversation

A chat conversation is represented by a SysOpenAIChatSession and its SysOpenAIMessage objects. Each message has a role. The role tells the AI whether the text is persistent guidance, a user task, or an AI response.

For example, a session could contain these messages in order:

  1. A system message: You answer questions about the current case using the information supplied in the conversation.
  2. A user message: Summarise the open tasks.
  3. An AI response message containing the generated summary.

Keep messages in the session so that later requests can use the same conversation context.

Chat roles

Role Use it for Example
system Instructions that guide and structure the interaction. This is the context the AI follows when generating responses. Return a short summary suitable for a case worker.
user A task or input from the person interacting with the AI. List the overdue items.
assistance The AI response, generated from the system and user context. There are two overdue items: …

Use a system message to define the scope and form of an answer, then add user messages for the requests made in that scope. Store the resulting AI reply as an assistance message in the same session.

Using the pattern with your application model

Connect a chat session to the business object that gives the conversation its context. For example, if users ask the AI to help with a case, associate the relevant case with the session. The messages can then record the questions and answers for that case.

Use clear system instructions that state what the AI should do with that context. For example:

You assist with the current case. Summarise the supplied information,
identify open tasks, and do not add information that is not present.

The package description does not define the exact OCL expressions, attributes, endpoint settings, or request operation used to send a session to Azure. Verify those details in the merged model pattern before implementing an OCL action.

Design considerations

  • Treat SysOpenAISingleton as the application-level connection reference; create separate SysOpenAIChatSession objects for separate conversations.
  • Preserve the order and role of messages. A response depends on the system and user context supplied to the AI.
  • Keep instructions in system messages and requests from people in user messages. This makes the purpose of each message clear when reviewing a session.
  • Review the imported model before extending it. If you adopt a referenced package, it becomes your editable copy and does not receive updates from the original package. See Documentation:Referenced package.

See also