Edit

Share via


Best Practices (TypeScript) (preview)

[This article is prerelease documentation and is subject to change.]

When sending messages using AI, Teams recommends a number of best practices to help with both user and developer experience.

AI-Generated Indicator

When sending messages using AI, Teams recommends including an indicator that the message was generated by AI. This can be done by adding a addAiGenerated property to outgoing message. This will help users understand that the message was generated by AI, and not by a human and can help with trust and transparency.

const messageToBeSent = new Message().addAiGenerated().text('Hello!');

AI Generated Indicator

Gather feedback to improve prompts

AI Generated messages are not always perfect. Prompts can have gaps, and can sometimes lead to unexpected results. To help improve the prompts, Teams recommends gathering feedback from users on the AI-generated messages. See Feedback for more information on how to gather feedback.

This does involve thinking through a pipeline for gathering feedback and then automatically, or manually, updating prompts based on the feedback. The feedback system is an point of entry to your eval pipeline.

Citations

AI generated messages can hallucinate even if messages are grounded in real data. To help with this, Teams recommends including citations in the AI Generated messages. This is easy to do by simply using the addCitations method on the message. This will add a citation to the message, and the LLM will be able to use it to generate a citation for the user.

Warning

Citations are added with a position property. This property value needs to also be included in the message text as [<position>]. If there is a citation that's added without the associated value in the message text, Teams will not render the citation

const messageActivity = new MessageActivity(result.content).addAiGenerated();
for (let i = 0; i < citedDocs.length; i++) {
  const doc = citedDocs[i];
  // The corresponding citation needs to be added in the message content
  messageActivity.text += `[${i + 1}]`;
  messageActivity.addCitation(i + 1, {
    name: doc.title,
    abstract: doc.content,
  });
}

AI Generated Indicator