Allow rendering HTML snippets (and code from other programming languages) in the Chat Generation Explorer

Created on 13 April 2025, about 1 month ago

Problem/Motivation

Not sure if this was posted/requested before in the issue tracker, couldn't find anything with a simple search, so here we go:

Yesterday I was doing a test of requesting ChatGPT to do this: I want an HTML template with a "Hello world" text inside it., and I got the expected result:

and you can copy and paste this snippet to use anywhere, basically I want to create HTML blocks like tables, lists or iframes to use in other pages in the same site.

I tried to do the same in the Chat Generation Explorer (Using OpenaAI and model gpt-3.5-turbo), and the results were a bit different:

It seems like the Chat Explorer tries to render the actual HTML, with no success, and the thing is that the response sent by OpenAI actually tells you that the following content is HTML content, so you can react properly on it:

"```html\n\u003C!DOCTYPE html\u003E\n\u003Chtml\u003E\n\u003Chead\u003E\n\u003C\/head\u003E\n\u003Cbody\u003E\n\n\u003Ch2\u003EList of 10 Fruits:\u003C\/h2\u003E\n\n\u003Cul\u003E\n \u003Cli\u003EApple\u003C\/li\u003E\n \u003Cli\u003EBanana\u003C\/li\u003E\n \u003Cli\u003EOrange\u003C\/li\u003E\n \u003Cli\u003EStrawberry\u003C\/li\u003E\n \u003Cli\u003EGrapes\u003C\/li\u003E\n \u003Cli\u003EWatermelon\u003C\/li\u003E\n \u003Cli\u003EPineapple\u003C\/li\u003E\n \u003Cli\u003EMango\u003C\/li\u003E\n \u003Cli\u003EKiwi\u003C\/li\u003E\n \u003Cli\u003EPeach\u003C\/li\u003E\n\u003C\/ul\u003E\n\n\u003C\/body\u003E\n\u003C\/html\u003E\n```"

Wouldn't be great to allow the user to generate HTML/JS/etc blocks from the chat and use it in the same site or everywhere? or is this something that was looked on but not implemented for some reason?

I can help implementing this because I'll be doing the same for my own module

Steps to reproduce

1. Install the AI module
2. Install your AI provider of choice
2. Open the Chat Generation Explorer (/admin/config/ai/explorers/chat_generator) and ask the question mentioned above.
4. You'll see the half-rendered HTML page in the "Response" section

Proposed resolution

- Parse the response sent by the AI provider, look at the headers, apply functions to parse the response and render ir properly (For example use the PHP function htmlentities() to process the response)
- Apply extra security verifications before parsing & rendering the code block, just in case

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.1

Component

Code

Created by

🇨🇦Canada danrod Ottawa

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024