Skip to content

Latest commit

 

History

History
228 lines (173 loc) · 8.05 KB

POWERED-BY-AI.md

File metadata and controls

228 lines (173 loc) · 8.05 KB

Powered by AI

Navigation


What is Powered by AI?

Powered by AI envelopes a set of features that allows for a better user experience when interacting with AI systems. It is a set of features that can be used to enhance the user experience and make the AI system more engaging and interactive. Those features include:

  1. Generated by AI - This is a flag that can be sent within a bot activity to indicate that the message was generated by an AI system. This can be used to inform the user that the message was not written by a human. On Teams, this will show a small icon above the message.
  2. Feedback loop - This is a feature that allows the user to provide feedback on the AI system's responses via thumbs up or thumbs down buttons associated with the bot's activity. This can be used to improve the AI system over time.
  3. Citations - This is a feature that displays citations provided by the AI system when using a datasource like Azure Open AI On Your Data. This can be used to provide sources for the information the AI system provides.
  4. Sensitivity information - This is a feature that displays sensitivity information on citations provided by the AI system when using a datasource like Azure Open AI On Your Data. This can be used to inform the user that the information provided may be sensitive and whether or not it can be shared outside of your organization.

To learn more about how to use these features, please continue on below.

Generated by AI

The Generated by AI feature flag is addable to a bot activity. Fortunately, the Teams AI library makes it easy and adds this for you automatically to activities sent via the AI module in PredictedSAYCommand.

  • In JS, the code that automatically adds this flag can be found in SayCommand.ts.

To add this flag manually, you can use the following JSON in your activity:

{
    "type": ActivityTypes.Message,
    "text": // ...
    // ... other properties
    "entities": [
        {
            "type": "https://schema.org/Message",
            "@type": "Message",
            "@context": "https://schema.org",
            /**
              * Must be left blank. This is for Bot Framework schema.
              */
            "@id": "",
            /**
              * Indicate that the content was generated by AI.
              */
            "additionalType": ["AIGeneratedContent"]
        }
    ]
}

If you find it necessary to add this flag manually, please see the Modifying PredictedSAYCommand section below.

Feedback loop

Feedback loop, when enabled, will add thumbs up and thumbs down buttons to the bot's activity on the Teams client. This can be used to gather feedback from the user on the AI system's responses. The thumbs up and thumbs down buttons will appear on the bottom right of the bot's activity in Teams.

To enable this feature, set the enable_feedback_loop property to true in the AIOptions object when creating the AI object.

JS

export const app = new Application<ApplicationTurnState>({
    ai: {
        planner: planner,
        enable_feedback_loop: true
    },

C#

AIOptions<TurnState> options = new(planner);
options.EnableFeedbackLoop = true; // setting `EnableFeedbackLoop`

Application<TurnState> app = new ApplicationBuilder<TurnState>()
    .WithAIOptions(options)
    .Build();

Python

app = Application[AppTurnState](
    ApplicationOptions(
        # ...other options e.g. planner
        ai=AIOptions(
           enable_feedback_loop=True
        ),
    )
)

This feature is set to false by default. When enabled, all SAY commands from the AI will have the following added to the activity:

{
    "type": "message",
    "text": // ...
    // ... other properties
    "channelData": {
        "feedbackLoopEnabled": true
    }
}

If the user presses either of the feedback buttons, they will be prompted to provide feedback on the AI system's response. The feedback will be sent as an activity to the bot, which will be up to the developer to store and process via the feedback loop activity handlers.

Use the app.feedbackLoop method to register a feedback loop handler. This method will be called when the user provides feedback on the AI system's response. It is up to the developer to store and process the feedback.

JS

app.feedbackLoop(async (context, state, feedbackLoopData) => {
  // custom logic here...
});

C#

app.OnFeedbackLoop(async (turnContext, turnState, feedbackLoopData, cancellationToken) =>
{
    // custom logic here...
});

Python

@app.feedback_loop()
async def feedback_loop(
    context: TurnContext, state: TurnState, feedback_data: FeedbackLoopData
):
    # custom logic here...

The feedbackLoopData payload will contain the following properties:

{
    "actionName: "feedback",
    "actionValue": {
        "reaction": string, //"like" or "dislike"
        "feedback": string
    },
    "replyToId": string
}

Citations

Citations are a feature that can be used to provide sources for the information the AI system provides. This can be from digital documents the LLM references, like when using a datasource like Azure Open AI On Your Data. To see citations in action, please check out the Azure OpenAI datasources sample(s).

Citations that are detected in the AI response will be parsed and automatically added to the outgoing activity via the PredictedSAYCommand action.

  • In JS, the code that automatically parses and adds citations to the entities object within the activity can be found at SayCommand.ts.

If you find it necessary to modify the citations received from the AI response manually, please see the Modifying PredictedSAYCommand section below. When adding citations manually, please see the ClientCitation interface in the Teams AI library for the expected shape of the citation object.

Sensitivity Information

Sensitivity information is included within the citations object. At this time in the Teams AI library, sensitivity information is not addable via AIOptions. In order to add this information manually to each citation, please see the Modifying PredictedSAYCommand section below. To reference what information can be added, please see the SensitivityUsageInfo interface.

Modifying PredictedSAYCommand

Modifying PredictedSAYCommand will provide the developer with more granualar control on how the above features are added to the bot's activity. To modify PredictedSAYCommand, you can use the following code:

JS

app.ai.action<PredictedSayCommand>(AI.SayCommandActionName, async (context, state, data, action) => {
  // custom logic here...
  await context.sendActivity(data.content);
  return "";
});

C#

// AIActions.cs
public class AIActions
{
    [Action(AIConstants.SayCommandActionName, isDefault: false)]
    public async Task<string> SayCommandAsync([ActionTurnContext] ITurnContext turnContext, [ActionParameters] PredictedSayCommand command, CancellationToken cancellationToken = default)
    {
        // Custom logic here...
        return "";
    }
}

// Program.cs
app.AI.ImportActions(new AIActions());

Python

@app.ai.action(ActionTypes.SAY_COMMAND)
async def on_say(
    _context: ActionTurnContext,
    _state: AppTurnState,
):
    # Custom logic here...
    return ""