Skip to main content

AI assistant

Integrating an AI assistant can provide intelligent conversations, personalized recommendations, and enhanced customer experience for your application or website.

How to use


const AIAssistant: ThemeConfigProps["AIAssistant"] = useMemo(() => {
return {
async onGenerate(messages) {
// Just pay attention to the return type here
const { data } = await axios.post<{ content: string; role: string }>(
`https://your-api-server.com/api/ai`,
{
data: {
messages: messages,
model: "gpt-3.5-turbo",
},
}
);
return { content: data.content, role: data.role };
},
// options: options,
};
}, []);


...
const config = Retro.useCreateConfig({
...
AIAssistant,
})

interface

 AIAssistant?: {
onGenerate: (messages: Array<{
role: string;
content: string;
}>) => Promise<{
role: string;
content: string;
}>;
options?: Array<{
label: string;
value: string;
getMessages(text: string): {
role: string;
content: string;
}[];
}>;
};

default options

const options = [
{
label: "Ask AI",
value: "Ask AI",
getMessages(text: string) {
return [
{
role: "system",
content: "Answer the question based on the context below.",
},
{
role: "system",
content: "The response should be in HTML format.",
},
{
role: "system",
content:
"The response should preserve any HTML formatting, links, and styles in the context.",
},
];
},
},
{
label: "Summarize content",
value: "Summarize content",
getMessages(text: string) {
return [
{
role: "system",
content: "Answer the question based on the context below.",
},
{
role: "system",
content: "The response should be in HTML format.",
},
{
role: "system",
content:
"The response should preserve any HTML formatting, links, and styles in the context.",
},
{
role: "user",
content: `Question: Provide the key points and concepts in this content in a succinct summary. Context: ${text}`,
},
];
},
},
{
label: "Improve writing",
value: "Improve writing",
getMessages(text: string) {
return [
{
role: "system",
content: "Answer the question based on the context below.",
},
{
role: "system",
content: "The response should be in HTML format.",
},
{
role: "system",
content:
"The response should preserve any HTML formatting, links, and styles in the context.",
},
{
role: "user",
content: `Question: Rewrite this content with no spelling mistakes, proper grammar, and with more descriptive language, using best writing practices without losing the original meaning. Context: ${text}`,
},
];
},
},
{
label: "Simplify language",
value: "Simplify language",
getMessages(text: string) {
return [
{
role: "system",
content: "Answer the question based on the context below.",
},
{
role: "system",
content: "The response should be in HTML format.",
},
{
role: "system",
content:
"The response should preserve any HTML formatting, links, and styles in the context.",
},
{
role: "user",
content: `Question: Rewrite this content with simplified language and reduce the complexity of the writing, so that the content is easier to understand. Context: ${text}`,
},
];
},
},
{
label: "Expand upon",
value: "Expand upon",
getMessages(text: string) {
return [
{
role: "system",
content: "Answer the question based on the context below.",
},
{
role: "system",
content: "The response should be in HTML format.",
},
{
role: "system",
content:
"The response should preserve any HTML formatting, links, and styles in the context.",
},
{
role: "user",
content: `Question: Expand upon this content with descriptive language and more detailed explanations, to make the writing easier to understand and increase the length of the content. Context: ${text}`,
},
];
},
},
{
label: "Trim content",
value: "Trim content",
getMessages(text: string) {
return [
{
role: "system",
content: "Answer the question based on the context below.",
},
{
role: "system",
content: "The response should be in HTML format.",
},
{
role: "system",
content:
"The response should preserve any HTML formatting, links, and styles in the context.",
},
{
role: "user",
content: `Question: Remove any repetitive, redundant, or non-essential writing in this content without changing the meaning or losing any key information. Context: ${text}`,
},
];
},
},
];