Using a Chatbot
The Chatbot window functionality connects to an external AI system. A subscription agreement with the AI system host is needed to obtain an API key. COMSOL is not a party in this agreement, and use of the external AI system may be subject to additional fees.
The Chatbot window is only available with the Windows® version of the COMSOL Desktop. The COMSOL software must also be installed with the CHATBOT feature included in the installation and enabled using the Enable Chatbot checkbox on the Chatbot page in the Preferences window.
From the Windows menu on the Home toolbar in the Windows version, choose Chatbot () to open the Chatbot window for chatting with an AI model, for example Open AI GPT-5. It can assist with generating and correcting COMSOL API for Java® code from within COMSOL Multiphysics as well as modeling questions related to the COMSOL Multiphysics software. Doing so can help out with programming using the COMSOL API for Java® as well as with general COMSOL modeling using the COMSOL Desktop. The Chatbot window appears both in the Model Builder workspace and in the Application Builder workspace.
To configure a chatbot provider, click Configure Chatbot Provider in the Chatbot window. In the Preferences window, choose a provider in the Provider list and enter a key in the API key field. If you are using Azure OpenAI or an OpenAI API compatible provider, see Chatbot Preference Settings for some additional settings required to set up the chatbot. Then click OK. You can now start a chatbot conversation.
Chatbot Conversations
From the start, the Conversation list at the top of the Chatbot window only contains New conversation. In the input area at the bottom of the window (where the text Enter prompt here appears), type a prompt (any question or statement) for the chatbot to respond to. Press Enter to submit the prompt as a message to the AI system, or click the Submit (Enter) button (). Press Shift+Enter to add a new line to the input area for submitting prompts. The conversation is named from the first message that you submit. The reply, including your input and all further messages appear in the output area in the middle of the Chatbot window. In the output area, you can right-click any message in a conversation and choose Copy () (or press Ctrl+C) to copy the content of that message, or choose Details () to open the part in a Details window where you can see the message in a separate view. The Details window can be resized.
From the Conversation list, choose New conversation to start a new conversation. Then use the Conversation list to switch between all active conversations. You can also click the Add Conversation button () to add a new conversation. Click the Delete Conversation button () to delete the current conversation; click the Clear All Conversations button () to clear all conversations.
In the input area, you can select some text and then right-click it and choose Copy (or press Ctrl+C) to copy that text, Cut (or press Ctrl+X) to remove it, or Paste (or press Ctrl+V) to replace it with some previously copied text. If the cursor is outside any text, only Paste is available, if something has previously been copied.
The messages are of the following types:
From the list in the top-left corner of the Chatbot window, you can choose from a list of subjects:
Choose General (the default) for any general conversations.
Choose Programming for any conversations that focus on programming using the COMSOL API for Java®.
Choose Modeling for any conversations about general COMSOL modeling and the COMSOL Desktop.
Click the Add File Attachment button () at the bottom of the window to attach a message with a text or image file from your file system. From the Select File window, select a file with one of the supported formats: text, CSV, PNG, JPEG, or GIF.
Sending Attachments to the Chatbot Window
In addition to adding external files as attachments, it is possible to attach contents from a model or application to the Chatbot window — for instance, Model Builder nodes, the model history, images from the Graphics window, and Application Builder methods. You can then ask the AI system for modeling advice or to assist with debugging or improving a method, for example.
Some attachments might exceed the Message Size limit set in the Chatbot Preference Settings. If so, you will be prompted to either send the message anyway (using the number of tokens specified in the Message Size dialog) or to cancel the operation.
Model Builder Nodes
Send Model Builder nodes as attachments to the Chatbot window by right-clicking one or multiple nodes in the Model Builder tree and then choosing one of the following options from the Send to Chatbot submenu:
Choose Node to send an attachment of the selected node (or nodes) to the current chatbot conversation.
Choose Node and Children to send an attachment of the selected node (or nodes) and all its children to the current chatbot conversation.
The attached message comprises the contents of the node as the corresponding Java code. This is an alternative to copying the node’s content using the Copy as Code to Clipboard functionality and pasting it in the input area. The difference is that when the code is sent as an attachment, only the attachment symbol () and the node’s name is displayed in the output area, minimizing clutter. To see the code in detail, right-click the attachment and choose Details.
Model History
To send the model history as an attachment to the current chatbot conversation, right-click the model’s root node and from the Send to Chatbot submenu choose Model History (). You will be prompted to compact the model history. In the Compact History dialog, click Yes to attach the model history that corresponds to the current state of the model. Click No to attach the entire history of the model, including settings that are no longer part of it. Right-click the attachment and choose Details to inspect the code in the Details dialog, if desired.
Graphics Window Content
Right-click in the Graphics window and choose Image () from the Send to Chatbot submenu to send a snapshot of the Graphics window as an image attachment to the current chatbot conversation. The image can be viewed by right-clicking the Image snapshot attachment in the Chatbot window’s output area and selecting Details.
Application Builder Methods
When in the Application Builder, you can right-click in a method window or on a Method node and from the Send to Chatbot submenu choose one of the following options:
Choose Code - method1 (for example, depending on the method name) to attach the method to a message in the Chatbot window.
Choose Find Bugs in method1 (for example, depending on the method name) to attach the method to a message in the Chatbot window with a suitable prompt for the given task, which you can adjust as you see fit.
Choose Suggest Improvements to method1 (for example, depending on the method name) to attach the method to a message with a suitable prompt for the given task, which you can adjust as you see fit.
These options can also be accessed by clicking Send to Chatbot in the Code section of the Method toolbar. This is an alternative to pasting the method code into the input area to ask about it if you have an Application Builder method that you have written or otherwise acquired. Right-click a method in the output area and choose Copy (or press Ctrl+C) to copy the method content. You can also right-click and choose Delete to remove it (or press Delete) or Details, to open a Details dialog where you can see the model content.
Connecting to the Java Shell Window
If you have code in a message in the output area (such messages have a in the upper-left corner), then, in addition to the Copy and Details options when right-clicking, you can also choose Send to Java Shell. The code is then transferred to the Java Shell window (see Interactively Using the COMSOL API for Java in the Java Shell Window), where it appears as a multiline input. Click the Run button () in the Java Shell window to run the code from the Chatbot window. You can also click the Send to Java Shell button () to send a code message to the Java Shell window.
If you get an error from the suggested code when running it in the Java Shell window, consider selecting the error in the Java Shell window, right-click it and choose Send to Chatbot, submit it in the Chatbot window, then use Send to Java Shell on the chatbot reply, run that Java code in the Java Shell window, and so on until the chatbot provides correct and error-free code.
Tokens
OpenAI and Azure OpenAI uses tokens as the basis for their billing. AI language models operate on tokens that are bits of words. Both the model input and output consist of tokens and are billed for. The total tokens consumed by a conversation is defined as the sum of the input and output tokens accrued throughout a given conversation. The following two token counts are be displayed in the Chatbot window’s top-right corner, next to Tokens used:
You can see the values directly, with the current conversation size to the left and the total usage to the right, abbreviated using K or M suffixes if needed. If you hover over the numbers, a tooltip such as Conversations Size: 1063 Conversation Total: 6457 displays the exact token counts.
Chatbot Preference Settings
The following preferences, available on the Chatbot page in the Preferences window, are related to the chatbot functionality:
The Enable Chatbot checkbox is selected by default. Clear it to close the Chatbot window and its functionality.
In the Conversation size (tokens) field, enter the threshold after which a conversation is automatically truncated, in tokens (default: 100,000 tokens).
In the Message size (tokens) field, enter the maximum size of an individual user message, in tokens (default: 5000 tokens). This limit on the message size only applies to user messages and not the messages related to the assistant or function calls.
In the Maximum number of concurrent conversations field, enter the number of ongoing conversations that are stored (default: 20, upper limit: 100). When the limit is surpassed, the oldest conversations are automatically deleted. The stored conversations can be accessed from the Conversation list in the Chatbot window.
From the Provider list, choose the AI provider that is used for generating responses: None, OpenAI (the default), Azure OpenAI, or OpenAI API compatible.
If you choose Azure OpenAI, also enter the following settings:
-
In the Endpoint field, enter the endpoint URL to your Azure OpenAI service. The URL should have the format: https://comsol.openai.azure.com, where comsol is your Azure OpenAI resource name.
-
In the Deployment name field, enter the model deployment name specified at the given Azure OpenAI endpoint.
Choose OpenAI API compatible to use the Chatbot window with an OpenAI API compatible AI provider. The following settings are then also required:
-
In the Base URL field, enter the URL to the API server. The URL has to include protocol (HTTP/HTTPS) and port number if the port is not standard.
-
In the Model id field, enter the id of the language model. Reference your AI provider’s documentation for the correct values.
-
In the Context length (tokens) field, enter the model context size, which limits the number of input plus output tokens in any given API request (default: 128,000 tokens).
-
Select the Tool calling checkbox to enable support for function calling. Make sure that your AI provider supports function calling, otherwise enabling this setting can cause errors.
The API key field contains the authorization key as hidden text. If authorization is not required by the provider, the field can be left blank.
When OpenAI or Azure OpenAI is selected from the Provider list, from the Model list, choose the OpenAI or Azure OpenAI model to be used by the chatbot: GPT-5 Low (the default), GPT-5 High, GPT-5 mini Low, GPT-5 mini High, GPT-4o, GPT-4 Turbo, or Custom. The suffixes Low and High indicate the reasoning effort of the GPT-5 model — Low is faster whereas High is more thorough. If you choose Custom, also enter the following settings for a custom model:
-
In the Model id field, enter an id to determine the OpenAI or Azure OpenAI model.
-
In the Context length (tokens) field, enter the model context size, which limits the number of input plus output tokens in any given API request (default: 128,000 tokens).
If you use Azure OpenAI as your provider, the model selected in the Model list must correspond to the model configuration of the Azure deployment.
If you choose Custom from the Model list, see the OpenAI or Azure OpenAI documentation for correct values to use with the Model id and Context length (tokens) settings.