Getting Started
In this guide, we will explore the essential principles and practical tips to ensure that your conversational AI app integrates seamlessly with our ecosystem.
1
Use your preferred package manager to install the Adgent package.
# using npm as package manager
npm install adgent-react
2
Go to Developer Dashboard to get your API key.
3
-
Wrap your chatbox in the
EnrichmentProvider
component, and pass the messages to it.
TheEnrichmentProvider
component is responsible for sending requests to our backend,
and fetching the appropriate enrichment. -
Add the
Enrichment
component outside of the loop that renders your messages,
this component is responsible for displaying the fetched enrichment. -
Provide appropriate styles to
Enrichment
to ensure it blends in with your chatbox.
import { EnrichmentProvider, Enrichment } from "adgent-react";
const apiKey = process.env.NEXT_PUBLIC_ADGENT_API_KEY;
// ...
// Add EnrichmentProvider around your chatbox
<EnrichmentProvider apiKey={apiKey} messages={messages}>
{messages.map((message, index) => (
<YourMessageComponent key={index} message={message} />
))}
// Add Enrichment component outside of the message components
<Enrichment darkMode={true} styles={{
marginLeft: "10px",
...
}}/>
</EnrichmentProvider>
By default, the component expects the messages to be of type Message[]
.
The message type is defined as follows:
type Message = {
role: "user" | "assistant" | ...;
content: string;
...;
};
A role
field with both "user" and "assistant" present and a content
field for text messages are mandatory.
If you are using a different type, you can pass an additional prop messageConfig
to the component.
The messageConfig
is defined as follows:
type MessageConfig = {
roleFieldName: string;
roleFieldUserValue: string;
roleFieldAssistantValue: string;
contentFieldName: string;
};
4
To test the enrichment, you can set the testMode
prop to true
. This will display mock enrichments.
Use testMode
to ensure that your enrichment component renders consistently with your ui.
<Enrichment testMode={true}/>
5
Setup is completed! You can view your statistics in the Dashboard.