Make OpenAI ChatGPT Better!
It will be a very long article. Here you can try our custom OpenAI GPT designed to be an expert in the Sitecore area. If you want to know why and how we created it, grab a cup of tea and have a good reading!
Nowadays, AI is everywhere. Somewhere, it is useful. Somewhere is it harmful. I wrote about a LinkedIn case and a Microsoft Translations case. Today, I will criticize and fight with the holy grail of all modern AI: OpenAI ChatGPT. And I will fight against the most recent version o1-preview
. But, it will be not only critics comparing to previous cases. We will improve the Chat GPT results by creating a custom GPT based on our knowledge base and instructions!
Content is the King
We used to hear this phrase too often in the CMS world. Content rules the world of CMS. The better content you have, the more people will spend time consuming it, and the higher chance you will sell your products or services.
Content is the King also for AI. If you have a lot of content about some topic, you can easily train your AI with this content. If there is a lot of content about your topic on the internet, the leading large language models will learn more from it. And the quality of answers will be much higher.
I can give you an example. I needed to write some small script on Nyquist for Audacity. Nyquist is the programming language based on Lisp. It is an extension of the XLISP dialect. I have a ChatGPT Plus subscription, and I have a Copilot subscription, so it should not be a problem. Yes? No, unfortunately, I failed. I got some relevant suggestions on LISP, but all Nyquist suggestions and Audacity API suggestions were wrong. I tried to pass relevant context to ChatGPT, but with no luck… And I ended up with the usage of Python with Audacity. It would be more efficient to write everything on Nyquist from the architectural point of view. But, it was much more efficient to use Python from the time consumption point of view.
The same is true about Sitecore. If we compare ChatGPT answers about WordPress and Sitecore, the WordPress answers will be much more better. And that is not because OpenAI doesn’t like Sitecore and prefers WordPress. It is because of content. There is much more content about WordPress, and ChatGPT will be learned using this content. And it will not need to hallucinate about things that it doesn’t know. Indeed, it will still hallucinate, but it will hallucinate less about WordPress than about Sitecore.
ChatGPT Sitecore Examples
I will use the recently release o1-preview
. There is a lot of hype about the new model these days. But is it good for Sitecore? I will ask ChatGPT some simple questions, nothing very complex or very niche. I will share only the parts of the answers that we are interested in to save your time!
How to remove Sitecore Processor using configuration file patch?
To remove a Sitecore processor using a configuration file patch, you need to create a patch XML file that modifies the Sitecore configuration without altering the base configuration files. This is done by leveraging Sitecore's configuration patching mechanism, which allows you to add, replace, or remove configuration nodes.
Here's how you can do it:
- Create a Patch File:
- Create a new
.config
file (e.g.,RemoveProcessor.config
). - Place this file in the
App_Config\Include
folder of your Sitecore installation.
- Create a new
- Write the Patch Configuration:
- Use the
patch:remove
attribute to specify the processor you want to remove. - Ensure you include the correct namespace (
xmlns:patch="http://www.sitecore.net/xmlconfig/"
) in the<configuration>
element.
- Use the
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<mypipeline>
<processor type="MyNamespace.MyProcessor, MyAssembly" patch:remove="true" />
</mypipeline>
</pipelines>
</sitecore>
</configuration>
Failed. The result is very plausible, but it is wrong! There is no *patch:remove="true"
.*
How to create Hero component in Sitecore JSS Next.js? It should contain 3 fields: Image, Heading: SingleLine and SubHeading: RichText.
Create the React Component
Create the Hero component in your Next.js application that will render the fields defined in the manifest.
-
Create the Component File:
In your components directory (e.g.,
src/components
), create a new file namedHero.jsx
orHero.tsx
if you're using TypeScript.// src/components/Hero.tsx import React from 'react'; import { Text, RichText, Image, Field, ImageField } from '@sitecore-jss/sitecore-jss-nextjs'; type HeroProps = { fields: { image: ImageField; heading: Field<string>; subHeading: Field<string>; }; }; const Hero = ({ fields }: HeroProps): JSX.Element => ( <div className="hero"> <Image field={fields.image} alt="Hero Image" /> <h1> <Text field={fields.heading} /> </h1> <div className="subheading"> <RichText field={fields.subHeading} /> </div> </div> ); export default Hero;
Register the Component in the Component Factory
Sitecore JSS uses a component factory to map between the component definitions in Sitecore and the React components in your app.
-
Update the Component Factory:
In the
src/temp
directory, find thecomponentFactory.js
orcomponentFactory.ts
file and register your Hero component.import Hero from '../components/Hero'; export const componentFactory = (componentName) => { switch (componentName) { case 'Hero': return Hero; // ... other components default: return null; } };
If your project uses automatic component discovery, ensure your component's filename matches the component name in Sitecore (case-sensitive).
Passed? The code of the component is correct! But the addition about ComponentFactory is useless, it is misleading as this file is autogenerated.
Can you write a Sitecore PowerShell script to change the template of items?
PowerShell Script to Change Item Templates in Sitecore
# Parameters
$rootItemPath = "/sitecore/content/Home" # The starting path of items to process
$oldTemplateId = "{OLD-TEMPLATE-GUID}" # The ID of the template to change from
$newTemplateId = "{NEW-TEMPLATE-GUID}" # The ID of the template to change to
$language = "en" # The language version to process
$recursive = $true # Set to $false to process only the root item
# Get the root item
$rootItem = Get-Item -Path "master:$rootItemPath" -Language $language
if ($null -eq $rootItem) {
Write-Error "Root item not found at path: $rootItemPath"
return
}
# Function to change the template of an item
function Change-ItemTemplate {
param (
[Sitecore.Data.Items.Item]$item
)
# Check if the item's template matches the old template ID
if ($item.TemplateID.ToString().ToUpper() -eq $oldTemplateId.ToUpper()) {
Write-Host "Processing item: $($item.Paths.FullPath)"
# Begin editing the item
$item.Editing.BeginEdit()
try {
# Change the item's template
$newTemplate = Get-Template -Id $newTemplateId
if ($null -eq $newTemplate) {
Write-Error "New template not found with ID: $newTemplateId"
$item.Editing.CancelEdit()
return
}
$item.ChangeTemplate($newTemplate)
Write-Host "Template changed successfully for item: $($item.Paths.FullPath)"
$item.Editing.EndEdit()
}
catch {
Write-Error "Error changing template for item: $($item.Paths.FullPath). Error: $_"
$item.Editing.CancelEdit()
}
}
# Recursively process child items if required
if ($recursive -and $item.HasChildren) {
foreach ($child in $item.Children) {
Change-ItemTemplate -item $child
}
}
}
# Start the template change process
Change-ItemTemplate -item $rootItem
Failed. It is almost correct, but there is no Get-Template
function.
How to deploy Sitecore XM on Linux?
Deploying Sitecore on Linux has become more feasible with the introduction of container support in Sitecore 10 and later versions. By leveraging Docker containers and Kubernetes orchestration, you can run Sitecore in a Linux environment. Below are the steps and considerations for deploying Sitecore on Linux…
Failed. Total hallucinations.
o-1-preview Conclusion
I have to admit, that compared to GPT-4o
and GPT-4
, ChatGPT made big progress. It returns much more relevant answers related to Sitecore than it was before. And I like the reasoning, how it explains the way it came to some answer. However, it is still hardly usable for day-to-day work. Your daily workflow will become finding what is wrong with ChatGPT suggestions rather than writing code. Will it be more efficient? I have doubts…
Custom GPTs
We can see that the main problem of o1-preview
is hallucinations. It manages to answer some questions almost correctly if it has some knowledge about the topic. But it completely fails if it doesn’t know anything about the topic. And it will frequently fail in answers if junior developers try to use it for learning Sitecore. We can’t write a huge amount of content to force ChatGPT to learn about it. But, we can create a custom GPT with our knowledge base.
Creating Sitecore Expert GPT
We should use the same sources that we use if we want to find something about Sitecore
- Documentation
- Sitecore StackExchange
- GitHub source of Sitecore projects
- Blogs
- Sitecore Slack
The content should be either parsed and added to knowledge, or we should add instructions for Custom GPT to look inside all these locations before providing an answer. And very important thing is to force custom GPT to answer “I don’t know” if there is no relevant content. We tried different instructions, with “IMPORTANT” and “VERY IMPORTANT”, but custom GPT sometimes still starts to hallucinate before searching the knowledge. We assume that is caused by the costs of performing a search. Search could be quite expensive if you have a lot of data and you need to use this data as a context. Another problem for our Custom GPT is that Sitecore acquired many different products. And sometimes, when you ask about Sitecore XM, you get an answer about Sitecore Content Hub. It would be better if Sitecore doesn’t rename everything to Sitecore from the AI training point of view.
Custom GPT Results
Let’s compare our custom GPT with o1-preview
.
How to remove Sitecore Processor using configuration file patch?
To remove a Sitecore processor using a configuration file patch, you can utilize the patch:delete
element within your configuration patch file. Below is an example of how to remove a processor from a specific pipeline in Sitecore.
- Create a patch file (e.g.,
RemoveProcessor.config
). - Place the following XML code within the file:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<yourPipelineName>
<processor type="Your.Namespace.ProcessorType, Your.AssemblyName">
<patch:delete />
</processor>
</yourPipelineName>
</pipelines>
</sitecore>
</configuration>
In this example:
- Replace
yourPipelineName
with the name of the pipeline where the processor exists. - Replace
Your.Namespace.ProcessorType
andYour.AssemblyName
with the fully qualified name and assembly of the processor you want to remove.
This patch will delete the specified processor when Sitecore loads the configuration files .
Passed. It uses the right <patch:delete />
syntax for removing the processor.
How to create Hero component in Sitecore JSS Next.js? It should contain 3 fields: Image, Heading: SingleLine and SubHeading: RichText.
Define the TypeScript Interface
You need to define the fields that will be used in your component:
*import React from 'react';
import {
Field,
ImageField,
Image,
Text,
RichText,
} from '@sitecore-jss/sitecore-jss-nextjs';
interface HeroFields {
Image: ImageField;
Heading: Field<string>;
SubHeading: Field<string>;
}
type HeroProps = {
fields: HeroFields;
};
const Hero = (props: HeroProps): JSX.Element => {
return (
<div className="hero-component">
<Image field={props.fields.Image} alt="Hero Image" className="hero-image" />
<h1 className="hero-heading">
<Text field={props.fields.Heading} />
</h1>
<div className="hero-subheading">
<RichText field={props.fields.SubHeading} />
</div>
</div>
);
};
export default Hero;*
Passed. The component code looks ok and no additional hallucinations!
Can you write a Sitecore PowerShell script to change the template of items?
Here is an example of a Sitecore PowerShell script to change the template of items, while preserving field values:
# Define the paths to the source and target templates
$sourceTemplate = Get-Item "master:/sitecore/templates/SourceTemplate"
$targetTemplate = Get-Item "master:/sitecore/templates/TargetTemplate"
# Get the root item where you want to update the template
$rootItem = Get-Item "master:/sitecore/content/MySite"
# Traverse through all items and identify those that use the source template
Get-ChildItem $rootItem.FullPath -Recurse | Where-Object { $_.TemplateName -eq $sourceTemplate.Name } | ForEach-Object {
# Store the current field values from the source template
$title = $_.Fields["Title"].Value
$body = $_.Fields["Body"].Value
# Change the template to the target template
$_.ChangeTemplate($targetTemplate)
# Reload the item from the database after template change
$updatedItem = Get-Item $_.ID
# Set the field values in the new template
$updatedItem.Editing.BeginEdit()
$updatedItem.Fields["NewTitleField"].Value = $title
$updatedItem.Fields["NewBodyField"].Value = $body
$updatedItem.Editing.EndEdit()
Write-Host "Updated template for item: " $_.Paths.FullPath
}
Passed? It seems to work, but I don’t get an idea of setting additional field values. I didn’t ask about it. Also, it still doesn’t use the recommended approach Set-ItemTemplate
. However, it is aware of this function, but for some reason doesn’t use it for all cases. And to be honest, I prefer the o1-preview
version from the code point of view, even if it fails.
How to deploy Sitecore XM on Linux?
I couldn't find any related information in the knowledge base regarding deploying Sitecore XM specifically on Linux. However, if you're looking for general deployment instructions, the knowledge base contains information on deploying Sitecore using various other platforms like Azure PaaS and virtual machines, which may be adaptable for Linux environments.
For a Linux deployment, it might be worth consulting the official Sitecore documentation or seeking guidance on using containers (e.g., Docker) that can run Sitecore in a Linux environment.
Passed. Less Wrong!
Conclusion
We made a Custom GPT designed to chat about Sitecore. It is not ideal, but it seems that it is better than chatting with general-purpose GPTs about Sitecore. It has a huge knowledge base. It has more recent Sitecore knowledge(o1-preview
is limited to October 2023) and tends to hallucinate less! You can try it here.
If you have a knowledge base and want to use it for custom GPTs (OpenAI, LLAMA, etc.), we will be glad to help set it up for you!