The Chatbot Window
From the Windows menu on the Home toolbar, select Chatbot to open a window for communicating with an OpenAI, Azure OpenAI , or OpenAI API-compatible model. This feature assists with generating and correcting COMSOL API for Java® code directly within COMSOL Multiphysics, as well as answering modeling questions related to the software. Using the Chatbot window can help with both programming tasks using the COMSOL API for Java and general modeling tasks within the COMSOL Desktop. The Chatbot window is available in both the Model Builder and Application Builder workspaces.
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.
The Chatbot window requires authentication details for your selected provider, for example, an API key or connection settings for OpenAI, Azure OpenAI, or another OpenAI API–compatible service.
The first time that you use the Chatbot window you need to configure a chatbot provider. In the Chatbot window, click Configure Chatbot Provider, which opens the Preferences window. Choose a Provider and Model and enter your key in the API key field and click OK. If you are using Azure OpenAI, also enter an endpoint URL in the Endpoint field and a model deployment name in the Deployment name field. For the OpenAI API-compatible option, instead enter a Base URL and Model id.
If enabled, the Tool calling option allows the Chatbot to browse the COMSOL documentation for information.
Once configured, you can start a chatbot conversation. Note that obtaining an API key typically requires signing up for an API key payment plan. For more information, see the Reference Manual.
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.
It is your responsibility to ensure that your use of the AI system is in accordance with laws and policies that may apply. It is also your responsibility to review the suitability of any suggestions made by the AI system.
The following Chatbot window examples use various models from OpenAI. The output may vary depending on the selected provider and model, and due to the nature of large language models (LLMs), some random variation between responses is expected.
 
The Chatbot window includes a set of toolbar buttons and menus, as shown in the figure below. In addition, information on the number of tokens used is displayed in the Chatbot window’s top-right corner, next to Tokens used:
From the list in the top-left corner of the Chatbot window, you can select a subject: General, Programming, and Modeling, as shown in the figure below.
The selected subject influences how the chatbot interprets your prompts. The chatbot understands Java syntax but not all aspects of the COMSOL API. However, you can guide the chatbot to help you write code by using the Record Code functionality of the Method Editor.
For example, let us use the Chatbot window to add annotations to the Pacemaker Electrode tutorial model which is available in the Application Libraries under COMSOL Multiphysics>Electromagnetics with the filename pacemaker_electrode.mph.
If we open this model and record the creation of one annotation feature for the Electric Potential plot, then the following code is produced:
model.result("pg1").create("ann1", "Annotation");
model.result("pg1").feature("ann1").set("posxexpr", 0.001);
model.result("pg1").feature("ann1").set("posyexpr", 0.002);
model.result("pg1").feature("ann1").set("poszexpr", 0.003);
model.result("pg1").feature("ann1").set("text", "eval(V)");
Say that you would like to create 10 such annotations along a line. While having the Programming subject selected, the following prompt will then guide the chatbot to write functional code:
This is how you create an annotation in COMSOL Multiphysics:
 
model.result("pg1").create("ann1", "Annotation");
model.result("pg1").feature("ann1").set("posxexpr", 0.001);
model.result("pg1").feature("ann1").set("posyexpr", 0.002);
model.result("pg1").feature("ann1").set("poszexpr", 0.003);
model.result("pg1").feature("ann1").set("text", "eval(V)");
 
Can you create a for loop that places these annotations at 10 locations along a line from (x,y,z)=(0,0,-0.02) to (x,y,z)=(0,0,0).
The figure below shows the resulting output from the Chatbot window, which can be used to automate this task by entering the code in a method or in the Java Shell window.
To run the code in the Java Shell window, right-click in the output area and select Send to Java Shell. Alternatively, you can click the Send to Java Shell button in the toolbar.
Then, in the Java Shell window, click Run. The result is shown in the figure below.
For more details about the Chatbot window, see the Reference Manual.
Attaching Model History, Model Tree Nodes, or Images
You can attach the entire model history, represented as a Model File for Java, to a Chatbot prompt:
Select Send to Chatbot > Model History.
In the Chatbot window, enter a prompt, for example:
Can you find any issues with this model setup
This is shown in the figure below.
When prompted to compact the model history, choose Yes to remove redundant steps, unless you specifically want to include them.
You can also attach a specific model tree node:
Select Send to Chatbot > Node or Send to Chatbot > Node and Children to submit only that portion of the setup.
To attach images or screenshots: