Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 3.2 KB

02.API-REFERENCE.md

File metadata and controls

72 lines (48 loc) · 3.2 KB

API Reference

The teams-ai API matches Semantic Kernel prompt options.

Developer flow

Below is a diagram of the Teams-AI flow. Teams AI SDK hooks into the Teams SDK and Azure OpenAI SDK to provide a seamless experience for developers.

Teams-AI user-to-bot flow

Bot memory

Bot memory and AI memory are separate. Bot memory stores data for the bot to use, while AI memory stores AI data.

  • $conversation.<prop> - bot conversation memory
  • $user.<prop> - bot user memory
  • $temp.<prop> - bot temp memory (data kept for 1 turn only)
    • $<prop> may be used as an alias for $temp.<prop>

AI memory ($history)

AI bot memory may store context/information for as little as 1 turn, while bot memory may be used to store information for the lifetime of the conversation.

Unlike bot memory, AI memory consumes tokens and therefore is more expensive, but keeping a shorter $history may cause more frequent hallucinations from the AI.

  • $history - conversation history tracked by AI (not related to bot's conversation history see Bot memory)
  • $input - input from the prompt, such as activity.text
  • $output - the last executed function's output. You reference this output in code as state.temp.value.output
  • Hallucinatiion - when the AI creates an independant context/response that does not match the app's use-cases.
  • Parent prompt: when executing chaining, the output from the child prompt may be directly passed to the parent prompt:

Creating a function

app.ai.prompts.addFunction("getUserName", async (context, state) => {
  return context.activity.from.name;
});

In your prompt(s) text file, reference the above function as {{getUserName}}

Chaining prompts

app.ai.prompts.addFunction("translateInputToEnglish", app.ai.createSemanticFunction("translationPrompt"));

The child prompt passes its $output to the parent (translationPrompt)

Calling (prompt) function in code

const result = await app.ai.completePrompt(context, state, "myPrompt");

Using RegExp to match user input

If, for example, a user wants to reset the conversation, a command like 'reset' may be created. However, there are any number of ways the user might call reset, as well as ways that the developer does not want to consider valid. The following is a fairly comprehensive RegExp that can cover many scenarios.

RegExp: ` For details and coverage on this regex, visit this regex101 link which covers and tests 'reset' and 'restart' inputs from the user.

const resetRegex = `/^(?:.*\s)?\/(reset|restart)|^(reset|restart)\(?\)?$/i`;
app.message(resetRegex, async (context, state) => {
  state.conversation.delete();
  await context.sendActivity(`Ok I have deleted the conversation history.`);
});

You may replace reset|restart with whatever word(s) desired, of course. Usage of regex is not required, but may be helpful in covering many scenarios that result in the same action.